Login Page - Create Account

Support Board


Date/Time: Wed, 14 May 2025 09:48:31 +0000



[Programming Help] - counting colored bars

View Count: 1101

[2016-04-08 15:56:03]
User166870 - Posts: 13
Hello,

I'm using the "color bar based on alert condition" study.
Is it possible to count these colored bars over a fixed period and print
the result on screen ?

Thanks
Hannes
[2016-04-11 18:05:17]
User166870 - Posts: 13
Here is an image for better understanding :

http://www.sierrachart.com/image.php?Image=1460397663195.png
[2016-04-11 21:28:40]
Sawtooth - Posts: 4214
You can do it with the Spreadsheet Study study, and the Text Display for Study study.

If you give me the ID# of the color bar study, I'll post the formula.
[2016-04-12 11:32:44]
User166870 - Posts: 13
The ID# is 2.

Many thanks in advance !
[2016-04-12 14:16:59]
Sawtooth - Posts: 4214
Is the current day included in the 25 day lookback?
[2016-04-12 14:55:33]
User166870 - Posts: 13
No it isn't, I need the information before market open.

Thanks again
[2016-04-12 17:20:19]
Sawtooth - Posts: 4214
1) Add the Spreadsheet Study study
-Check 'Hide Study'
-Give it a name in the 'Spreadsheet Name' field
Use these formulas in these cells:
K1: (this is the number of lookback days)
25
K3: (this counts the days the spreadsheet sees)
=IF(A3>A4,K4+1,K4)
L3: (this counts the colored bars in the previous K1 days, not including the current day)
=IF(AND(ROW()>3,ID2.SG1@3,K3>$K$3-$K$1-1),L4+1,L4)
You can minimize the spreadsheet.

2) Add the Text Display for Study study
-Set the 'Value Format' to 1
-Set the 'Study And Subgraph To Display' to the spreadsheet study and L(SG2)
[2016-04-12 18:25:51]
User166870 - Posts: 13
It works, thank you.

But after closing & re-opening the chartbook the display study shows '25'

I need to reset the value in 'Study And Subgraph To Display' from L(SG2) to another value & back, few times.

I'm looking for another workaround (hope this is not a bug).

Thanks again
[2016-04-12 18:32:12]
Sawtooth - Posts: 4214
I noticed this also. The bars are still colored but the color bar study's output to the spreadsheet goes away.
I would consider this a bug.

After you open the chartbook, go to Chart >> Recalculate.
[2016-04-12 18:55:46]
User166870 - Posts: 13
Okay, I can live with that for now.
The Spreadsheet Study was new for me. I'll take a deeper look into these method.

Thank you very much for your assistence !
[2016-04-12 19:01:39]
Sawtooth - Posts: 4214
You could also add a Recalculate button on the Control Bar:
Global Settings >> Customize Control Bars

If you don't want to manually do a recalc every time you open or modify the chartbook, there is a study Kiwi programed that recalculates every n seconds, called Recalc.

Put the attached in your Sierra \Data folder, go to Analysis >> Studies >> Add Custom Study >> Kiwi's Stuff 2015 >> Recalc
Set the 'Seconds between recalcs' to 1
Date Time Of Last Edit: 2016-04-12 19:03:41
attachmentkiwi15.dll - Attached On 2016-04-12 18:45:54 UTC - Size: 142.5 KB - 587 views
[2016-04-12 19:14:03]
User166870 - Posts: 13
Very nice, it works perfectly !
[2016-04-12 19:42:47]
Sawtooth - Posts: 4214
Another solution would be to use the spreadsheet to color the bars, instead of the Color bar study.

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

Login

Login Page - Create Account