Login Page - Create Account

Support Board


Date/Time: Wed, 12 Feb 2025 09:07:28 +0000



[Programming Help] - How to count bars after certain conditions met

View Count: 712

[2020-10-19 21:10:19]
Luigi - Posts: 18
I am a newbie in SC ACSIL programming, so forgive me if it is a trivial question.

What I try to achieve:
Count n number of bars after certain indicator changed value and change bar color of nth bar.

Problem:
My data processing logic works when chart is loaded first time, but when live or replaying the function called at each price updates and my counter is not counting bars anymore, but the updates on the last bar.

What would be the best way to solve this?

Code snipet which works when chart is loaded:

  int& upCounter = sc.GetPersistentInt(1);
  int& downCounter = sc.GetPersistentInt(2);
  
  if ((Subgraph_Avg[sc.Index] - Subgraph_Avg[sc.Index-1]) >= 0 )
  {
    Subgraph_TTF_Trend[sc.Index] = 1;
    upCounter = upCounter +1;
    downCounter=0;

  }
  else
  {
    Subgraph_TTF_Trend[sc.Index] = -1;
    downCounter = downCounter +1;
    upCounter=0;
  }

Date Time Of Last Edit: 2020-10-19 21:13:16
[2020-10-20 07:24:24]
User907968 - Posts: 826
You could incorporate this function (sc.GetBarHasClosedStatus()) into your code and only update the count when the bar is closed.
[2020-10-20 11:09:08]
Luigi - Posts: 18
It worked like a charm. Need to digest the documentation more....
Thanks!

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account