• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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

            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

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by quinton77, Yesterday, 09:59 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_EricB  
                Started by akuntysh, Today, 12:02 AM
                0 responses
                2 views
                0 likes
                Last Post akuntysh  
                Started by Revan, Yesterday, 11:53 PM
                0 responses
                3 views
                0 likes
                Last Post Revan
                by Revan
                 
                Started by allangl, Yesterday, 10:50 PM
                0 responses
                7 views
                0 likes
                Last Post allangl
                by allangl
                 
                Started by jeffm, Yesterday, 10:47 PM
                0 responses
                4 views
                0 likes
                Last Post jeffm
                by jeffm
                 
                Working...
                X