need help with EA function

 

When a pending order is executed and then closed out at a loss, I need the EA to re-entry the order.

I have tried various ways of getting this done with no success. Is it not possible? It seems fairly simple.. can anyone help??

 

show some code..


//z

 
zzuegg:

show some code..


//z


int Count;
int Orders; 
   
   
int start()
{
//----
Orders=OrdersTotal();
Count=OrdersHistoryTotal()-1;

if(Orders>OrdersTotal())
{
OrderSelect(Count,SELECT_BY_POS,MODE_HISTORY);
if(OrderProfit() < 0)
   {
   OrderSend(Symbol(),OrderType(),OrderLots(),OrderOpenPrice(),7,OrderStopLoss(),OrderTakeProfit(),"",OrderMagicNumber(),0,CLR_NONE);
   }
}
//----
return(0);
   
}


 

it is not guaranteed that OrdersHistoryTotal()-1 is the last order..

You should store the ticket number of the order and check with:

if(OrderCloseTime()!=0){
  //Order is closed

//Long Orders:
if(OrderClosePrice()<=OrderStoploss)
 //SL  HIT

//Short Orders:
if(OrderClosePrice()>=0OrderStoploss && OrderStoploss!=0)
 //SL  HIT

}
 
if(OrderCloseTime()!=0){
  //Order is closed

OrderSelect only selects open trades, OrderCloseTime will always be zero

OrderSelect( ..., MODE_HISTORY) only selects closed trades, OrderCloseTime will always be nonzero


When a pending order is executed and then closed out at a loss, I need the EA to re-entry the order.
bool ClosedAtALoss = OrderProfit() < 0;
 
WHRoeder:

OrderSelect only selects open trades, OrderCloseTime will always be zero

OrderSelect( ..., MODE_HISTORY) only selects closed trades, OrderCloseTime will always be nonzero



int Count;
int ClosedAtALoss; 
int ClosedAtAProfit; 


int start()
  {
//----
Count = OrdersHistoryTotal()-1;


//Local Variables   
bool ClosedAtALoss = OrderProfit() < 0;
bool ClosedAtAProfit = OrderProfit() > 0;  


//Main 
if(OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 7) == true && ClosedAtALoss == true)
       {
       OrderSelect(Count,SELECT_BY_POS,MODE_HISTORY); 
       OrderSend(Symbol(),OrderType(),OrderLots(),OrderOpenPrice(),7,OrderStopLoss(),OrderTakeProfit(),"",OrderMagicNumber(),0,CLR_NONE); 
       }




//----
   return(0);
  }