Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Lookback Period in CrossAbove

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

    Lookback Period in CrossAbove

    Relative newbie here.

    I have a few test strategies using the CrossAbove and CrossBelow methods. If the lookback period is set to zero in these, I get no trades in my backtests. It's unclear to me why the lookback period needs to be >0, when the other indicators I am working with don't seem to have this requirement. Further, when actually run the simulator, trades seem to be executing one bar later than they should based on when the crosses are occurring.

    Any ideas?

    Thanks

    #2
    Originally posted by Trader5555 View Post
    Relative newbie here.

    I have a few test strategies using the CrossAbove and CrossBelow methods. If the lookback period is set to zero in these, I get no trades in my backtests. It's unclear to me why the lookback period needs to be >0, when the other indicators I am working with don't seem to have this requirement. Further, when actually run the simulator, trades seem to be executing one bar later than they should based on when the crosses are occurring.

    Any ideas?

    Thanks
    What would a lookback period of zero mean? A cross on the last zero bars? That does not make sense. A cross must have happened relative to at least one bar.

    Comment


      #3
      Originally posted by Trader5555 View Post
      Relative newbie here.

      I have a few test strategies using the CrossAbove and CrossBelow methods. If the lookback period is set to zero in these, I get no trades in my backtests. It's unclear to me why the lookback period needs to be >0, when the other indicators I am working with don't seem to have this requirement. Further, when actually run the simulator, trades seem to be executing one bar later than they should based on when the crosses are occurring.

      Any ideas?

      Thanks
      CrossAbove or CrossBelow will need to occur in the last 1 bar or greater. There is no way to check for a cross above/below 0 bars ago.

      For the simulator, are you running that strategy on Calculate On Bar Close set to True or False? In real-time, if you want the strategy to enter the position at the point these two values cross, you would need to run on COBC = false. When set to true, the strategy will not take action until that condition is true and the next bar has closed.

      More information on this property can be found below:

      MatthewNinjaTrader Product Management

      Comment


        #4
        Originally posted by NinjaTrader_Matthew View Post
        CrossAbove or CrossBelow will need to occur in the last 1 bar or greater. There is no way to check for a cross above/below 0 bars ago.

        For the simulator, are you running that strategy on Calculate On Bar Close set to True or False? In real-time, if you want the strategy to enter the position at the point these two values cross, you would need to run on COBC = false. When set to true, the strategy will not take action until that condition is true and the next bar has closed.

        More information on this property can be found below:

        http://www.ninjatrader.com/support/h...onbarclose.htm
        The COBC must have been the problem. Does this work the same way when backtesting? Changing this does not seem to alter my backtest results. I had been thinking, in response to koganam's post, that if you're calculating on bar close then a lookback period of 0 references the bar that just closed, and 1 references the previous bar.

        Comment


          #5
          Hello,

          When backtesting, COBC will always be true. There is no interbar granularity when backtesting.
          MatthewNinjaTrader Product Management

          Comment


            #6
            Matthew,
            Sorry for the long latency on this thread. I want to be certain I understand the proper order of things. Assuming a script with a simple CrossAbove with a lookback of one and EnterLong if CrossAbove is true, the steps NT will take upon bar close are:

            1. Check if CrossAbove is true
            2. If true, enter long order immediately

            Do I have this correct, or is there another bar's worth of wait time before a trade will be entered? I ran the simulator with two copies of the same strategy, one with COBC set to true and one to false, and order timing did not seem to be affected.

            Thank you

            Comment


              #7
              Hello,

              When you run on historical data. COBC is always true. You can only run COBC = false in a live market. It will open on the open of the next bar after the condition is true for entry in historical. Whereas in live it will submit instantly at the close of the bar.

              Comment


                #8
                In fact, that's a very interesting point. I would prefer to know if there is a cross on bar X, i.e.
                CrossAbove(Close, SMA, X) should have returned true if the crossing occurred at bar X. This would have given me an information about the cross AND when this cross has occurred.

                In contrast, the current version only tells that the cross occurred somewhen.

                Both approaches are quite equivalent but for the current version I would expect an error message when lookbackperiod = 0

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ghoul, Today, 06:02 PM
                0 responses
                7 views
                0 likes
                Last Post ghoul
                by ghoul
                 
                Started by Barry Milan, Yesterday, 10:35 PM
                6 responses
                18 views
                0 likes
                Last Post Barry Milan  
                Started by DanielSanMartin, Yesterday, 02:37 PM
                2 responses
                13 views
                0 likes
                Last Post DanielSanMartin  
                Started by DJ888, 04-16-2024, 06:09 PM
                4 responses
                13 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by terofs, Today, 04:18 PM
                0 responses
                12 views
                0 likes
                Last Post terofs
                by terofs
                 
                Working...
                X