I wrote an EA, which work with labels (with ON or OFF text). Everytime a new position is closed, I read the history to check, if there was a stop loss position, if so, the label change to off and the EA is stopped.
If I change the label text manually to ON, the EA is working on.
My idea is e.g. to write the latest time of the ON/OFF-change in an ini/text-file, to avoid the automaticly change of the text, if the history is re-read (e.g. by changing the time frame, start EA again, start MT4 and so on).
Is there an easy way to handle this like with ini-files (last_sl_time = xxxx) instead of read/write each variable in separate files?
Why do you think you need separate files?
You can also look into GlobalVariableSet().
I guess GlobalVariableSet() are not stored, if MetaTrader restarts?
Furthermore I cant use GlobalVariableSet(), because I have runing the same EA up to 20 times at the same time with various settings, timeframes and magic numbers.
It should be easier to handle for each EA a separate file (e.g. Symbol_TimeFrame_MagicNumber.ini).
With GlobalVariableSet() the variable remains accessible for 4 weeks from the last time it was accessed. It doesn't matter if the platform is re-started between times.
If you use Symbol_TimeFrame_MagicNumber.ini to name a file, you could probably use the same method to name an individual Global Variable.
If the solution should protect against re-initialization of the ea status, (time frame change as the above mentioned example), then naming the variable/file with timeframe value is perhaps not a good idea.
I would use storing the values to chart objects placed out of sight by deinit and checking them back in init.
Because of the fix name of GlobalVariables, I want to go to another way of storing the values. In using are at least 20 EAs with different adjustable MagicNumbers by user.
I have to explain some more details for you to understand the issue.
The user can choose a custom MagicNumber, the "real" MagicNumber (in the background) for the open chart and EA orders is in reality a combination of symbolname (StringGetChar for each letter) + TimeFrame-Value + custom MagicNumber.
E.g. for EURUSD in M1 the "real" MagicNumber is 438 and in M5 442, so the user can apply the same MagicNumber (1) in different timeframes for the same symbol (hope that is userfriendly). For the same timeframe and the same symbol the user have to use a different MagicNumber.
OVO> "storing the values to chart objects"
In my first post I wrote:
I have trouble with the chart objects, so I wrote the thread here. If the user change the chart object to OFF or a stop loss position is changing the chart object to OFF the EA is stopping. If the user change the timeframe, EA inputs or MT4-restart, the trade history is read again and the ON value is changing to OFF (thats the problem). So my Idea is, to save in a file (e.g. 438.ini/438.txt) the last user changing-time of the chart object and the last time of the sl-position/changing-time. I hope this is explained well. :-X
To add comments, please log in or register