Problem with triggered order

 
I have trouble with orders that trigger automatically.

When it is performed, the order is automatically triggered with new price and then the stop loss as well.

See the image:

This happens in the strategy tester. What can it be?

 
//Code part

double price=iClose(NULL,TimeFrame,0);
                     
double open = iOpen(NULL,TimeFrame,1);
double close = iClose(NULL,TimeFrame,1);
double high = iHigh(NULL,TimeFrame,1);
double low = iLow(NULL,TimeFrame,1);
                     
double tamanhoBarra;
double retracao;
double entrada;
double stop=0;
double take=0;

tamanhoBarra = open - close;
retracao = tamanhoBarra * (percent/100);
entrada = NormalizeTick(close + retracao);

stop=NormalizeTick(entrada-StopLoss*Scale);
take=NormalizeTick(entrada+StopGain*Scale);

trade.BuyStop(Contratos,entrada,NULL,stop,take,0,0,NULL);
 
Thiago Schappo :
I have trouble with orders that trigger automatically.

When it is performed, the order is automatically triggered with new price and then the stop loss as well.

See the image:

This happens in the strategy tester. What can it be?

On the EXCHANGE, a limit order (in this case Buy LImit) placed ABOVE the current price - immediately triggers.

  Types of pending orders

 
Thiago Schappo:
I have trouble with orders that trigger automatically.

When it is performed, the order is automatically triggered with new price and then the stop loss as well.

See the image:

This happens in the strategy tester. What can it be?

The order was not immediately triggered, it was 2 seconds later (placed at 10:15:00 at 100560, triggered at 10:15:02). So it seems normal.

For the stoploss it seems strange as the SL was at 100510 but triggered at 100545 and the deal is at 100535. However that's the last price that triggers order on WIN and we don't see it.

What testing mode are you using ? (real ticks or ...)

What MT5 build is it ?