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

How do I specify a rising sma for the last 10 bars?

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

    How do I specify a rising sma for the last 10 bars?

    I need help with code example on how to specify that if an sma is rising for the last 10 bars then enter a trade. Please help. Thank you

    #2
    Hello relogical,

    Thank you for your post.

    As there is not a period input for rising, this information would need to be found with a loop.

    For example:

    Code:
    bool isRising = true;
    for (int i = 0; i<10; i++)
    {
    if (!Rising(SMA(19)))
    {
    isRising = false;
    }
    }
    if (isRising)
    {
    // has been rising for the last 10 bars
    // execute code
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi relogical,

      You are correct, the Rising doesn't work that way. My apologies.
      Code:
      bool isRising = true;
      for (int i = 0; i<10; i++)
      {
      if (SMA(19)[i] <= SMA(19)[i+1])
      {
      isRising = false;
      }
      }
      if (isRising)
      {
      // has been rising for the last 10 bars
      // execute code
      }
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_ChelseaB View Post
        Hi relogical,

        You are correct, the Rising doesn't work that way. My apologies.
        Code:
        bool isRising = true;
        for (int i = 0; i<10; i++)
        {
        if (SMA(19)[i] <= SMA(19)[i+1])
        {
        isRising = false;
        }
        }
        if (isRising)
        {
        // has been rising for the last 10 bars
        // execute code
        }
        Thanks.

        I deleted my own post (which is why there appears to be a gap here!) before you posted again, Chelsea, because I'd realised I'd made a mistake myself - relogical was asking about a rising SMA, not just pure price rises - and I didn't have time to correct it.

        Although 'Rising' doesn't allow you to specify bar numbers, the function 'Slope' does, as in:

        Code:
        Slope(SMA(19), 1, 0)
        I've found this quite helpful on occasion.

        Comment


          #5
          Hi arbuthnot,

          Ah, couldn't confirm the name after I saw the post was deleted. Thanks for commenting on this, it made me realize the mistake.

          The slope would measure between the first and last point, ignoring all points in between.So I guess its a question of granularity.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            A very important statement must be put:

            if (CurrentBar < 10) return;
            or

            if (CurrentBar >= 10) {
            // do your checking stuff here

            }
            Cheers,
            Pi
            ninZa
            NinjaTrader Ecosystem Vendor - ninZa.co

            Comment


              #7
              Originally posted by ninZa View Post
              A very important statement must be put:



              or



              Cheers,
              Pi
              Thanks, ninZa. The number of times I forgot to put that in a script and so it failed to work defies my capacity for counting!

              I would add that, in this specific example, given that the SMA parameter is 19 - as has been used in this thread - must be greater than the number of bars being checked for the 'rising' condition, I'd adjust this to:

              if (CurrentBar < 19) return;

              Comment


                #8
                Originally posted by arbuthnot View Post
                Thanks, ninZa. The number of times I forgot to put that in a script and so it failed to work defies my capacity for counting!

                I would add that, in this specific example, given that the SMA parameter is 19 - as has been used in this thread - must be greater than the number of bars being checked for the 'rising' condition, I'd adjust this to:

                if (CurrentBar < 19) return;
                You may want to make it 19, but that's not necessary
                * Putting 10 is to make sure you have no errors.
                * Putting 19 is to make sure you have no errors + you have a true SMA value
                (for CurrentBar < 19, the value of SMA(19) still exists, but it's not accurate)

                Thanks.
                Pi
                Last edited by ninZa; 12-26-2014, 07:46 PM.
                ninZa
                NinjaTrader Ecosystem Vendor - ninZa.co

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Skifree, Today, 03:41 AM
                1 response
                4 views
                0 likes
                Last Post Skifree
                by Skifree
                 
                Started by usazencort, Today, 01:16 AM
                0 responses
                1 view
                0 likes
                Last Post usazencort  
                Started by kaywai, 09-01-2023, 08:44 PM
                5 responses
                603 views
                0 likes
                Last Post NinjaTrader_Jason  
                Started by xiinteractive, 04-09-2024, 08:08 AM
                6 responses
                23 views
                0 likes
                Last Post xiinteractive  
                Started by Pattontje, Yesterday, 02:10 PM
                2 responses
                23 views
                0 likes
                Last Post Pattontje  
                Working...
                X