//±-----------------------------------------------------------------+
//| 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.01"
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0

//— input parameters
input int InpAtrPeriod = 10; // ATR period
input int InpMonthsToCalculate = 3; // Number of months to calculate

int PeriodEXT(ENUM_TIMEFRAMES tf)
{
   switch(tf)
   {
      case PERIOD_M1   :
         return 10;
      case PERIOD_M5   :
         return 10;
      case PERIOD_M15  :
         return 10;
      case PERIOD_M30  :
         return 10;
      case PERIOD_H1   :
         return 10;
      case PERIOD_H4   :
         return 10;
      case PERIOD_D1   :
         return 5;
      case PERIOD_W1   :
         return 14;
      case PERIOD_MN1  :
         return 31;
      default          :
         return 14; // Default period
   }
}

int ExtendPeriodDays = 0; // Number of days to extend the lines

//±-----------------------------------------------------------------+
//| Custom indicator initialization function                        |
//±-----------------------------------------------------------------+
int OnInit()
{
   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[])
{
   ExtendPeriodDays = PeriodEXT(Period());

   for (int month = 0; month < InpMonthsToCalculate; month++)
   {
      double H_L[10];
      int m = 0;
      double openATR[10];
      
      // Calculate moving average and MADiff using monthly timeframe data
      for (int i = 0; i < InpAtrPeriod; i++)
      {
         int shift = i + month + 1;
         double maxHigh = iHigh(_Symbol, PERIOD_MN1, shift);
         double minLow = iLow(_Symbol, PERIOD_MN1, shift);
         openATR[m] = iOpen(_Symbol, PERIOD_MN1, shift);
         H_L[m] = NormalizeDouble(maxHigh - minLow, _Digits);
         m++;
      }

      double ATR = 0;
      for (int i = 0; i < 9; i++)
      {
         double sum = H_L[i] + H_L[i + 1];
         ATR += sum / 2 / openATR[i + 1] * 100;
      }

      double ATRavg = NormalizeDouble(ATR / 9, 2);
      
      
      double priceHigh = openATR[0] + (openATR[0] * ATRavg / 100);
      double priceLow = openATR[0] - (openATR[0] * ATRavg / 100);
      double priceHigh_2 = openATR[0] + (openATR[0] * ATRavg / 200);
      double priceLow_2 = openATR[0] - (openATR[0] * ATRavg / 200);

      string suffix = IntegerToString(month);
      datetime time_end = iTime(_Symbol, PERIOD_MN1, month);
      // Extend the time_end by specified number of days
      time_end += ExtendPeriodDays * 24 * 60 * 60;
      // Compute time for 10 candles back from the current time
      datetime time_start = iTime(_Symbol, PERIOD_MN1, month);

ObjectCreate(0, "priceHigh" + suffix, OBJ_TREND, 0, time_start, priceHigh, time_end, priceHigh);
      ObjectCreate(0, "priceLow" + suffix, OBJ_TREND, 0, time_start, priceLow, time_end, priceLow);
      ObjectCreate(0, "priceHigh_0.5" + suffix, OBJ_TREND, 0, time_start, priceHigh_2, time_end, priceHigh_2);
      ObjectCreate(0, "priceLow_0.5" + suffix, OBJ_TREND, 0, time_start, priceLow_2, time_end, priceLow_2);
      
      ObjectSetInteger(0, "priceHigh" + suffix, OBJPROP_COLOR, clrCrimson);
      ObjectSetInteger(0, "priceLow" + suffix, OBJPROP_COLOR, clrCrimson);
      ObjectSetInteger(0, "priceHigh_0.5_" + suffix, OBJPROP_COLOR, clrBlue);
      ObjectSetInteger(0, "priceLow_0.5_" + suffix, OBJPROP_COLOR, clrBlue);

      ObjectSetInteger(0, "priceHigh" + suffix, OBJPROP_WIDTH, 2);
      ObjectSetInteger(0, "priceLow" + suffix, OBJPROP_WIDTH, 2);
      ObjectSetInteger(0, "priceHigh_0.5_" + suffix, OBJPROP_WIDTH, 2);
      ObjectSetInteger(0, "priceLow_0.5_" + suffix, OBJPROP_WIDTH, 2);
   }

   return (rates_total);
}нужно что бы он правильно считал для других месяцев