Error in strategy coding: open and closes signals are late one bar

Forums ProRealTime English forum ProOrder support Error in strategy coding: open and closes signals are late one bar

Viewing 8 posts - 1 through 8 (of 8 total)
  • #58696

    Hi everyone,

    I tried to code a very simple str in a simplified way. And when I pro backtest, I can see, that the open and closes signals are late one bar. Anyone experienced something similar? Any tips?

     

    The strategy as follows (long):

    Entry:

    Price must be at or above 50 SMA (close ›= Average [50](close)

    The setup bar’s close is lower, than the close of the bar two bar before (close[1]‹close[3])

    entry bar’s high is higher than the setup’s bar high (high›high[1])

     

    Exit:

    when a bar’s high is lower than the previous bar’s high (high‹high[1])

     

    And I can see the entry arrow not below the entry bar, but one bar later, and I can see the exit signal also one bar later than expected

     

    Kind regards

    George

    #58699

    For anyone to be of some help you should post your complete code.

    Roberto

    #58701

    Sorry, Roberto. Here it is! Thank you!

     

    #58703

    Topic moved to ProOrder support forum and code edited, please respect forums rules.

    #58707

    Sorry, I did not intend to break any rules…

    #58770

    I tested it on DAX, both 2-hour and 4-hour TF and it works perfectly as you can see from the attached pic.

    I outlines the 4 setup bars:

    • 0 = the current one (just closed, when the strategy is executed)
    • 1 = previous bar
    • 2 = second previous bar
    • 3 = third previous bar

    Next to them, on the right side, you’ll see the cyan arrow pointin yo the entry bar, yet

    Your code means:

    All is fine.

    You probably think the current bar (setup bar)= entry bar.  NO, the setup bar is the current (identified by 0) bar, just closed, while the entry bar is the next one which will open afterwards and you cannot reference it until it closes.

    Strategy are ALWAYS (no matter what TF) executed when each bar closes, BEFORE the next one is opened. So the current bar cannot be the next one (the entry bar) because it has not yet started.

    #58777

    Thank you Roberto!

    #58786

    Before your reply I noticed the “next bar open” in the “assisted ProBacktest creation” window. And it made clear, that its logic different from indicators. I created several indicators in the program, and it draws the arrow when the condition is met (on the entry bar and not one bar later). The strategy draws the arrow next bar open, so not below the entry bar. It is confusing, and may turn the profitability of the strategy upside down (not necessarily, but it can happen) .

    An example (dax long):

    The entry bar gives you the signal at 13.300. But it closes at 13.400.  The next bar opens with a 20 point gap up. So, the strategy enters at 13.420. Your stop is 20 points. It pulls back 40 points, and you are stopped out, and realise a loss. If your trade triggered at 13.300 you are not stopped out, and you realise profit.

    The higher high is such a condition which can be realised immediately, and activate the trade. If you trade 4 hour timeframe…a lot can happen till the next bar opens…

    So, when I noticed the next bar open condition in the window, I understood why the signals are late one bar. So from this point of view, the program works fine. But from trading, or risk point of view it has to be considered. If you have the trigger now, but if your trade is activated on the next bar open, it is an unforeseen risk. It can also happen that the trade should be negated, and the program just activates it instead.

    Is it possible to define the stop level below the setup bar? So with not a number, or %.

    Thank you for your time, and patience.

    Kind regards

    George

     

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