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

CrossAbove / CrossBelow

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

    CrossAbove / CrossBelow

    NT Team,

    It appears the CrossAbove and CrossBelow indicators may have a bug.

    Using CrossAbove(IDataSeries series1, IDataSeries series2, int lookBackPeriod), where lookBackPeriod = 1, it appears the indicator is designed along the lines of if the prior series1 value is less than the prior series2 value and the current series1 value is greater than the current series 2 value than return true, else false. That is:
    if (series1[1] <= series2[1] && series1[0] > series2[0])
    {
    true;
    else
    false;
    }

    While this will be correct most the time there is an exception. In the event series1 has been above series2 for the last several bars, then in the next bar series1 dips to EQUAL series2, and in the following bar series1 remains above series two this would result in the CrossAbove indicator returning "true" when a cross above has not occurred.

    Any input would be appreciated.
    Thanks
    Shannon

    #2
    Shannon, thanks for your post - do you have a reproducible scenario so we can check into this?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Bertrand,

      Apologies for the tardy reply.

      Logically, CrossAbove and CrossBelow formulas, with the same settings should alternate when both placed in a script as price moves from above to below Series2 and vice versa. As shown the in the below listing this is not the case where CrossAboves or CrossBelows can occur consecutively. This occurs where the bar prior to the second consecutive CrossAbove / CrossBelow has its Close equal to the SMA(24).

      On the ES 09-09 1min, while there are many many CrossAboves / Crossbelows, below are two examples where there are two consecutive CrossAboves / Crossbelows:

      'UpBar' = CrossAbove(Close, SMA(Close, 24),1) = 13/06/2009 2:24:00 AM
      'Downbar' = CrossBelow(Close, SMA(Close, 24),1) = 13/06/2009 2:25:00 AM
      'Downbar' = CrossBelow(Close, SMA(Close, 24),1) = 13/06/2009 2:41:00 AM
      'UpBar' = CrossAbove(Close, SMA(Close, 24),1) = 13/06/2009 2:43:00 AM

      'UpBar' = CrossAbove(Close, SMA(Close, 24),1) = 15/06/2009 11:26:00 PM
      'Downbar' = CrossBelow(Close, SMA(Close, 24),1) = 15/06/2009 11:32:00 PM
      'UpBar' = CrossAbove(Close, SMA(Close, 24),1) = 15/06/2009 11:59:00 PM
      'UpBar' = CrossAbove(Close, SMA(Close, 24),1) = 16/06/2009 12:06:00 AM
      'Downbar' = CrossBelow(Close, SMA(Close, 24),1) = 16/06/2009 12:15:00 AM


      Happy hunting
      Regards
      Shannon

      Comment


        #4
        Shannon,

        Not sure I entirely follow you. Once you have "crossed above" you need to come back down for it to be able to cross above another time.

        If you are running with CalculateOnBarClose = false, it is very possible to get a cross above = true while the bar is building, but ultimately have a cross above = false at the end of the bar which when coupled with a future bar may seem like two consecutive cross aboves.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh,

          Thank you for the reply. Apologies for my less than clear explanation.

          I agree 100% with your first statement, "Once you have 'crossed above' you need to come back down for it to be able to cross above another time". Though, to be complete I understand it to be "Once you have 'crossed above' you need to 'cross below' for it to be able to cross above another time".

          The script was run with CalculateOnBarClose = true. Please investigate the examples provided.

          Thanks
          Shannon

          Comment


            #6
            Shannon,

            Please try printing evaluations on every single bar and see what the values are between those events.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Josh,

              Not sure what you're asking.
              Just run the following script on the ES 09-09 1min.

              protectedoverridevoid OnBarUpdate()

              {

              if (CurrentBar < 100) return;
              // Set past SMA CrossAbove bars
              if (CrossAbove(Close, SMA(Close, 24),1))

              {
              Print (
              "'UpBar' = CrossAbove(Close, SMA(Close, 24),1) = " + Time.ToString());

              }

              // Set past SMA CrossBelow bars
              if (CrossBelow(Close, SMA(Close, 24),1))

              {
              Print (
              "'Downbar' = CrossBelow(Close, SMA(Close, 24),1) = " + Time.ToString());

              }
              }

              Shannon

              Comment


                #8
                Originally posted by Shansen View Post
                While this will be correct most the time there is an exception. In the event series1 has been above series2 for the last several bars, then in the next bar series1 dips to EQUAL series2, and in the following bar series1 remains above series two this would result in the CrossAbove indicator returning "true" when a cross above has not occurred.

                Any input would be appreciated.
                Thanks
                Shannon
                This is correct and is expected. I recall vaguely years ago we had internally discussed this and for whatever reason, it was implemented as you have pointed out. I will check into this again.
                RayNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by timmbbo, Today, 08:59 AM
                1 response
                2 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by KennyK, 05-29-2017, 02:02 AM
                2 responses
                1,281 views
                0 likes
                Last Post marcus2300  
                Started by fernandobr, Today, 09:11 AM
                0 responses
                2 views
                0 likes
                Last Post fernandobr  
                Started by itrader46, Today, 09:04 AM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by bmartz, 03-12-2024, 06:12 AM
                5 responses
                33 views
                0 likes
                Last Post NinjaTrader_Zachary  
                Working...
                X