SL being executed a lot sooner than expected

 

I'm creating a EA and testing on Strategy Tester, it works for hundreds of orders as expected but one specific trade is closing in 15 points instead of 40 points and I'm not sure why. Others actually close between 38-42 points, but 25 points seems too much.

It's a lot more complex but I was able to reduce the EA in this simple piece of code:

void OnTick()
{
        MqlTick latest_price;
        MqlTradeRequest mrequest;
        MqlTradeResult mresult;
        ZeroMemory(mrequest);

        SymbolInfoTick(_Symbol, latest_price);

        if (latest_price.time_msc == 1737044011967)
        {
                mrequest.action = TRADE_ACTION_DEAL;
                mrequest.price = NormalizeDouble(latest_price.ask, _Digits);
                mrequest.sl = NormalizeDouble(latest_price.ask - 40 * _Point, _Digits);
                mrequest.tp = NormalizeDouble(latest_price.ask + 40 * _Point, _Digits);
		mrequest.symbol = _Symbol;
                mrequest.volume = 0.01;
                mrequest.magic = 12345;
                mrequest.type = ORDER_TYPE_BUY;
                mrequest.type_filling = ORDER_FILLING_FOK;
                mrequest.deviation = 100;
         
                OrderSend(mrequest,mresult);
        }
}


I run the test with the following parameters:

 - Delay: zero latency, ideal execution

 - Modelling: every tick based on real ticks

 - Profit in pips for faster calculation: disabled


Here's the journal output:

and



Can anyone clarify why this is happening, please?

 
Tiago Viger Ortiz:

I'm creating a EA and testing on Strategy Tester, it works for hundreds of orders as expected but one specific trade is closing in 15 points instead of 40 points and I'm not sure why. Others actually close between 38-42 points, but 25 points seems too much.

It's a lot more complex but I was able to reduce the EA in this simple piece of code:


I run the test with the following parameters:

 - Delay: zero latency, ideal execution

 - Modelling: every tick based on real ticks

 - Profit in pips for faster calculation: disabled


Here's the journal output:

and



Can anyone clarify why this is happening, please?

Tiago Viger Ortiz:
mrequest.sl = NormalizeDouble(latest_price.ask - 40 * _Point, _Digits);                 mrequest.tp = NormalizeDouble(latest_price.ask + 40 * _Point, _Digits);
buy execute on bid, sell executes on ask. if you are selling, tp should be bid
 
Rajesh Kumar Nait #:
buy execute on bid, sell executes on ask. if you are selling, tp should be bid
Correction: buy at ask and sell on bid. Here is example so adjust points as you wish with correction at your code

Code Base

Buy Sell on your Price

Dark Ryd3r, 2021.06.26 18:04

Buy Sell on your price, Choose Market order, Pending Limit order or Pending Stop Order

 
Tiago Viger Ortiz:

I'm creating a EA and testing on Strategy Tester, it works for hundreds of orders as expected but one specific trade is closing in 15 points instead of 40 points and I'm not sure why. Others actually close between 38-42 points, but 25 points seems too much.

It's a lot more complex but I was able to reduce the EA in this simple piece of code:


I run the test with the following parameters:

 - Delay: zero latency, ideal execution

 - Modelling: every tick based on real ticks

 - Profit in pips for faster calculation: disabled


Here's the journal output:

and



Can anyone clarify why this is happening, please?

Check SYMBOL_TRADE_STOPS_LEVEL , spread at that tick, and actual TP hit price. Use mresult.retcode and log tick data around 1737044011967 .