• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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.
    BertrandNinjaTrader Customer Service

    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.
      BrandonNinjaTrader Customer Service

      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
          BrandonNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by dtl-saw, Today, 03:36 PM
          0 responses
          2 views
          0 likes
          Last Post dtl-saw
          by dtl-saw
           
          Started by williamzz, Today, 02:04 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Started by jtrading82, Today, 01:55 PM
          3 responses
          21 views
          0 likes
          Last Post NinjaTrader_Tyler  
          Started by StevenNelson, Today, 01:00 PM
          3 responses
          18 views
          0 likes
          Last Post NinjaTrader_Tyler  
          Started by allinthechart, Today, 12:21 PM
          0 responses
          8 views
          0 likes
          Last Post allinthechart  
          Working...
          X