• 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 vivekniwas, 04-18-2018, 06:49 AM
          5 responses
          590 views
          0 likes
          Last Post NinjaTrader_ChrisSch  
          Started by smcllr, Yesterday, 08:25 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_ChrisSch  
          Started by pol133, Today, 12:39 AM
          0 responses
          8 views
          0 likes
          Last Post pol133
          by pol133
           
          Started by giulia_brotzu, Yesterday, 10:09 PM
          0 responses
          4 views
          0 likes
          Last Post giulia_brotzu  
          Started by Woomera, Yesterday, 09:55 PM
          0 responses
          3 views
          0 likes
          Last Post Woomera
          by Woomera
           
          Working...
          X