I know this must require global variables, but even after reading the documentation
on their use... I am still completely clueless
I don't understand , may be this way you need
if (closedProfit > ProfitTarget) { ClosePendingOrdersAndPositions(); // try close/delete all(by MagicNumber etc.) orders if (OrderTotals()==0) // all orders are closed and deleted { closedProfit=0; uniqueMagic = uniqueMagic +1; } }
Thank you!! I am very grateful for your reply, however this still does not make
it work.
My only guess is to use global variables...but I have no clue on how to use them. I need an example of some sort to help point me in the right direction so I can start coding them on my own.
Thanks,
Jon
My only guess is to use global variables...but I have no clue on how to use them. I need an example of some sort to help point me in the right direction so I can start coding them on my own.
Thanks,
Jon
since you said you don't understand here is exacly what I am trying to do.
Once equity has reached a profit of X, i need the EA to close all orders and reset itself to run again in a way that it no longers looks at what was closed on prior magic number, but uses a NEW magic number so it can once again do the same things as before.
The proble I am having is lets say balance is 10k. Once equity reaches 10.5k close all orders and start again. The EA constanly sees that equity is +5 (10.5K) so it does not understand that I want the next value to be 11k (+5), and so on
Once equity has reached a profit of X, i need the EA to close all orders and reset itself to run again in a way that it no longers looks at what was closed on prior magic number, but uses a NEW magic number so it can once again do the same things as before.
The proble I am having is lets say balance is 10k. Once equity reaches 10.5k close all orders and start again. The EA constanly sees that equity is +5 (10.5K) so it does not understand that I want the next value to be 11k (+5), and so on
Yes, you can use global variable.
double ProfitbyMN(int MN) { double profit; .... if (OrderMagicNumber()==MN) res=res+OrderProfit(); .... return(profit); } ... int oldMagicNumber=GlobalVariableGet("MagicNumber"); if (ProfitbyMN(oldMagicNumber)>ProfitTarget) { CloseDeleteByMN(oldMagicNumber); GlobalVariableSet("MagicNumber",oldMagicNumber+1); }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I am using some functions to calculate my Closed Profits.
Once closed profits = X, I am having the EA shut down all orders and restart.
How can I get the closed profits to reset itself to 0?
I have tried a few methods, such as getting the EA to reset closeProfit to 0 as well as getting my uniqueMagic to add 1 to the number.
I am using code similar to below but it is not working:
if (closedProfit > ProfitTarget) {
ClosePendingOrdersAndPositions();
closedProfit=0;
uniqueMagic = uniqueMagic +1; }