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 JonesJoker, 04-22-2024, 12:23 PM
          8 responses
          41 views
          0 likes
          Last Post JonesJoker  
          Started by timko, Today, 06:45 AM
          0 responses
          3 views
          0 likes
          Last Post timko
          by timko
           
          Started by Waxavi, 04-19-2024, 02:10 AM
          2 responses
          38 views
          0 likes
          Last Post poeds
          by poeds
           
          Started by chbruno, Yesterday, 04:10 PM
          1 response
          44 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by Max238, Today, 01:28 AM
          1 response
          25 views
          0 likes
          Last Post CactusMan  
          Working...
          X