#include <stdlib.mqh> int start(){
static int ClosedTrades; if(ClosedTrades==HistoryTotal()-1);
OrderSelect(ClosedTrades,SELECT_BY_POS,MODE_HISTORY){
if((OrderType()==OP_BUY)||OrderType()==OP_SELL)) {
if(CompareDoubles(OrderClosePrice(),OrderTakeProfit())){ //Order closed by TP
.
.
.
}
if(CompareDoubles(OrderClosePrice(),OrderStopLoss())){ // Order closed by SL
.
.
.
}
ClosedTrade=HistoryTotal(); }
}
Digger:
Great! Thanks for the quick reply, #include <stdlib.mqh> int start(){
static int ClosedTrades; if(ClosedTrades==HistoryTotal()-1);
OrderSelect(ClosedTrades,SELECT_BY_POS,MODE_HISTORY){
if((OrderType()==OP_BUY)||OrderType()==OP_SELL)) {
if(CompareDoubles(OrderClosePrice(),OrderTakeProfit())){ //Order closed by TP
.
.
.
}
if(CompareDoubles(OrderClosePrice(),OrderStopLoss())){ // Order closed by SL
.
.
.
}
ClosedTrade=HistoryTotal(); }
}
I was under the impression that the numerical order of the MODE_HISTORY collection
was not the order in which the trades were closed.
Therefore one has to find the closed trade with the biggest timestamp, can somebody at Metaquotes clarify this?
Therefore one has to find the closed trade with the biggest timestamp, can somebody at Metaquotes clarify this?
...a tumbleweed rolls by...
I worked my way through the above function and it seems to correctly identify the last closed order. It worked fine for me because I have only one order open at a time. But I understand that others who want to use the function for multiple simultaneous orders, this may need to be worked out more thoroughly and delicately.
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
Thanks