Strange stop loss execution

 

I have an EA that places 2 trades with size 0.1  with the same stoploss

Running in Strategy tester

The trade hits stoploss  a while later    with a sell of 1.4 lots.

Where the heck did the size 1.4 come from???  Must be missing something vital in my code or what?


2013.12.10 21:48:41    Core 1    2013.12.04 14:15:40   order performed sell 1.40 at 1.35754 [#162 sell 1.40 EURUSD at 1.35754]
2013.12.10 21:48:41    Core 1    2013.12.04 14:15:40   deal performed [#162 sell 1.40 EURUSD at 1.35754]
2013.12.10 21:48:41    Core 1    2013.12.04 14:15:40   deal #162 sell 1.40 EURUSD at 1.35754 done (based on order #162)
2013.12.10 21:48:41    Core 1    2013.12.04 14:15:40   stop loss triggered buy 1.40 EURUSD 1.35967714 sl: 1.35754 tp: 1.36561 [#162 sell 1.40 EURUSD at 1.35754]        <<<<<<<<<<<<<<<<<     1.4   ?????
2013.12.10 21:48:41    Core 1    2013.12.04 14:08:00   [PlaceOrder]: Trade request has been successfully executed, order volume = 0.1
2013.12.10 21:48:41    Core 1    2013.12.04 14:08:00   order performed buy 0.10 at 1.35961 [#161 buy 0.10 EURUSD at 1.35961]                                                             <<<<<<<
2013.12.10 21:48:41    Core 1    2013.12.04 14:08:00   deal performed [#161 buy 0.10 EURUSD at 1.35961]
2013.12.10 21:48:41    Core 1    2013.12.04 14:08:00   deal #161 buy 0.10 EURUSD at 1.35961 done (based on order #161)
2013.12.10 21:48:41    Core 1    2013.12.04 14:08:00   instant buy 0.10 EURUSD at 1.35961 sl: 1.35754 tp: 1.36561 (1.35954 / 1.35961 / 1.35954)
2013.12.10 21:48:41    Core 1    2013.12.04 14:08:00   [PlaceOrder]: Order checked
2013.12.10 21:48:41    Core 1    2013.12.04 14:08:00   [PlaceOrder]: Trade request has been successfully executed, order volume = 0.1
2013.12.10 21:48:41    Core 1    2013.12.04 14:08:00   order performed buy 0.10 at 1.35961 [#160 buy 0.10 EURUSD at 1.35961]                                                              <<<<<<<<
2013.12.10 21:48:41    Core 1    2013.12.04 14:08:00   deal performed [#160 buy 0.10 EURUSD at 1.35961]
2013.12.10 21:48:41    Core 1    2013.12.04 14:08:00   deal #160 buy 0.10 EURUSD at 1.35961 done (based on order #160)
2013.12.10 21:48:41    Core 1    2013.12.04 14:08:00   instant buy 0.10 EURUSD at 1.35961 sl: 1.35754 tp: 1.36261 (1.35954 / 1.35961 / 1.35954)

2013.12.10 21:48:41    Core 1    2013.12.04 14:08:00   [PlaceOrder]: Order checked


code:

//+------------------------------------------------------------------+
//| ConstructOrders                             ConstructOrders      |
//+------------------------------------------------------------------+ 
bool ConstructOrders(int indx,int type) 
 {
  double ordersize = 0.4;
  double lotsize= 0;
 
  if(NumberOfTrades >= 1)
    lotsize = MathRound(ordersize*100/NumberOfTrades)/100;
    
  Print(">>>>>>>>>>>>>>>>>>>>>>>Lotsize1: " + lotsize);
      
  lotsize = NormalizeDouble(lotsize,1);
  
  Print(">>>>>>>>>>>>>>>>>>>>>>>Lotsize2: " + lotsize);
  
  if(NumberOfTrades>=1)
   {
     PlaceOrder(type,indx,lotsize,StopLoss,FirstTP,"FXCMT_01");  
   }
   
  if(NumberOfTrades>=2)
   {
     PlaceOrder(type,indx,lotsize,StopLoss,2*FirstTP,"FXCMT_02");  
   }
    
   return true;
 }
//+------------------------------------------------------------------+
//| PlaceOrder                                       PlaceOrder      |
//+------------------------------------------------------------------+  
bool PlaceOrder(int type,int indx,double size, int SL_Value,int TP_Value,string Trade_ID)
{
  MqlTradeRequest request;
  MqlTradeCheckResult check_result;
  MqlTradeResult trade_result;
  string Pair;
  
  Pair = Pairs[indx];
  
  string moduleID = "PlaceOrder";
  
  ZeroMemory(request);   //Clear request
  
  request.action = TRADE_ACTION_DEAL;
  request.magic = MagicNumber;
  request.symbol = Pair;
  request.volume = size;
  request.deviation = 30;
  request.type_filling = ORDER_FILLING_FOK;
  request.comment = Trade_ID;
  
  if(type == BUY)
   {
    request.type = ORDER_TYPE_BUY;
    request.price = SymbolInfoDouble(Pair,SYMBOL_ASK);
    request.sl    = SymbolInfoDouble(Pair,SYMBOL_BID) - SL_Value*MyPoints[indx];
    request.tp    = SymbolInfoDouble(Pair,SYMBOL_ASK) + TP_Value*MyPoints[indx]; 
   }
   
  if(type == SELL)
   {
    request.type = ORDER_TYPE_SELL;
    request.price = SymbolInfoDouble(Pair,SYMBOL_BID);
    request.sl    = SymbolInfoDouble(Pair,SYMBOL_ASK) + SL_Value*MyPoints[indx];
    request.tp    = SymbolInfoDouble(Pair,SYMBOL_BID) - TP_Value*MyPoints[indx]; 
   }
  
  if(!OrderCheck(request,check_result))
   {
    D_Print(moduleID,"Order does not check! result: " + check_result.retcode);
    return false;
   }
  else
   D_Print(moduleID,"Order checked");
   
  if(OrderSend(request,trade_result))
   {
    D_Print(moduleID,"Trade request has been successfully executed, order volume = " +trade_result.volume);
    return true;
   }
  else
   D_Print(moduleID,"What does this mean?");

  D_Print(moduleID,"Error in trade reqest execution. Return code: "+trade_result.retcode);
  return false;
}
 
ingvar_e:

I have an EA that places 2 trades with size 0.1  with the same stoploss

Running in Strategy tester

The trade hits stoploss  a while later    with a sell of 1.4 lots.

Where the heck did the size 1.4 come from???  Must be missing something vital in my code or what?


Multiple deals on the same symbol combine to become one position . . . perhaps you had 14 x 0.1 lot sell deals on EURUSD ?  we can see 2 in the log excerpt you posted . . .  
 

Just found that out. Thanks anyhow.

Takes time to get the new way of order handling into the mindset. Working on porting a rather complex EA of mine from MQL4 to MQL5.

Reason: