Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator to count bars?

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

    #16
    Originally posted by kabott View Post
    and how do i use the value?

    this wont compile

    if(CountIf(delegate {return Close[0] > Open[0];}, 50));

    UpCandles =UpCandles +1;

    else

    UpCandles = 0;


    [ATTACH]21281[/ATTACH]
    You may be overthinking your solution. CountIf does the counting if a certain condition is met. You want the number of candles where the close is greater than the open, so all you need is:
    Code:
    int NumBullishCandle = CountIf(delegate {return Close[0] > Open[0];}, 50);

    Comment


      #17
      Thank you very much Koganam!!

      i had this working but couldn't compare both values


      DrawTextFixed("Up",CountIf(delegate {return Close[0] >Open[0];}, periods).ToString("N0"), TextPosition.TopRight ,Color.White,new Font ("Arial", 20), Color.Black, Color.Green, 10);

      DrawTextFixed("Dn",CountIf(delegate {return Close[0] < Open[0];}, periods).ToString("N0"), TextPosition.BottomRight ,Color.White,new Font ("Arial", 20), Color.Black, Color.Red, 10);


      now i am, thank you man!!

      Comment


        #18
        Originally posted by NinjaTrader_RyanM1 View Post
        You could custom code a counter, but using built-in method CountIf() should work well for this:
        http://www.ninjatrader.com/support/h...t7/countif.htm
        Hello Ryan, how would you print the count?

        For example I have this code
        PHP Code:
        if (CountIf(() => High[0] - Low[0] >= 25*TickSize5) > 0)
        {
             Print(
        "# of Bar Ranges >= 25 Ticks : " + ?);


        What do i substitute the"?'" with?

        It's supposed to means, if over the previous 5 Bars there is any (>0) bar whose range is greater or equal 25 ticks, then print the number of bars that meet that condition.

        For illustration example, the Countif() would return 2 (for Bar[2] and Bar[3] below)

        High[0] - Low[0] (Bar[0]) = 7 ticks

        High[0] - Low[0] (Bar[1]) = 12 Ticks

        High[0] - Low[0] (Bar[2) = 31 ticks

        High[0] - Low[0] (Bar[3]) = 29 Ticks

        High[0] - Low[0] (Bar[4]) = 21 Ticks

        Thanks!



        I've found a way with the Draw.FixedText method to draw it on the chart without variable declaration
        PHP Code:
        protected override void OnBarUpdate()
        {
             if(
        CurrentBar 5)
             {
                  return;
             }

             if (
        CountIf(() => High[0] - Low[0] >= 25*TickSize5) > 0)
             {
                 
        Draw.TextFixed(this"myTextFixed"CountIf(() => High[0] - Open[0] >= 25*TickSize5).ToString(), TextPosition.BottomRightChartControl.Properties.ChartTextChartControl.Properties.LabelFontBrushes.BlueBrushes.Transparent0);
             }


        but for the print it needs variable declaration

        PHP Code:
        namespace NinjaTrader.NinjaScript.Indicators
        {
             public class 
        up25 Indicator
             
        {
                  private 
        string up25;
             ... 
        PHP Code:
        if (CountIf(() => High[0] - Low[0] >= 25*TickSize5) > 0)
        {
             
        up25 CountIf(() => High[0] - Open[0] >= 25*TickSize5).ToString();
             Print(
        "up25 : " up25);


        With output
        PHP Code:
        up25 2
        up25 
        3
        up25 
        3
        up25 
        4
        up25 

        Last edited by PaulMohn; 02-22-2022, 12:44 PM.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by algospoke, 04-17-2024, 06:40 PM
        6 responses
        48 views
        0 likes
        Last Post algospoke  
        Started by arvidvanstaey, Today, 02:19 PM
        4 responses
        11 views
        0 likes
        Last Post arvidvanstaey  
        Started by samish18, 04-17-2024, 08:57 AM
        16 responses
        61 views
        0 likes
        Last Post samish18  
        Started by jordanq2, Today, 03:10 PM
        2 responses
        9 views
        0 likes
        Last Post jordanq2  
        Started by traderqz, Today, 12:06 AM
        10 responses
        19 views
        0 likes
        Last Post traderqz  
        Working...
        X