Please help me to modify this script [fixed]

 

Hello, 

recently i downloaded this scripts:

https://www.mql5.com/en/code/viewcode/2226/127941/periodnext.mq5

frome here:

https://www.mql5.com/en/code/2226

but my problems are these:(simply i want to read time frame from current chart (not first chart) and apply new timefarme to current chart. (not all charts)).

1-first problem: the script read time frame from first chart in terminal, i want script read time frame from selected chart on terminal.( i'm working with several charts on my terminal) i am not mql5 developer, but i'm programmer in another languages so i searched for the function and found this ( https://www.mql5.com/en/docs/chart_operations), but i don't know the syntax of mql5.

you should change this part:

   long id=ChartFirst();

2- second problem: the script apply new timeframe to all open charts, but i want to apply it to just current (selected)chart.

i think you should change(delete) this iteration condition and replace it with something else,

   while(id!=-1)
     {
      string symbol=ChartSymbol(id);
      ChartSetSymbolPeriod(id,symbol,period);
      id=ChartNext(id);
     }
Documentation on MQL5: Chart Operations
Documentation on MQL5: Chart Operations
  • www.mql5.com
Chart Operations - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

update:

the first problem could be fixed by this function:

https://www.mql5.com/en/docs/chart_operations/chartid

   long id=ChartFirst();

should changed to :

   long id=ChartID();
Documentation on MQL5: Chart Operations / ChartID
Documentation on MQL5: Chart Operations / ChartID
  • www.mql5.com
ChartID - Chart Operations - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

update 2:

the second problem fixed by change loop with if:

   if(id!=-1)
     {
      string symbol=ChartSymbol(id);
      ChartSetSymbolPeriod(id,symbol,period);
     }
  }

https://www.mql5.com/en/docs/basis/operators/if

Documentation on MQL5: Language Basics / Operators / Conditional Operator if-else
Documentation on MQL5: Language Basics / Operators / Conditional Operator if-else
  • www.mql5.com
Conditional Operator if-else - Operators - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: