Support Board
Date/Time: Wed, 27 Nov 2024 19:50:01 +0000
[Programming Help] - Displaying the first time ONLY when a condition is met - ASCIL
View Count: 373
[2023-06-26 22:02:31] |
User907609 - Posts: 16 |
I'm using the "color bar based on above/below study" to display the green dots above the high of the bar to show this example. I want the green dot ONLY on the first bar (shown with gold arrows) that goes past 1.50 in this example, all the other green dots on the bars afterward I do not want to see, even knowing the condition is true Is anyone able to help me or point me in the right direction? |
Example.png / V - Attached On 2023-06-26 21:56:03 UTC - Size: 38.09 KB - 93 views Desired Outcome.png / V - Attached On 2023-06-26 22:01:40 UTC - Size: 41.87 KB - 87 views |
[2023-06-27 16:35:23] |
JohnR - User831573 - Posts: 306 |
i would use 2 persistent variables. One that is set when the alert fires the first time on the bar. A second one that keeps the bar/index # of the prior tick bar index. If the bar index changes, reset the alert / persistent variable & update the bar # persistent variable. This partial logic should work, John |
[2023-06-27 16:42:01] |
User907609 - Posts: 16 |
How would this look in code? If you do not mind of course. Thanks. |
[2023-06-27 17:17:53] |
User719512 - Posts: 265 |
If you only want a signal the first time the condition is met and never again, then use a persistent variable initialized to -1 during sc.IsFullRecalculation. Then for the SG you are using for your green dot on set it to 1 or the high of the bar that meets the condition only if the persistent is -1, and then set that persistent variable to the index of the bar that first gets above your price level, so future calculations will not fire since it is no longer -1. This would be for on bar close only, otherwise, you need to clarify the behavior you want intra-bar during live updates if you want the dot to follow the high till that bar closes. In which case you would check if the persistent is equal to current bar index, and set/reset the high on the SG. |
[2023-07-06 16:49:13] |
User907609 - Posts: 16 |
Are you able to show a coded example of this? I'm still fairly new to the coding world lol.
|
To post a message in this thread, you need to log in with your Sierra Chart account: