HunFxTrader Posted July 9, 2011 Report Share Posted July 9, 2011 Could anyone please help me how can i get the number of the last consecutive losing trades and the number of the last consecutive winning trades from the orders history? Thank you for your help! Quote Link to comment Share on other sites More sharing options...
HunFxTrader Posted July 10, 2011 Author Report Share Posted July 10, 2011 I was able to solve that issue. Moderators, please delete this thread. Thanks. Quote Link to comment Share on other sites More sharing options...
chrisbenjy Posted July 10, 2011 Report Share Posted July 10, 2011 it would be helpful if you posted the code so that if any other coders need help to do this they can see how it is done. freddy 1 Quote Link to comment Share on other sites More sharing options...
HunFxTrader Posted July 10, 2011 Author Report Share Posted July 10, 2011 (edited) The solution Okay Chris, here is the solution: First we need to get the last closed order and its profit from the orders history. int LastCloseTime = 0; double LastProfit = 0; for (int cnt = 0; cnt < OrdersHistoryTotal(); cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_HISTORY); if (OrderSymbol()== Symbol() && OrderMagicNumber()== Magic) { if (OrderCloseTime() > LastCloseTime) { LastCloseTime = OrderCloseTime(); LastProfit = OrderProfit(); } } } Then we need two integers for counting the last consecutive winning and losing trades, and a global variable to save the last order's close time. int CntWinners=0; int CntLosers=0; if (!GlobalVariableCheck("LastCloseTime")) GlobalVariableSet("LastCloseTime",0); In the last step we need this code for counting: if (LastProfit>=0 && LastCloseTime>GlobalVariableGet("LastCloseTime")) { GlobalVariableSet("LastCloseTime",LastCloseTime); CntWinners+=1; // adding one to the winners CntLosers=0; // nulling the losers } if (LastProfit<0 && LastCloseTime>GlobalVariableGet("LastCloseTime")) { GlobalVariableSet("LastCloseTime",LastCloseTime); CntWinners=0; // nulling the winners CntLosers+=1; // adding one to the losers } If we want to print the actual number of the last consecutive winner and loser trades on to the chart we can do it this way: Comment("Last Consecutive Winners: ", CntWinners, "\n", "Last Consecutive Losers: ", CntLosers); I hope you find it useful! Edited July 10, 2011 by HunFxTrader freddy 1 Quote Link to comment Share on other sites More sharing options...
vikram88 Posted August 10, 2011 Report Share Posted August 10, 2011 Need help in writing EA Hello Can someone please assist in writing an Ea to change stop loss based on 34EMA of high of the last closed bar for open sell trades and 34EMA of low for open buy trades Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.