Login Page - Create Account

Support Board


Date/Time: Wed, 15 Jan 2025 16:01:20 +0000



Post From: sc.GetBarHasClosedStatus Doesn't Calculate When Bars Are Flat

[2017-07-26 20:28:33]
CustomIndicators - Posts: 126
My study finds pivot points, and draws a dot on them. This is one a single line oscillator.

When I just search for pivot points using this code, the studies take over an hour to load:


if (sc.GetPersistentInt(VALLEY_ACTIVATOR) == NOT_ACTIVE && sc.Subgraph[OSCILLATOR][sc.Index - 3] <= sc.Subgraph[OSCILLATOR][sc.Index - 2] && sc.Subgraph[OSCILLATOR][sc.Index - 2] > sc.Subgraph[OSCILLATOR][sc.Index - 1])
  {
    DrawDots(sc); // Draws a dot at sc.Index - 2 on oscillator to mark pivot point.
    sc.SetPersistentInt(PEAK_ACTIVATOR, NOT_ACTIVE);
    sc.SetPersistentInt(VALLEY_ACTIVATOR, ACTIVE);
  }


If I place it in this if statement, it also takes over an hour to load:


if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED)
{
  if (sc.GetPersistentInt(VALLEY_ACTIVATOR) == NOT_ACTIVE && sc.Subgraph[OSCILLATOR][sc.Index - 3] <= sc.Subgraph[OSCILLATOR][sc.Index - 2] && sc.Subgraph[OSCILLATOR][sc.Index - 2] > sc.Subgraph[OSCILLATOR][sc.Index - 1])
    {
      DrawDots(sc); // Draws a dot at sc.Index - 2 on oscillator to mark pivot point.
      sc.SetPersistentInt(PEAK_ACTIVATOR, NOT_ACTIVE);
      sc.SetPersistentInt(VALLEY_ACTIVATOR, ACTIVE);
    }
}


If I change BHCS_BAR_HAS_CLOSED to BHCS_BAR_HAS_NOT_CLOSED, they load in under 2 seconds. A serious performance boost. Seems backwards, right? But it works much better.


if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_NOT_CLOSED)
{
  if (sc.GetPersistentInt(VALLEY_ACTIVATOR) == NOT_ACTIVE && sc.Subgraph[OSCILLATOR][sc.Index - 3] <= sc.Subgraph[OSCILLATOR][sc.Index - 2] && sc.Subgraph[OSCILLATOR][sc.Index - 2] > sc.Subgraph[OSCILLATOR][sc.Index - 1])
    {
      DrawDots(sc); // Draws a dot at sc.Index - 2 on oscillator to mark pivot point.
      sc.SetPersistentInt(PEAK_ACTIVATOR, NOT_ACTIVE);
      sc.SetPersistentInt(VALLEY_ACTIVATOR, ACTIVE);
    }
}

Only problem is, when using if sc.GetBarHasClosedStatus() to increase performance, it doesn't become true on candles that open, don't move, and then close. It will only calculate on candles that move. This becomes a problem on my 32 tick (Number of trades per bar) chart.

Is there a way I can have sc.GetBarHasClosedStatus() return BHCS_BAR_HAS_NOT_CLOSED when a bar hasn't moved, yet closed? I was hoping that it would actually return on every candle, but it only does so on candles that opened, moved (even back to the open price), and then closed.