Login Page - Create Account

Support Board


Date/Time: Sat, 20 Apr 2024 03:57:10 +0000



Custom Study - performing code once per bar

View Count: 2350

[2013-04-29 19:20:41]
joshtrader - Posts: 439
I am using some code to draw a horizontal line near the last bar on the chart. I would like to update the line only once per new bar, not every tick, for efficiency reasons.

But, if I surround the code inside a check for sc.GetBarHasClosedStatus(), what happens is that if I switch time frames or settings and the chart reloads, the code waits until the bar has closed to draw the line. After that, it updates on each new bar and it is fine. But if I switch time frames, I have no line until the bar closes. So I would like the line to draw immediately, and only then switch to updating every bar. I can't think of a way to do this--do you have a suggestion?

As a second question, if I want to hide the drawings in the study I will have to know whether the current study is visible and hide them manually (I would guess so anyway), and I suppose the GetStudyVisibilityState() function you are adding will make this possible; however, how do I know internally the ID of my own study?
Date Time Of Last Edit: 2013-04-29 19:59:35
[2013-04-29 22:36:31]
ejtrader - Posts: 688
Josh - Do you want the line to be drawn at the Open Tick of the bar? if so - I typically use the current logic:



int& lastIndex=sc.PersistVars->i1;

if ( lastIndex == 0 )
{
lastIndex=-1;

// Any other One-Time Initiation Commands
}

int i=sc.Index;

if (i == lastIndex) return; // Everything gets processed on very first tick of the bar ONLY and then the control would return back

lastIndex = i;

// Draw Line logic;




Date Time Of Last Edit: 2013-04-29 22:50:27
[2013-04-30 05:33:34]
joshtrader - Posts: 439
ejtrader, this is perfect, thank you!
[2013-04-30 06:39:58]
Sierra Chart Engineering - Posts: 104368
To get the integer identifier of the study instance that the code is running within, use sc.StudyGraphInstanceID
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing

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

Login

Login Page - Create Account