How to correctly execute a partial take profit in Hedging account in Tester with OHLC 1 minute?

 

Hi,

for some time, I've been using market orders to execute partial take profits in my EA executed after my code inside OnTick identifies the market reached the desired partial take profit level. The problem is that such system has issues with backtesting with "OHLC 1 minute" mode: instead of the market orders being executed at or around the desired partial take profit price, they end up being done at the extreme of OHLC candle leading to false bigger profits not verified in "each tick" mode or in the real trading.

Example

The image above, from the Tester running in "OHLC 1 min", shows that: instead of being executed in the desired price, the partial take profit market orders were executed at the extreme of the candlestick giving a boosted, irrealistic profit over what "each tick" and real world gives:

Each Tick

(All this running my EA in PERIOD_M1)

One way to counter that would obviously be to use pending orders as partials. The problem is that, in hedging mode, this is not allowed. So how can I do my partial take profits in the exact desired price when backtesting with "OHLC 1 min"?

 

Hello Martin,

I am facing exactly the same problem.

Did you get to solve it anyway?

 

You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

  1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

  2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
              MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

  3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
    Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

 

It is the way OHLC is generated by tester. Prone to tester grails. Live with it or do not use it if you want to mimic the real history (every tick based on real ticks).

Reason: