MQL4: Last Closed Order Checking condition

KHALID ABES
982
KHALID ABES  

In order to check the last order Type if LONG or CHORT
For Example : Long if Last Closed is Short


int LastOrderType()
{
 for(int i=OrdersTotal()-1;i>=0;i--)
 {
  bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
  if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
  {
   return(OrderType());
  }
 }
 return(0);
}  


void OnTick() {  
if(LastOrderType()==OP_BUY)   
if(LastOrderType()==OP_SELL) 

Taking exemple EA based on MACD, with conditions  :

LONG if MACD_Historam > 0

SHORT if MACD_Histogram<0

- The Known if we close order or set Fix Take profit , the expert will open new order at Same Exit Point , the code above will define the first HISTOGRAM Tick only to open trade and wait the reverse signal to open New Trade.

Alain Verleyen
40765
Alain Verleyen  

So what ?

Your code is not even reliable. Why are declaring a variable "select" you don't check it, you have to do it.

The last order closed is not necessarily the greatest index, you have to check close time.