Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculate On Bar Close - Unexpected Results

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Calculate On Bar Close - Unexpected Results

    NT Support:

    I am currently running a test using the sample SMA Strategy with CalculateOnBarClose set to False.

    It seems to work as expected, but I noticed something was not consisent with the expected behavior.

    A CrossBelow was fire, and the system went short. This was expected. Then after a few bars, the current bar with the issue spiked up thus causing a CrossAbove and getting Long, but then after the bar closed, you can see that it did not really CrossAbove (the sma) and it left the trade Long when it should clearly be straight. Only after a stop loss did it get out of the trade.

    So again, position was Short.

    Some bars go by and the SMA is slowly creeping up with the fast catching up to the slow.

    A during one of the later bars, a spike up happened, firing a CrossAbove IntraBar and the Closed Current Position, and put the system Long 1.

    (all fine up until this point).

    Now intrabar we also didn't hold that spike and the downtrend continued, the SMA is clearly inversed to the downside and we did not get put back short again, instead it left us long even though it clearly crossed back below intrabar (fast cut down through the slow).

    Could you elaborate in regards to how this might occur and propose a solution to preventing it other than COBC = True?


    Thank you in advance,

    #2
    The condition was evaluated to true and so it placed a trade, just because the condition is no longer true does not mean it will close that trade. Works as expected. There is no logic saying if the condition is all of a sudden not true to place a closing trade.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Josh View Post
      The condition was evaluated to true and so it placed a trade, just because the condition is no longer true does not mean it will close that trade. Works as expected. There is no logic saying if the condition is all of a sudden not true to place a closing trade.
      Josh,

      I understand. But I do not believe your answer applies to my question per se. If we fired a crossAbove intrabar during an up spike, then it should put us long, got that. Likewise, when the spike dies and then reverses, the SMA is now inverted with fast back below the slow (short), but it DIDN'T FIRE a trade reflecting that. I checked the logs and orders.

      Something doesn't make sense here. I believe there is a logical explanation, but the one you are giving me I don't believe applies here :-(

      Comment


        #4
        r2kTrader,

        CrossAbove/Below conditions are determined based on the lookback period set and the latest tick information. It does not compare latest tick versus previous tick. You are likely looking at the previous bar's close versus the current tick. If it crosses above then it is true, if it falls back down on the same bar, the cross below is still NOT true because there was no cross below based on the previous bar. As such, no short trade will be placed.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh,

          This was helpful. So I want to be sure I get this correct.

          Note: Calc On Bar Close = False

          Based on the fact the COBC = false, why would it be looking at the prior bar? My lookback is the default, which is 1 bar I assume. I am not saying if price Crosses above, I am saying if SMA value crosses, so if it crossed above, didn't it cross below when it resumed going lower?

          I kind of understand what you are saying, but I don't see how we can crossabove, and then not cross back below. Your logic makes sense to me with COBC = true, because we crossed above, but didn't close above, etc.

          Bear in mind, as I look at the chart, the final plot showed that the fast did not "close" above the slow, rather the price action visited above on that spike and retraced.

          Thanks


          Originally posted by NinjaTrader_Josh View Post
          r2kTrader,

          CrossAbove/Below conditions are determined based on the lookback period set and the latest tick information. It does not compare latest tick versus previous tick. You are likely looking at the previous bar's close versus the current tick. If it crosses above then it is true, if it falls back down on the same bar, the cross below is still NOT true because there was no cross below based on the previous bar. As such, no short trade will be placed.

          Comment


            #6
            r2kTrader,

            CrossAbove/Below does not look at the last tick versus the prior tick. It looks at last tick versus prior bar. This is the way it has always worked. You are checking for a condition to cross above condition to be true on a bar. If it moved above on that bar it is true. If it now moves back down it is now back to false. Becoming false again does not trigger a cross below logic. This is what it is designed to do and it behaves as expected. If you want some more logic in there you need to self program it.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Josh View Post
              r2kTrader,

              CrossAbove/Below does not look at the last tick versus the prior tick. It looks at last tick versus prior bar. This is the way it has always worked. You are checking for a condition to cross above condition to be true on a bar. If it moved above on that bar it is true. If it now moves back down it is now back to false. Becoming false again does not trigger a cross below logic. This is what it is designed to do and it behaves as expected. If you want some more logic in there you need to self program it.
              So CrossAbove works as follows?

              SMA fast = 400
              SMA slow = 390

              Current bar has 3 minutes left on 5m bar. Currently Fast is above Slow and we are long 1 car.

              during the bar, we get a pullback to say 380, this would fire a CrossBelow?

              But if it reverts back to say 405, it won't fire a CrossAbove?

              hmm, yeah, that makes perfect sense to the layman, lol.

              I hear what you are saying. If I am understanding this correctly, as per the example, we started out with a CrossAbove under our best, hence crossAbove was true and put us in trade. But when we intrabar crossedBelow firing a false, it doesn't "undo" the CrossAbove, that value is still essentially true ? I hope you can see how this might be a bit confusing. I am sure with COBC=on, it's a little more black and white.

              At least it is behaving as expected, thanks for the time to explain this to me and I hope it helps someone else.

              Comment


                #8
                r2kTrader, you're correct in understanding CrossAbove and CrossBelow are not connected in their outcomes, hence this can lead to whipsaws if you run this to update on every tick or CalculateOnBarClose = false. This is expected and you would need to add custom logic helping preventing your condition becoming true / false intrabar too many times.

                Comment


                  #9
                  Calculate On Bar Close - Strategy with Indicator

                  Support,

                  Which takes precedence as I just noticed/realized that the SMA has a General Property for COBC.

                  If Strategy has COBC = false, but SMA Indicator has General Property set to COBC=True, will the SMA be aligned and subjected to its own property, or does the Strategy Property take precedence?

                  Thank you,


                  r2kTrader

                  Comment


                    #10
                    r2kTrader,

                    Your indicators should not have any COBC line. There is a bug with it so please do not use any COBC lines except in the overarching script.

                    If IndicA calls IndicB, only IndicA should have a COBC line if at all.
                    If Strategy calls IndicA, only Strategy should have a COBC line if at all.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Josh View Post
                      r2kTrader,

                      Your indicators should not have any COBC line. There is a bug with it so please do not use any COBC lines except in the overarching script.

                      If IndicA calls IndicB, only IndicA should have a COBC line if at all.
                      If Strategy calls IndicA, only Strategy should have a COBC line if at all.
                      This explains the anomoly I was seeing.

                      Comment


                        #12
                        Hi,
                        To my relief I just stumbled upon this thread and this seems to explain my NT 6.5 strategy's eratic behavior.

                        Does anyone know of a work around for this without resorting to the (un-backtestable) OnMarketData() method?

                        My strategy needs COBC = false
                        but the custom indicator that drives most of it needs COBC = true

                        Thank you in advance,
                        Stevo

                        Comment


                          #13
                          Is this the same

                          I have noticed this in an indicator ... should it be commented out when used in a strategy??

                          indicator.CalculateOnBarClose = CalculateOnBarClose;

                          Comment


                            #14
                            Jon, this should be commented out if you plan on calling the indicator programmatically.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            648 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            369 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            108 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            572 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            573 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X