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 wzgy0920, 04-20-2024, 06:09 PM
              2 responses
              27 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 02-22-2024, 01:11 AM
              5 responses
              32 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 04-23-2024, 09:53 PM
              2 responses
              49 views
              0 likes
              Last Post wzgy0920  
              Started by Kensonprib, 04-28-2021, 10:11 AM
              5 responses
              193 views
              0 likes
              Last Post Hasadafa  
              Started by GussJ, 03-04-2020, 03:11 PM
              11 responses
              3,235 views
              0 likes
              Last Post xiinteractive  
              Working...
              X