Clearing stored variables for the EA

Post Reply
User avatar
c1borg
Trader
Posts: 456
Joined: Sun Aug 14, 2016 5:09 pm

Clearing stored variables for the EA

Post by c1borg »

Anybody know how to reset a variable for an EA. For example I have a daily profit set at say 1% of my balance which is say $6, it has reached $3 but want to stop the EA and restart without the EA trying to bank the target and restart fresh from tomorrow. Probably havent explained it very well :shock:
Letsarb

Clearing stored variables for the EA

Post by Letsarb »

It is very dangerous to modify the external variables with the EA because every time you start again your EA, every Empty4 crash or whatever, the original external variables are used and replace the modified values....
User avatar
c1borg
Trader
Posts: 456
Joined: Sun Aug 14, 2016 5:09 pm

Clearing stored variables for the EA

Post by c1borg »

So if I restart the EA the variables are reset to 0 is that correct?
Letsarb

Clearing stored variables for the EA

Post by Letsarb »

They are reset to the initialisation value, not especially 0...
The easy way would be to transform this variable as an normal variable, not an external any more...
Radar
Trader
Posts: 437
Joined: Fri Mar 23, 2012 5:39 pm
Location: Round the bend ;)

Clearing stored variables for the EA

Post by Radar »

Hey C1borg,
c1borg » Thu Apr 26, 2018 3:54 am wrote:Anybody know how to reset a variable for an EA. For example I have a daily profit set at say 1% of my balance which is say $6, it has reached $3 but want to stop the EA and restart without the EA trying to bank the target and restart fresh from tomorrow. Probably havent explained it very well :shock:
If the EA sending a TP with the trade, then it doesn't matter if you restart the EA... Unless, of course, you have set the EA to close all trades on removal (Why would you do that??).

If the EA is not sending a TP with the trade, is it calculating the TP based on current balance, or balance when the trade was opened?

If TP is being calculated on current balance, then you can only ever have one trade open at any time, because any change in balance would cause a change in the calculated TP.

Now, if you're calculating TP based on the balance when the trade is opened, and storing it in an internal variable, you will lose the TP as soon as you stop the EA or the terminal. The safest way I know of to do it, (other than send the TP to the broker's server to look after), is to calculate it once, and store the TP in a GlobalVariable (GV), and just check if Ask/Bid is below/above the price stored in the GV and close as appropriate. Just make sure you give the GV a unique name (I use EAName_Symbol_MagicNumber. If your EA sends multiple trades per symbol, just add the ticket number to the name).

Have fun!
Radar =8^)
Check out my new, (well, old now), manual trade & automatic scale-in manager,
StackManV2
Selim
Trader
Posts: 13
Joined: Thu Nov 17, 2011 7:15 pm
Location: Giza-Egypt

Re: Clearing stored variables for the EA

Post by Selim »

He can Instead of storing each order tp in GlobalVariable store the balance in GlobalVariable and this GlobalVariable value does not change until there is no order in the market
Forex trading is very difficult work not a game so you must know all tools for this work that meet with your need
User avatar
c1borg
Trader
Posts: 456
Joined: Sun Aug 14, 2016 5:09 pm

Re: Clearing stored variables for the EA

Post by c1borg »

Wow, this is from 2018, thanks for the reply :smile:
Post Reply

Return to “Know your MT4 platform”