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

Counting Renko up and down bars

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

    Counting Renko up and down bars

    Hi everyone

    I'm simply trying to count the number of Renko ups and downs over a given period and get a ratio. Getting a weird problem with the plot even though it compiles OK. This is the code:

    Code:
    if (CurrentBar < LookBack)
            		return;
    		
    int CountUp = CountIf(delegate {return Close[0] > Open[0];}, LookBack);
    int CountDown = CountIf(delegate {return Close[0] < Open[0];}, LookBack);
    			
    double a = CountUp / (CountUp + CountDown);
    
                Plot0.Set( (double) a);
    With Plot0.Set( (CountUp) there's no problem, but:

    - Plot0.Set(a) plots to zero only

    - Plot0.Set( (double) a) it sometimes plots to zero and sometimes plots as the expected decimal.

    There are no errors in the log.

    Could someone please explain the best way to approach this.

    Many thanks in advance.

    #2
    Hello,

    This is because of the math you are doing.

    You are dividing a double number against a integer which will result in a 0.


    Here is a simple breakdown:

    Code:
                         Double  / int (Int+Int)
    double a = CountUp / (CountUp + CountDown);
    you would need to cast your int result as a double before dividing like so:


    Code:
    double a = CountUp / (double)(CountUp + CountDown);
    Plot0.Set(a);
    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks as always, Jesse, for the solution with a great explanation.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by yertle, Today, 08:38 AM
      6 responses
      25 views
      0 likes
      Last Post ryjoga
      by ryjoga
       
      Started by algospoke, Yesterday, 06:40 PM
      2 responses
      24 views
      0 likes
      Last Post algospoke  
      Started by ghoul, Today, 06:02 PM
      3 responses
      16 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      46 views
      0 likes
      Last Post jeronymite  
      Started by Barry Milan, Yesterday, 10:35 PM
      7 responses
      23 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Working...
      X