Support Board
Date/Time: Wed, 27 Nov 2024 22:45:35 +0000
[Programming Help] - Plots into the forward space disappear when new bar starts
View Count: 240
[2023-06-22 17:03:59] |
WarEagle - Posts: 73 |
I have several custom indicators that plot into the future or forward space of the chart. Since these calculations are complex but only need to be made once, I run this code only on the first bar for efficiency. The problem I have is that when a new bar starts, the forward part of the plot disappears. If I recalculate the chart manually the forward plot reappears until the next new bar starts when it disappears again. It is like anything in the forward array is deleted with a new bar. This is not a big deal on daily charts but it becomes a pain on intraday charts that update frequently. I am assuming the issue is related to the code only calculating on the first bar but I can't figure out what I need to do to fix it. I tried running the calculations for just the future portion on the current bar and it solves the problem of the future plot disappearing but this causes the calculation to occur every tick and it is really slowing things down. I tried checking GetBarHasClosedStatus() of the current bar to avoid calculations when it has not closed but once the bar closes it moves to the next index number so the code never runs. Or maybe it runs but the new bar instantly deletes the future plot again. Is there some property I have overlooked or a way around this problem? Thank you |
[2023-06-22 17:18:27] |
User431178 - Posts: 544 |
As you've found, extended array elements are cleared when new bars are added. Instead of using GetBarHasClosedStatus(), try uisng a persistent int variable to store the last index processed. This way you can perform the calculation once, on the new bar when it is added. int& lastProcessed = sc.GetPersistentInt(0); for (int i = sc.UpdateStartIndex; i < sc.ArraySize; ++i) { /// some code /// if (i > lastProcessed) { lastProcessed = i; // some code to update the extended array elements } /// some other code /// } Date Time Of Last Edit: 2023-06-22 17:18:37
|
[2023-06-22 19:24:50] |
WarEagle - Posts: 73 |
Ok thank you! After getting your suggestion to work I played around with it further and found I could simply change the bar I did the calculations on from bar #1 to the most recent non-updating bar and it plots everything without the disappearing part. It does add some extra computation but no different than manually recalculating each new bar. I appreciate the help! |
[2023-06-23 09:40:01] |
Sierra_Chart Engineering - Posts: 17198 |
Looks like you have found the answer here.
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, use 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: