I have a following code in MQL Language. This code (function) checks if there is a existing order
This code will return with true if there is existing order and false if there is no existing orders.
// ================================================== ===
bool ExistPosition() {
bool ExistingOrder = FALSE;
for (int i = 0; i < OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
ExistingOrder = TRUE;
break;
}
}
}
}
return (ExistingOrder);
}
// ================================================== ===
What would be best way to check existing orders in NT?
This is how I got so far in NT script
public ExistPosition(){
int TotalTrades = Performance.AllTrades.Count;
bool ExistingOrder = false;
for ( int i =0 ; i <= TotalTrades; i++){
if(Performance.AllTrades("MSFT", EntryReference, i)) {
ExistingOrder = true;
}else{ExistingOrder = false;}
}
return(ExistingOrder);
}
All I wanted to do is just checking existing order so My Automated strategy does not open two orders at the same time. That is all.
Is there any way of doing this nicely in NT?
Thansk all
Comment