Login Page - Create Account

Support Board


Date/Time: Sat, 15 Mar 2025 16:15:02 +0000



[Programming Help] - Update previous drawing in study when doing AutoLooping

View Count: 946

[2022-07-10 22:08:39]
Thang N - Posts: 11
Hi,

I'm working on a study to automate drawing some support / resistance zone base on certain criteria. My zone are drawn by using DRAWING_RECTANGLE_EXT_HIGHLIGHT. I have AutoLooping = 1 and it runs fine when the chart is not updating live.

The problem I run into is I don't know how to access / modify previous drawn zone once the chart is updating live. As far as I understand, AutoLooping would run the study on all the bars from index 0 to ArraySize-1, so say if there are 100 bars, then we run the study from bar 0 to bar 99. Then when the new bar is added when we running live, the study is run for the bar 100 and keep going forth, not re-run from bar 0 to 99, right?

Please let me know how I can access previous drawings of bar 0 to 99 when we're updating live. Thank you.
[2022-07-11 16:43:23]
John - SC Support - Posts: 38678
You have your information correct in terms of how the calculations are performed.

But, this does not prevent you from updating previous information. If you are at BarIndex = 1000 and you need to change something back at BarIndex = 500, then you can just go ahead and change it. So if you need to modify a drawing then you can just update it.

But, if you really need to have a full recalculation, then refer to the following variable:
ACSIL Interface Members - Variables and Arrays: sc.FlagFullRecalculate
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2022-07-11 21:29:14]
Thang N - Posts: 11
Thanks John.

So for iterating over all the bars, even in live update, I should do a loop starting with index 0 and end with CurrentIndex, since CurrentIndex will continue to be the latest bar on the chart, both at the initial function call and live update?
[2022-07-11 21:45:35]
John - SC Support - Posts: 38678
Yes, you can do that, but if it is something you are doing all the time, then you would not want to use the Auto-Looping, since you are taking care of the looping yourself.

But, if it is just an occasional thing where you need to update something in the past based on a current event, then you can continue with the Auto-Loop and then loop through all the bars as necessary.
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2022-07-11 22:38:25]
Thang N - Posts: 11
I do want to run it for every new bar added, since I have to update the zones to see if the new bar has entered the zone (I change the zone color / remove the zone if the new bar intersect / trade past the zone).

In that case, what would be the right way to go about it? Manual looping?
[2022-07-12 13:42:12]
JohnR - User831573 - Posts: 320
As with most things programming, there is more than one way to complete a task. My thought would be to continue to do auto looping. I would also set up an array of your rectangle objects values, start/end bar# & values and any other fields/properties you need to identify if it is extended. Then as you update each new tick, have a loop that goes through your array to see if any of your zones need to be updated.

Just a thought, hope it helps.
JohnR
[2022-07-12 16:42:15]
Thang N - Posts: 11
@JohnR: yes, that's what I'm doing, using sc.subgraph array to store the zone value, the line numbers, etc. Just a bit confused with how I should structure the flow so it would be right on both initial function calc and subsequent update, but your idea is great! Thank you.
[2022-07-12 18:58:02]
JohnR - User831573 - Posts: 320
FYI - I am not a great coder, like some here, but this is how I would approach your task.

JohnR

During real time vs historical updates, you would have to determine if you want to update your zones on each tick, or wait until (EOB) end of bar/ new bar first calc. If you are processing once per bar, then the following is one idea.

somewhere within your study definition

  int& lastIndex = sc.GetPersistentInt(1);

Then on first bar, set your var LastIndex

  if (sc.Index == 0)
  {
    lastIndex = -1;

then within the Data Processing (bar/tick update section)

  if (sc.Index != lastIndex) // this is true when there is a new bar
  {
    lastIndex = sc.Index;
    
Add your logic here to modify existing / create new zones
  }
[2022-07-12 21:34:32]
Thang N - Posts: 11
@JohnR:

That's a good suggestion, I'll try that out and report back. Thank you!
[2022-07-16 20:26:15]
Thang N - Posts: 11
So I got my code to work, however, when I try to import it as a Study Price overlay for another chart, it doesn't show up. Any clue on why?
[2022-07-17 15:56:00]
JohnR - User831573 - Posts: 320
My guess would be that your sup/res zones are drawings. Study Overlays show subgraphs. You may want to look into the area of sharing chart drawings.
Copying Chart Drawings from Other Charts Automatically

https://www.google.com/search?q=sierrachart+share+drawings&rlz=1C1MKDC_enUS774US774&oq=sierrachart+share+drawings&aqs=chrome..69i57j69i64.12331j0j7&sourceid=chrome&ie=UTF-8

Hope this helps,
JohnR

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

Login

Login Page - Create Account