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 TradeForge, 04-19-2024, 02:09 AM
      2 responses
      28 views
      0 likes
      Last Post TradeForge  
      Started by aprilfool, 12-03-2022, 03:01 PM
      3 responses
      327 views
      0 likes
      Last Post NinjaTrader_Adrian  
      Started by giulyko00, Today, 12:03 PM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by f.saeidi, Today, 12:14 PM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by AnnBarnes, Today, 12:17 PM
      1 response
      2 views
      0 likes
      Last Post NinjaTrader_Zachary  
      Working...
      X