Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 alifarahani, Today, 09:40 AM
          4 responses
          21 views
          0 likes
          Last Post alifarahani  
          Started by gentlebenthebear, Today, 01:30 AM
          3 responses
          16 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by PhillT, Today, 02:16 PM
          2 responses
          7 views
          0 likes
          Last Post PhillT
          by PhillT
           
          Started by Kaledus, Today, 01:29 PM
          3 responses
          11 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by frankthearm, Yesterday, 09:08 AM
          14 responses
          47 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Working...
          X