Hi MT4 programmers,
When a user changes chart timeframe, all static variables are initialized once, and then the values are retained between function calls. However... what if what I want to retain is the current timeframe (Period()) value itself??
In the start() block, this code snippet shows how the "last_period" value is retained between ticks:
static int last_period;
Print("PRE-last_period: ", last_period);
last_period = Period();
Print("POST-last_period: ", last_period);
With the 1st tick, the PRE value is 0, and the POST value is, for example, 60. With every subsequent tick, both values are 60 as you would expect for a "static" variable.
However, what I need is when I change chart timeframes, with the first tick I would like to see a PRE value of "60" and a POST value of, for example, "240".
Unfortunately the PRE value is always "0". I also tried moving the "static int last_period;" line out of the start() block to make it a high-level global variable but that didn't work either. My program needs to know the timeframe was changed, including from what value. (If I go up in timeframes, my action will be different from when I go down in timeframe).
FYI, using a terminal client Global Variable isn't a practical answer, because I would need unique variables for every single chart. That's too many if I open up 20-30 charts.
I'm guessing my only answer would be to write the info to a unique file-per-chart (???), and read the file in the init() block. If so, does anyone have any examples? I've never attempted anything similar.
If there is an easier answer, I'd really like to know.
Thanks in advance for any help,
Pips4life (Kent)
When a user changes chart timeframe, all static variables are initialized once, and then the values are retained between function calls. However... what if what I want to retain is the current timeframe (Period()) value itself??
In the start() block, this code snippet shows how the "last_period" value is retained between ticks:
static int last_period;
Print("PRE-last_period: ", last_period);
last_period = Period();
Print("POST-last_period: ", last_period);
With the 1st tick, the PRE value is 0, and the POST value is, for example, 60. With every subsequent tick, both values are 60 as you would expect for a "static" variable.
However, what I need is when I change chart timeframes, with the first tick I would like to see a PRE value of "60" and a POST value of, for example, "240".
Unfortunately the PRE value is always "0". I also tried moving the "static int last_period;" line out of the start() block to make it a high-level global variable but that didn't work either. My program needs to know the timeframe was changed, including from what value. (If I go up in timeframes, my action will be different from when I go down in timeframe).
FYI, using a terminal client Global Variable isn't a practical answer, because I would need unique variables for every single chart. That's too many if I open up 20-30 charts.
I'm guessing my only answer would be to write the info to a unique file-per-chart (???), and read the file in the init() block. If so, does anyone have any examples? I've never attempted anything similar.
If there is an easier answer, I'd really like to know.
Thanks in advance for any help,
Pips4life (Kent)