141 lines
3.0 KiB
Plaintext
141 lines
3.0 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center RMA Indicator
|
|
// ---------------------------------------------
|
|
// saherelm implementation of above oscillator ...
|
|
//
|
|
// Maintainer:
|
|
// ------------
|
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
//
|
|
//////////////////////////////////////////////////////
|
|
//
|
|
// Global Properties ...
|
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
#property link "https://saherelm.ir"
|
|
#property version "1.00"
|
|
#property description "SaherElm RMA Indicator"
|
|
#property strict
|
|
|
|
//
|
|
// START Inputs ...
|
|
//
|
|
//
|
|
// Set the RMA Length ...
|
|
input int RMALength = 10; // Length
|
|
//
|
|
// END Inputs ...
|
|
//
|
|
|
|
//
|
|
// START Global Definitions: Variables, Properties and etc ...
|
|
//
|
|
#property indicator_chart_window
|
|
|
|
//
|
|
// we have 2 buffer in this indicator ...
|
|
#property indicator_buffers 1
|
|
|
|
//
|
|
// also we have 1 line for draw on this indicator ...
|
|
#property indicator_plots 1
|
|
|
|
//
|
|
// here we declare plot SlowOCS to system ...
|
|
#property indicator_label1 "RMA"
|
|
#property indicator_type1 DRAW_LINE
|
|
#property indicator_color1 clrFuchsia
|
|
#property indicator_style1 STYLE_SOLID
|
|
#property indicator_width1 1
|
|
|
|
//
|
|
// Declare Buffers ...
|
|
#define RMABufferIndex 0
|
|
|
|
//
|
|
double RMABuffer[];
|
|
//
|
|
// END Global Definitions: Variables, Properties and etc ...
|
|
//
|
|
|
|
//
|
|
// Start Event Handlers ...
|
|
//
|
|
//
|
|
// Initialization ...
|
|
int OnInit() {
|
|
//
|
|
// Initialize what we want ...
|
|
SetIndexBuffer(RMABufferIndex, RMABuffer);
|
|
|
|
//
|
|
// initialization done ...
|
|
return(INIT_SUCCEEDED);
|
|
}
|
|
|
|
//
|
|
// Do Calculation ...
|
|
int OnCalculate(
|
|
const int rates_total,
|
|
const int prev_calculated,
|
|
const datetime &time[],
|
|
const double &open[],
|
|
const double &high[],
|
|
const double &low[],
|
|
const double &close[],
|
|
const long &tick_volume[],
|
|
const long &volume[],
|
|
const int &spread[]
|
|
) {
|
|
//
|
|
int maxLength = MathMax(0, RMALength);
|
|
|
|
//
|
|
// wait to pass bars until we have rights ...
|
|
if (rates_total <= maxLength) {
|
|
//
|
|
// return not calculated ...
|
|
return 0;
|
|
}
|
|
|
|
//
|
|
// find loop count for bars manipulation ...
|
|
int count = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
|
|
|
|
//
|
|
// Print("Count: ", count, ", Bars: ", Bars);
|
|
|
|
//
|
|
// this is the main loop of calculations, for each bar index ...
|
|
for (int i = count - 1; i >= 0; i--) {
|
|
//
|
|
// Start Calculation with Formula 1 ...
|
|
//
|
|
double shortSMA = iMA(_Symbol, _Period, RMALength, 0, MODE_SMA, PRICE_CLOSE, i);
|
|
double mediumSMA = iMA(_Symbol, _Period, RMALength * 2, 0, MODE_SMA, PRICE_CLOSE, i);
|
|
double longSMA = iMA(_Symbol, _Period, RMALength * 3, 0, MODE_SMA, PRICE_CLOSE, i);
|
|
|
|
//
|
|
double rma1 = longSMA - mediumSMA + shortSMA;
|
|
rma1 = NormalizeDouble(rma1, _Digits);
|
|
//
|
|
// End Calculation with Formula 1 ...
|
|
//
|
|
|
|
//
|
|
RMABuffer[i] = rma1;
|
|
}
|
|
|
|
//
|
|
return rates_total;
|
|
}
|
|
//
|
|
// END Event Handlers ...
|
|
//
|
|
|
|
//
|
|
// START Functions ...
|
|
//
|
|
//
|
|
// END Functions ...
|
|
// |