HunFxTrader Posted July 9, 2011 Report 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!
HunFxTrader Posted July 10, 2011 Author Report Posted July 10, 2011 I was able to solve that issue. Moderators, please delete this thread. Thanks.
chrisbenjy Posted July 10, 2011 Report 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
HunFxTrader Posted July 10, 2011 Author Report 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
vikram88 Posted August 10, 2011 Report 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
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now