Current variable values read and write ​​in ini file?

 

Hi,

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?

Thanks.

 

shck:

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().

 
ubzen:

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).




 
shck:

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.

 
GumRai:


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.


How can I change the GlobalVariable-Name, if I change e.g. the MagicNumber? I think, the name of variables are fix in the code, not changeable by user.
 
shck:

How can I change the GlobalVariable-Name, if I change e.g. the MagicNumber? I think, the name of variables are fix in the code, not changeable by user.
The GlobalVariable name is a string, you can't change the name of an existing GV but you can create a new one using a string for the name that, for example, contains the Magic Number.
 

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.

 
RaptorUK:
The GlobalVariable name is a string, you can't change the name of an existing GV but you can create a new one using a string for the name that, for example, contains the Magic Number.

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.


Ovo:

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.


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 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.


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

Reason: