Support Board
Date/Time: Wed, 15 Jan 2025 16:14:11 +0000
sc.GetBarHasClosedStatus Doesn't Calculate When Bars Are Flat
View Count: 1471
[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. |
[2017-07-26 21:07:38] |
ejtrader - Posts: 688 |
You can try this: This works Once per bar & only when the bar is closed. Psuedo Code: if (sc.Index < sc.ArraySize - 1) { // Calculations here.... } Date Time Of Last Edit: 2017-07-26 21:08:43
|
[2017-07-26 21:45:10] |
CustomIndicators - Posts: 126 |
Thank you, ejtrader, that solution worked wonderfully!
|
To post a message in this thread, you need to log in with your Sierra Chart account: