extra pips on SELL orders

 

In my EA, I buy at the ASk, sell at the bid.

On all SELL orders, I set a target profit and a stop loss both with 3 pips added due to the spread. However, when I run this in the strategy tester, BUY trades show profits of 400, losses of 400, yet

SELL trades show profits of 430, losses of 430.

With the spread added, they should be the same shouldn't they?


   double TradeTargetPrice = 40;
   double TradeStopLoss = 40;
   double BufferShort = 0.0006;
   double BufferLong = 0.0009; //takes into account the spread should be more than 6

   double OvernightHigh = High[iHighest(NULL,PERIOD_H1,MODE_HIGH,diff,0)];
   double OvernightLow = Low[iLowest(NULL,PERIOD_H1,MODE_LOW,diff,0)];  
   double HighTime = TimeHour(Time[iHighest(NULL,PERIOD_H1,MODE_HIGH,diff,0)]);
   double LowTime = TimeHour(Time[iLowest(NULL,PERIOD_H1,MODE_LOW,diff,0)]);     

   double LongSL = (OvernightHigh+BufferLong)-(TradeStopLoss*Point);
   double LongTP = (OvernightHigh+BufferLong)+(TradeTargetPrice*Point);
   double ShortSL = (OvernightLow-BufferShort)+(TradeStopLoss*Point)+0.0003;
   double ShortTP = (OvernightLow-BufferShort)-(TradeTargetPrice*Point)-0.0003;

   if (debug==true) {Print("creating orders");}

   //if (OrdersTotal() == 0 && is_timetocreatependingorders == true)
   if (is_timetocreatependingorders == true)
      {
         //LONG
         RefreshRates();
         ticket=OrderSend(Symbol(),OP_BUYSTOP,Lotsize,OvernightHigh+BufferLong,NULL,LongSL,LongTP,"LONG",1,0,Green);
      
         if(!ticket)
            {
               int errorCode = GetLastError();
               if(errorCode != ERR_NO_RESULT ) 
                  logError("OrderSend", "Error", errorCode);
            }
   
         //SHORT
         RefreshRates();
         ticket=OrderSend(Symbol(),OP_SELLSTOP,Lotsize,OvernightLow-BufferShort,NULL,ShortSL,ShortTP,"SHORT",1,0,Red);
   
         if(!ticket)
            {
               errorCode = GetLastError();
               if(errorCode != ERR_NO_RESULT ) 
                  logError("OrderSend", "Error", errorCode);
            }
      }
 
SanMiguel:
anyone?

anyone?

 
SanMiguel:

In my EA, I buy at the ASk, sell at the bid.

On all SELL orders, I set a target profit and a stop loss both with 3 pips added due to the spread. However, when I run this in the strategy tester, BUY trades show profits of 400, losses of 400, yet

SELL trades show profits of 430, losses of 430.

You don't need to add the spread in this way. If you have e.g. a buy stop order with pending entry at 1.4200 and a stop loss at 1.4100, then it will get filled when the ask is at 1.4200 and closed when the bid is at 1.4100. Ditto on the t/p. And vice versa for sells rather than buys. In other words, the spread is "automatically factored in" to the s/l and t/p prices.


However, you do need to do what you're currently doing in terms of adding the spread to your long entry price. Just in case this isn't already clear to you, High[] gives you the highest bid price over your chosen period. If you used that as the buy-stop entry price, then you'd enter when the ask hit the historical bid level. Therefore, it makes sense to do what you're doing in terms of subtracting x (0.0006) from the short entry, and adding x plus the spread (0.0009) to the long entry. Though I'm not quite sure where 0.0006 comes from.