Backtest resullt with limit orders too close to market level

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #75902 quote
    Jan
    Participant
    Veteran

    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);

    iLow = highest[3](Low)[1]  //the highest value from the last 3 lows
    
    IF Close crosses over Average[20](Close) ] THEN
    BUY 1 shares AT iLow limit     // limit buy levels should be buy below entry price (spread), if the set limit price is within the spread, the order is abandoned and the trading system is stopped
    
    endif
    
    

     

    Any comments welcome.

    Kind regards,  Jan

    #75905 quote
    Vonasi
    Moderator
    Master

    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.

    Spread = 4
    MaxPrice = close - Spread
    iLow = highest[3](Low)[1]  //the highest value from the last 3 lows
    iLow = min(iLow, maxPrice)
    
    IF Close crosses over Average[20](Close) ] THEN
    BUY 1 shares AT iLow limit     // limit buy levels should be buy below entry price (spread), if the set limit price is within the spread, the order is abandoned and the trading system is stopped
     
    endif
    Nicolas thanked this post
    #75938 quote
    Jan
    Participant
    Veteran

    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 quote
    Jan
    Participant
    Veteran

    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 quote
    Vonasi
    Moderator
    Master

    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.

    Jan thanked this post
    #76013 quote
    Jan
    Participant
    Veteran

    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.

    Spread = 4  //total spread buy and sell, the actual price is always in between !
    MaxPrice = close - Spread * 0,5 //you only need to correct half of the spread in my opinion to come below the buy entry spread
    iLow = highest[3](Low)[1]  //the highest value from the last 3 lows
    iLow = min(iLow, maxPrice)
     
    IF Close crosses over Average[20](Close) ] THEN
    BUY 1 shares AT iLow limit     // limit buy levels should be buy below entry price (spread), if the set limit price is within the spread, the order is abandoned and the trading system is stopped
     
    endif
    #76014 quote
    Vonasi
    Moderator
    Master

    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?

    Jan thanked this post
    #76024 quote
    Jan
    Participant
    Veteran

    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)
  • You must be logged in to reply to this topic.

Backtest resullt with limit orders too close to market level


Platform Support: Charts, Data & Broker Setup

New Reply
Author
author-avatar
Jan @janwd Participant
Summary

This topic contains 7 replies,
has 2 voices, and was last updated by Jan
7 years, 7 months ago.

Topic Details
Forum: Platform Support: Charts, Data & Broker Setup
Language: English
Started: 07/13/2018
Status: Active
Attachments: No files
Logo Logo
Loading...