//+------------------------------------------------------------------+ // ATR.mq5 //…
- User
//+------------------------------------------------------------------+ //| ATR.mq5 | //| Copyright 2024, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2024, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1
#property indicator_label1 "ATR_low" #property indicator_type1 DRAW_LINE #property indicator_color1 clrGreen #property indicator_style1 STYLE_SOLID #property indicator_width1 1
#property indicator_label1 "ATR_high" #property indicator_type1 DRAW_LINE #property indicator_color1 clrGreen #property indicator_style1 STYLE_SOLID #property indicator_width1 1
#property indicator_label1 "ATR_low_0.5" #property indicator_type1 DRAW_LINE #property indicator_color1 clrBlue #property indicator_style1 STYLE_SOLID #property indicator_width1 1
#property indicator_label1 "ATR_high_0.5" #property indicator_type1 DRAW_LINE #property indicator_color1 clrBlue #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //— input parameters input int InpAtrPeriod = 10; // ATR period
//— indicator buffers double AtrBuffer[];
double ATR; //±-----------------------------------------------------------------+ //| Custom indicator initialization function | //±-----------------------------------------------------------------+ int OnInit() { SetIndexBuffer(0, AtrBuffer,INDICATOR_DATA); return(INIT_SUCCEEDED); } //±-----------------------------------------------------------------+ //| Custom indicator iteration function | //±-----------------------------------------------------------------+ 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[]) { double H_L[10]; int m = 0; double openATR[10];
// Calculate moving average and MADiff for(int i = rates_total-1; i > rates_total-InpAtrPeriod-1; i--) { double maxHigh = high[i]; double minLow = low[i]; openATR[m] = open[i]; H_L[m] = NormalizeDouble(maxHigh - minLow,_Digits); m++; }
for(int i=0;i<9;i++) { double sum = H_L[i]+H_L[i+1]; ATR += sum/2/openATR[i+1]*100; }
ATRavg = NormalizeDouble(ATR/9,2)
return(rates_total); } //±-----------------------------------------------------------------+ у меня есть такой индикатор нужно что бы он отсупил от close цены графика на процент ATR и начертил линии
- Assistant