Change Timeframe All Charts

Author: Copyright © 2021, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
Change Timeframe All Charts
ÿþ//+------------------------------------------------------------------+

//|                                  Change Timeframe All Charts.mq5 |

//|                              Copyright © 2021, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43161 |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2021, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43161"

#property version   "1.00"

#property script_show_inputs

//--- input parameters

input ENUM_TIMEFRAMES   Inp_period  = PERIOD_D1;   // Timeframe

//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+

void OnStart()

  {

   long chart_id=ChartID();

//--- variables for chart ID

   long currChart,prevChart=ChartFirst();

   int i=0,limit=100;

   if(prevChart!=chart_id)

      ChartSetSymbolPeriod(prevChart,ChartSymbol(prevChart),Inp_period);

   while(i<limit)// We have certainly not more than 100 open charts

     {

      currChart=ChartNext(prevChart);  // Get the new chart ID by using the previous chart ID

      if(currChart<0)

         break;                        // Have reached the end of the chart list

      prevChart=currChart;             // let's save the current chart ID for the ChartNext()

      i++;                             // Do not forget to increase the counter

      if(currChart!=chart_id)

         ChartSetSymbolPeriod(currChart,ChartSymbol(currChart),Inp_period);

     }

   ChartSetSymbolPeriod(chart_id,ChartSymbol(chart_id),Inp_period);

  }

//+------------------------------------------------------------------+

Comments