Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

calculate bars

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

    calculate bars

    I want calculate bars for example during one hour. How many bars up and down. And compare them. I think that's easy but my strategy don't work. But I'm not programmer.
    I often need calculate indexes and I don't know what function I can use. I use counter "++'
    This is part of my code:
    protected override void OnBarUpdate()
    { if ((ToTime(Time[0]) > 90000 && ToTime(Time[0]) < 100000) ) // весь день
    if (Close[0]>Close [1])

    { counter++;}
    else if (Close[0]< Close [1])
    { counter1++;}
    {if (counter1 !=0)
    k=(counter/counter1)*100;}
    else k=1;}
    Print(k);
    Where I did mistake?

    #2
    Thanks for the post Kotyk, we will give your code a run and let you know our thoughts.

    Comment


      #3
      Hello Kotyk,

      So I may assist you further can you please clarify how you are wanting to compare the up bars to the down bars?
      Please give an example of what you would like to see printed to the output window.

      Comment


        #4
        Originally posted by NinjaTrader_Brandon View Post
        Hello Kotyk,

        So I may assist you further can you please clarify how you are wanting to compare the up bars to the down bars?
        Please give an example of what you would like to see printed to the output window.
        I want to see the ratio of bars up and down during one hour for all period. Example, during 1 year from 9 to 10 hour up bars - 6000, down 7000 and k (ratio) is (6000/7000)*100=85.71.
        but in my code K =0 or 100.

        Comment


          #5
          Hello Kotyk,

          Thanks for your reply.

          You will need to ensure that your variable are set to doubles
          On the time settings you may want to use a <= to include a full 60 min
          To calculate if a bar is a up bar or down bar you will need to Close[0] < Open[0]
          I would also recommend renaming your variables to better define them

          I have provided an attachment of how I would approach this indicator.
          Attached Files

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          572 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          331 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          549 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          550 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X