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 fx.practic, 10-15-2013, 12:53 AM
              5 responses
              5,404 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by Shai Samuel, 07-02-2022, 02:46 PM
              4 responses
              95 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by DJ888, Yesterday, 10:57 PM
              0 responses
              8 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by MacDad, 02-25-2024, 11:48 PM
              7 responses
              159 views
              0 likes
              Last Post loganjarosz123  
              Started by Belfortbucks, Yesterday, 09:29 PM
              0 responses
              8 views
              0 likes
              Last Post Belfortbucks  
              Working...
              X