Backtest resullt with limit orders too close to market level

Forums ProRealTime English forum ProRealTime platform support Backtest resullt with limit orders too close to market level

  • This topic has 7 replies, 2 voices, and was last updated 6 years ago by avatarJan.
Viewing 8 posts - 1 through 8 (of 8 total)
  • #75902
    Jan

    Dear all,

    I experienced that PRT-backtest results includes limit orders which are too close to market level, which will not be executed.  Obviously the PRT backtest results are not correct if they include results from orders which are not executed by the broker.  (The broker IG does not execute limit orders which are too close to market level.)

    The topic that limit orders too close to market are not executed was already discussed at https://www.prorealcode.com/topic/order-level-too-close-to-market-level-with-limit-buy-order/

    ===>>> I wish that the PRT-backtest follows the broker ordering and it shows backtest results until the limit order which is too close to market level, with a clear message that it can not proceed due to this limit order too close to market.  

     

    The problem appears with me when I use the following (part of my code);

     

    Any comments welcome.

    Kind regards,  Jan

    #75905

    Please use the ‘Insert PRT Code’ button when putting code in your posts. I have tidied your post up for you. 🙂

    Why not just set a minimum distance that is bigger than the spread.

     

    1 user thanked author for this post.
    #75938
    Jan

    Dear Vonasi,

    thanks for your reply. and in future I will use  ‘Insert PRT Code’ button for

    First I want to mention that I was not happy that back testing did not show me the problem of stopping my promising live trading strategy when limit orders are too close to market level, I would expect and therefore I have asked for PRT backtest programming taking into account this problem.

    Thank you for your solution, but 1 comment/question:

    if I do understand it correctly, a trade is triggered, based on the conditions measured at the last (closed) bar, but the trade is actually done at the (next) bar’s open. However the close and the next bar open can be different, at least I have seen this at the DAX, is therefore your formula “MaxPrice = close – Spread” still applicable ?

    Is rewriting your code to “MaxPrice = open  Spread ” better and possible?

    Thanks for the response in advance.

    Kind regards, Jan

     

    #75939
    Jan

    Dear Vonasi,

    A second question I have is whether the spread could be halved in the calculation of the limit price to avoid limit orders too close to the market level?

    The spread, at least at broker IG.com, is set 50% below and 50% above the close  (or open). So if the total spread would be 4, as in your coding example, would  MaxPrice = close  0,5 * Spread work to set a minimum distance that is bigger than the spread ? This instead of reducing the whole spread from the close (your code  MaxPrice = close   Spread)

    Thanks again in advance for your answer.

    Kind regards, Jan

    #76009

    OPEN instead of CLOSE would not work. The only data available is that of the last closed candle so OPEN would refer to the open of that candle and not the new one. Gaps are a problem. Maybe when MTF is fully available it will solve the issue by allowing us to use faster time frames to open trades decided on slower time frames and so have a better chance of getting in after a gap by not trading on the first bar of a day/week whatever.

    As for the spread of 4 – it was just a number plucked out of the air. Personally I think that if you are in a position where you have a stop of 4 pips then you would be better off to just close the trade as 99% of the time it will close anyway but at a 4 pip worse price than if you had just closed it. Close stops and especially very close stops will eat profit in any strategy IMHO.

    1 user thanked author for this post.
    avatar Jan
    #76013
    Jan

    Thanks for your clarification of my question of the Open : “OPEN instead of CLOSE would not work.”, now that is clear for me and solved.

    I am sorry, but I do not understand why you wrote “As for the spread of 4 – it was just a number plucked out of the air. Personally I think that if you are in a position where you have a stop of 4 pips then you would be better off to just close the trade as 99% of the time it will close anyway but at a 4 pip worse price than if you had just closed it. Close stops and especially very close stops will eat profit in any strategy IMHO.”

    Could you respond on the code below, where I adjusted your code a very little (, that was also my second question before ). In my opinion you only need to correct half of the spread to become below the spread for a buy limit order as the actual price is always in the middle of the spread.

    Thanks in advance.

     

    #76014

    Yes your code would work but would be just the same if you set spread = 2!

    My point was that if your strategy is getting stopped because the stop is too close then in my opinion that is your strategy trying to tell you something as very close stops will just get hit all the time and slowly empty your account – so why even think of having a very close stop?

    1 user thanked author for this post.
    avatar Jan
    #76024
    Jan

    Dear Vonasi,

    Thanks for your response again.

    Just for myself ,  I like to code the spread (diff buy – sell)  , which you also set in the PRT-backtests  at “Spread”,  as Spread divided  by 2.

    Remains the difference between close and next bar open, which is very small when using 5 min bars. For my strategy a correction of 0,5 is sufficient.

    ==> I still wish that the PRT-backtest follows the broker ordering and it shows backtest results  which stops in case a  limit order which is too close to market level, could not be executed, with a clear message that it can not proceed due to this limit order too close to market.

    Can it put somewhere on the PRT wish-list for improvements or at least clearly mentioned in the programming manual ?  How to proceed in this ?

    Kind regards, Jan

     

     

Viewing 8 posts - 1 through 8 (of 8 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login