Before everything else, move the double declaration out of the 'if'...:
if(Total_sell_pos() == 0 && Total_buy_pos() == 0) { double previous_balance = AccountBalance(); //usd1000 }
like this:
double previous_balance = 0; if(Total_sell_pos() == 0 && Total_buy_pos() == 0) { previous_balance = AccountBalance(); //usd1000 }
Before everything else, move the double declaration out of the 'if'...:
like this:
ok done
ok done
Er... problem solved, right?
Er... problem solved, right?
not yet
You need to declare
double previous_balance
variable outside (the best - before) OnTick, or OnTimer (depends which one you use), in global section.
In that way it will keep the state of calculation on next algo iterations.
If you dont want to do this, add static keyword before double, like this:
static double previous_balance
This will have similar effect.
not yet
Are these lines within the same function?
double previous_balance = 0; if(Total_sell_pos() == 0 && Total_buy_pos() == 0) { double previous_balance = AccountBalance(); //usd1000 } if (AccountEquity() > previous_balance + (previous_balance *0.05)){ //usd1000 + 50 = usd1050 CloseSellOrders(); CloseBuyOrders(); Delete_Pendings(); }
You need to declare
variable outside (the best - before) OnTick, or OnTimer (depends which one you use), in global section.
In that way it will keep the state of calculation on next algo iterations.
If you dont want to do this, add static keyword before double, like this:
This will have similar effect.
Perfect! It works. You are my hero. Thank you very much.
-
double previous_balance = AccountBalance(); //usd1000
That isn't the previous balance, it's the current balance. Previous must be calculated
Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum -
if (AccountEquity() > previous_balance + (previous_balance *0.05)){ //usd1000 + 50 = usd1050
This includes all open orders, not only orders on the current chart, not only orders from the EA. Code is incompatible with every EA (including itself on other charts and manual trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
MagicNumber: "Magic" Identifier of the Order - MQL4 Articlesprofit=Σ OrderProfit+OrderCommission+OrderSwap
Perfect! It works. You are my hero. Thank you very much.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
if Equity more than usd1050 then delete pending and orders.
But why when run the code, it keep delete pending and orders immediately even when Equity is less than previous balance?
The following code is the problem, and I replace it :
AccountEquity() > previous_balance + (previous_balance *0.05)
with
AccountEquity() > 1050
then only it works. I did try to check the value :
May I know why I cannot use the following code?
AccountEquity() > previous_balance + (previous_balance *0.05)