Download MetaTrader 5

How to change chart period on code base in oncalculate function for custom indicator?

To add comments, please log in or register
zeno
275
zeno 2014.05.10 20:04 

Hello,

By trying to switch chart period within oncalculate function in a custom indicator, we use following code below. But the chart automatically closes after the return. How can this be solved? Thank you.

ENUM_TIMEFRAMES periods[] = {PERIOD_M30, PERIOD_H1};
int period_ind;

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     &TickVolume[],
                const long     &Volume[],
                const int      &Spread[])
{
...
...
...
long currChart=ChartFirst();
ENUM_TIMEFRAMES period = periods[period_ind % (ArraySize(periods))];
ChartSetSymbolPeriod(currChart, ChartSymbol(currChart), period) ; 

return(rates_total);
}
Artem Temnikov
1031
Artem Temnikov 2014.05.10 20:23  
zeno:

Hello,

By trying to switch chart period within oncalculate function in a custom indicator, we use following code below. But the chart automatically closes after the return. How can this be solved? Thank you.

Programmatically change the current chart timeframe impossible.

But you can create a new chart using ChartOpen .

Alain Verleyen
Moderator
31091
Alain Verleyen 2014.05.10 22:05  
zeno:

Hello,

By trying to switch chart period within oncalculate function in a custom indicator, we use following code below. But the chart automatically closes after the return. How can this be solved? Thank you.

Do you really want to change the chart period on each tick ?
Alain Verleyen
Moderator
31091
Alain Verleyen 2014.05.10 22:07  
Fleder:

Programmatically change the current chart timeframe impossible.

But you can create a new chart using ChartOpen .

Yes it's possible to change the current chart timeframe.
To add comments, please log in or register