I've coded this little indicator to show me the last 10 trades profit or loss in pips. At the moment it shows me the first 10 trades in the order history pool. I want to display the last 10 trades. I can't work out why it won't work, can anyone help?
I assume you mean the 10 most recently closed trades ? these should be the 10 highest (largest index numbers) positions in the pool. Your loop is wrong, the last position is OrderHistoryTotal() - 1, starting at OrderHistoryTotal() - 10 and counting up while your count is <= OrdrHistoryTotal() will try to go one index too far, it should be < OrdrHistoryTotal()
If you only have 10 Orders in the pool you will be finding the first and last 10. How many do you have ?
Thanks, part of the problem was the method I was using to display the pairs. I have sorted it now.
Here is the code if anyone wants it. I gave you a vouch on Forex Factory by the way, in case you haven't seen it. Thanks for the help.
double orderpipsprofit; color profcol; int start() { ObjectsDeleteAll(); Display("heading", 40,20); ObjectSetText("heading","Account History In Pips",12,"Verdana", Blue); int counter1; int ordercount = 0; for(counter1 = OrdersHistoryTotal() -1; ordercount < 11; counter1--) { OrderSelect(counter1,SELECT_BY_POS,MODE_HISTORY); int pipMult = 10000; if(StringFind(OrderSymbol(),"JPY",0) != -1) pipMult = 100; if(OrderType() == OP_BUY) { orderpipsprofit = (OrderClosePrice() - OrderOpenPrice()) * pipMult; profcol = Blue; if(orderpipsprofit > 0) profcol = Lime; if(orderpipsprofit < 0) profcol = Red; ordercount++; } if(OrderType() == OP_SELL) { orderpipsprofit = (OrderOpenPrice() - OrderClosePrice()) * pipMult; profcol = Blue; if(orderpipsprofit > 0) profcol = Lime; if(orderpipsprofit < 0) profcol = Red; ordercount++; } if(OrderType() == OP_BUY || OrderType() == OP_SELL) { Display("order" + OrderTicket(), 40, ((ordercount * 20) + 20)); ObjectSetText("order" + OrderTicket(),OrderSymbol() + " / " + DoubleToStr(orderpipsprofit,1),10,"Verdana", profcol); } } return(0); } void Display(string name, int x, int y) { ObjectCreate(name, OBJ_LABEL, 0, 0, 0); ObjectSet(name, OBJPROP_CORNER, 0); ObjectSet(name, OBJPROP_XDISTANCE, x); ObjectSet(name, OBJPROP_YDISTANCE, y); ObjectSet(name, OBJPROP_BACK, FALSE); }
Here is the code if anyone wants it. I gave you a vouch on Forex Factory by the way, in case you haven't seen it. Thanks for the help.
Thank you, I hadn't seen it, not been on there for a little while, you are most welcome :-)
You probably don't want to either. You want the last 10 closed trades (by datetime.) The order in the pool is irrelevant. Could EA Really Live By Order_History Alone? - MQL4 forum
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I've coded this little indicator to show me the last 10 trades profit or loss in pips. At the moment it shows me the first 10 trades in the order history pool. I want to display the last 10 trades. I can't work out why it won't work, can anyone help? Thanks.