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 Hwop38, 05-04-2026, 07:02 PM
      0 responses
      154 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      307 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      244 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      345 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      176 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Working...
      X