Announcement

Collapse
No announcement yet.

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.

    Comment


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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      577 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      334 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      553 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      551 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X