//±-----------------------------------------------------------------+
//| 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 0
#property indicator_plots 0

//— input parameters
input int InpAtrPeriod = 10; // ATR period

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());
   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 + 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);

   datetime time_end = iTime(_Symbol, PERIOD_M1, 0);
   // 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, 1);

   ObjectCreate(0, "priceHigh", OBJ_TREND, 0, time_start, priceHigh, time_end, priceHigh);
   ObjectCreate(0, "priceLow", OBJ_TREND, 0, time_start, priceLow, time_end, priceLow);
   ObjectCreate(0, "priceHigh_0.5", OBJ_TREND, 0, time_start, priceHigh_2, time_end, priceHigh_2);
   ObjectCreate(0, "priceLow_0.5", OBJ_TREND, 0, time_start, priceLow_2, time_end, priceLow_2);

   ObjectSetInteger(0, "priceHigh", OBJPROP_COLOR, clrCrimson);
   ObjectSetInteger(0, "priceLow", OBJPROP_COLOR, clrCrimson);
   ObjectSetInteger(0, "priceHigh_0.5", OBJPROP_COLOR, clrBlue);
   ObjectSetInteger(0, "priceLow_0.5", OBJPROP_COLOR, clrBlue);

   ObjectSetInteger(0, "priceHigh", OBJPROP_WIDTH, 2);
   ObjectSetInteger(0, "priceLow", OBJPROP_WIDTH, 2);
   ObjectSetInteger(0, "priceHigh_0.5", OBJPROP_WIDTH, 2);
   ObjectSetInteger(0, "priceLow_0.5", OBJPROP_WIDTH, 2);

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