Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Find Max ammounts bars when close is above 10 ema line

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

    Find Max ammounts bars when close is above 10 ema line

    Hello Ninjatrader Team,

    how can I tell Ninjatrader ( in indicator mode) to tell me what was the Max amount of bars back when the close was higher than the 10 EMA line starting from today going backwards.


    I found this formula online but it not exactly correct.
    Code:
    int NumBullishCandle = CountIf(delegate {return Close[0] > EMA(10)[0];}, 20);
    Plot0.Set(NumBullishCandle);
    This formula starts to subtract when it fails this criteria. Also it maxes out at 20 but I needed it in infinite ammount..

    Also its going to be important to have it in Plot mode. Not print.

    Thank you

    #2
    Hello Wallsteetking,

    Thank you for your post.

    This formula starts to subtract when it fails this criteria
    I'm not sure what you mean by this. The CountIf() should maintain the same usage throughout the code.

    If you want to make it an infinite amount you can use CurrentBar in place of 20, however I would not recommend this unless you plan on ignoring the historical in the beginning, Otherwise, it will cause huge delays and lag in the chart.

    My recommendation instead would be to check when the Close is higher than the EMA(10) and then store a counter value

    if(Close[0] > EMA(10)[0])
    counter++;

    let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      I am not quite sure how to implement this.
      Is this correct....
      Code:
      if (Close[0] > EMA(10)[0])
      			
      				{	Counter++;
      					Plot0.Set(Counter++);
      				}
      when I do this I get (see picture) . What I need it to do is if the condition is not met. than start count again from zero.
      Attached Files

      Comment


        #4
        wallsteetking, would suggest doing the plot outside the condition then resetting the count to 0 if you see a close below the EMA simply.

        if (Close[0] > EMA(10)[0])
        Counter++;
        else
        Counter = 0;

        Plot0.Set(Counter);
        Last edited by NinjaTrader_Bertrand; 09-08-2014, 02:19 AM.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Thank you NinjaTrader_Bertrand this is what i was looking for.

          Comment


            #6
            Originally posted by NinjaTrader_Bertrand View Post
            wallsteetking, would suggest doing the plot outside the condition then resetting the count to 0 if you see a close below the EMA simply.

            if (Close[0] > EMA(10)[0])
            Counter++;
            else
            Counter = 0;

            Plot0.Set(Counter++);
            You mean
            Code:
            Plot0.Set(Counter);

            Comment


              #7
              You are right koganam, thanks for the spot.
              BertrandNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Dutch4756, Today, 04:57 PM
              0 responses
              6 views
              0 likes
              Last Post Dutch4756  
              Started by DerkWehler, 12-04-2024, 09:00 AM
              7 responses
              75 views
              3 likes
              Last Post RobEB
              by RobEB
               
              Started by _Gabor_, 12-03-2024, 12:16 PM
              4 responses
              28 views
              0 likes
              Last Post _Gabor_
              by _Gabor_
               
              Started by trelling, 11-28-2024, 01:50 PM
              6 responses
              53 views
              0 likes
              Last Post trelling  
              Started by nelslynn, Today, 03:52 PM
              0 responses
              6 views
              0 likes
              Last Post nelslynn  
              Working...
              X