Anyone?
I'm still getting back into all of these trading terms - but you might want to look at the AccountFreeMargin , AccountFreeMarginCheck, and esp AccountFreeMarginMode functions to check your profit at a glance instead of looping through orders?
I could have missed something though...
Also for profit you often have to look at OrderCommision() and OrderSwap()
- read1985:
if(!OrderClose(OrderTicket(),OrderLots(),Bid,0,0)) { Print("OrderClose Error: ",GetLastError()); } } if(OrderType()==OP_SELL) { if(!OrderClose(OrderTicket(),OrderLots(),Ask,0,0))
- You can not use any predefined variables when the OrderSymbol is not the current chart symbol.
- Don't test Bid/Sell. Just use OrderClosePrice().
- Server calls take time. You must RefreshRates() between them.
if(!OrdersTotal()==0) if(! 5 ==0) if(! TRUE ==0) if( FALSE ==0) if( 0 ==0) << test is always true.
for(cnts=OrdersTotal()-1;cnts>=0;cnts--) profit += .. : if(((Profit/GlobalVariableGet("DailyOpenBalance"))*100)>=ProfitTarget) { CloseTrades=true; }
All that could be simplified toCloseTrades = AccountEquity()/GlobalVariableGet("DailyOpenBalance"))*100 >= ProfitTarget;
No loop, no if.
Awesome thanks so much! have made the changes in point 1 ,2 and 3 with a small difference
CloseTrades=((AccountEquity()-GlobalVariableGet("DailyOpenBalance"))/GlobalVariableGet("DailyOpenBalance")) * 100>=ProfitTarget;
Also, I am not sure what you mean by this:
if(!OrdersTotal()==0) if(! 5 ==0) if(! TRUE ==0) if( FALSE ==0) if( 0 ==0) << test is always true.
Thanks for your help!
if(!OrdersTotal()==0)What part of "always true" was unclear?
Ok so, are you saying rather:
if(OrdersTotal()>0)
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
Hi!
I have an EA running on 5 charts. Part of my strategy is that as soon as my profit for the day, + floating P/L reaches 5%, I close all my open trades and stop trading of the day. I have written an EA that I run on a separate chart to monitor and P/L and close the trades. It is working well so far, however I have noticed that the speed at which the orders get close obviously has an impact on the final P/L. As much as I know that there are other factors that come in to play (latency, execution by broker), I want to make sure that my EA is using the most efficient code to close all the trades quickly.
I've posted my code here, and would appreciate it if anyone could give me some tips to "speed" up the code?
Thanks!
Richard