Clearing the value of variables when change TimeFrame in MetaTrader Termina 4 (mql4)
Clearing the value of variables when change TimeFrame in MetaTrader Termina 4 (mql4)
Loading saved threads...
user4402215 · External communityPost link
External question — Stack Overflow Stack Exchange
Author: user4402215
Original post: https://stackoverflow.com/questions/76083892
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I have a MetaTrader Terminal 4 ExpertAdvisor, coded in MQL4 language.
I have a problem.
Everything works fine except when a TimeFrame changes by a user-action.
Values of the variables (fields) are then erased and ExpertAdvisor gets once again initialized.
Please help me
I searched on the internet and they suggested global variables, but the use of global variables did not make sense to me.
Quote
Report
user3666197 · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: user3666197
Original post: https://stackoverflow.com/a/76306478
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
The above described behaviour is actually the desired functionality of the MetaTrader Terminal trading ecosystem.
Once a timeframe was changed, none of previous state-variables make sense since the "distances" in TimeDOMAIN are suddenly many times different then so far and similarly, the PriceDOMAIN { O, H, L, C, V, T }-data are never matching the actual { super- | sub- }-Frame. Integer Bar[]-indexing thus lost its capability to serve as a pointer into some Bar-data, as the "distance" offsets do not match the { super- | sub- }-Frame data anymore.
ExpertAdvisor-type of MQL4-code must stop working in such cases, otherwise a "context-blind-actions" may deteriorate one's equity by salvos of nonsensical XTO-s.
If in a need to build a TimeFrame-change resilient "Global-Trading-Strategy", some other tools are needed. Read as -- one must create some client-server interconnected agents, that on one side control the "G.T.S.", whereas on the other side, the EA-can reset its internal settings, once a TimeFrame-change happened ( be it by error or intent ) and within a "debate" with the server-side "G.T.S." re-adjust its own behaviour. I used such virtual-TimeFrame EA-s for cases, where distributed-computing was maintaining things that a single EA-code cannot perform inside an isolated MetaTrader Terminal 4 ecosystem.
Hard?
Well, actually not so.
Complex?
Yes, more complex, definitely more complex than running a solitaire EA-code with a set of Custom Indicators, yet doable. Using a herd of MT4-Terminals equipped with a mix of { EA | Custom Indicators | Script }-MQL4-code-execution units "over" many MT4-Graphs, with a remote-logging, remote-command-keyboards, external remote in-loop M/L-predictor engines was rather complex, yet very rewarding exosystem to build & operate, so definitely doable.
Quote
Report
PaulB · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: PaulB
Original post: https://stackoverflow.com/a/76307708
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
This behaviour is by design.
If you wish to retain values of variables, I would suggest you check
GlobalVariables
and use these for values which you need to retain after the EA resets.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: PaulB Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/a/76307708 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. This behaviour is by design. If you wish to retain values of variables, I would suggest you check GlobalVariables and use these for values which you need to retain after the EA resets.
Checking account access…