Login Page - Create Account

Support Board


Date/Time: Wed, 08 May 2024 22:12:31 +0000



[Programming Help] - Recalculate on Bar Close. Any options?

View Count: 3059

[2018-03-01 21:54:49]
Mooshu22 - Posts: 25
I'm using the study: Spreadsheet System for Trading and have three different timed charts in the chartbook. I have a study from a 60M chart overlayed on a smaller time frame chart, 5M. I then have a moving average study in the 5M chart using the "Input Data" field to average the 60M data so the lines are smoothed. One of the challenges of I'm experiencing is as the 60M candle progresses the data becomes more accurate. I am wondering if there is a way to trigger a recalculate of the 5M chart each time a 5M candle closes? Or is this idea just a dead end? I can manually press CTRL-INSERT to recalculate and I get what I need, but would like the computer to do it when away. Thank you-
[2018-03-02 09:29:33]
User35525 - Posts: 180
Hi Mooshu22,

I'm not an ACSIL expert, but this code snippet has worked for me in the past:


SCSFExport scsf_study_name(SCStudyGraphRef sc) // scsf_Name can be anything
{
if(sc.GetBarHasClosedStatus()==BHCS_BAR_HAS_NOT_CLOSED)
return;//do not do any processing if the bar at our current index has not closed
if (sc.SetDefaults != 1 && sc.IsFullRecalculation != 1) {
sc.FlagToReloadChartData= 1;
}
else {
sc.FlagToReloadChartData= 0;
}

...


So just create an ACSIL study that has the above, add it to your chart and set it to run on bar close only, and you should be good. Maybe SC can provide an official study called Recalculate all studies on bar close.
Date Time Of Last Edit: 2018-03-02 10:48:05
[2018-03-02 13:26:14]
Mooshu22 - Posts: 25
Thank you User35525 this code looks to be what I need for a temporary fix. I was able to create a custom study DLL and apply the custom study to the chart. I am a bit confused of where to set it to run, or is it doing what it needs by default? Otherwise in the Settings and Input page of the study there are no options or inputs to change.

add it to your chart and set it to run on bar close only

[2018-03-02 13:54:04]
Mooshu22 - Posts: 25
@User35525. After observing the chart close bars I can clearly see that this is working and the chart is reloading on bar close! Well done. Thank you once again. I was wondering what difference there is between reloading vs. recalculating; Does the chart experience different functionality when using recalculating vs. reloading?
[2018-03-02 15:41:05]
User35525 - Posts: 180
Glad to help, @Mooshu22! This study reloads the chart similarly to pressing CTRL-INSERT; as such, it should be located to the top of the study list, so it runs before any spreadsheet studies. For recalculate vs reload, all the studies get recalculated when the chart is reloaded.

This study is kind of a kludge and shouldn't be needed if everything is working correctly, but I have a similar problem with overlays and tried this fix (but from a slower, reversal chart into a faster, range chart); I'm still banging my head on that and one day will ping the SC engineers for help. Perhaps putting my ACSIL study on the higher-timeframe chart will work, as it will tag the lower-timeframe/destination chart to recalculate:
Study/Price Overlay Study: Study/Price Overlay Study Updating and Timing of Calculations Between Source and Destination Charts
Chart Studies: References to Other Charts and Tagging

SC engineers might have a better fix for this spreadsheet issue. I'm not sure why it's so difficult to overlay a study from a slower chart onto a faster chart; I'm sure they'd point you to this page:
Study/Price Overlay Study: Inconsistent Dependent Results Between Full Calculation and Real-Time Updating

Maybe Strict Signal Only On Bar Close Evaluation can do what you want (not sure since I'm not yet using spreadsheet studies), which would be better than forcing a full chart reload and recalculate on every bar:
Spreadsheet Systems, Alerts and Automated Trading: Strict Signal Only On Bar Close Evaluation
Date Time Of Last Edit: 2018-03-02 16:08:46
[2018-03-02 16:45:03]
Mooshu22 - Posts: 25
@User35525, Thank you once again! Your help is most appreciated. Thank you especially for the tip to put at the top of the study list. I didn't have it this way. I did a little bit more reading and found a variable on this page that flags a recalculation instead of reload:

ACSIL Interface Members - Variables and Arrays

With this I just swapped out the then and else conditions to sc.FlagFullRecalculate. Thank you thank you!


SCSFExport scsf_RecalculateOnBarClose(SCStudyGraphRef sc) // scsf_Name can be anything

{

if(sc.GetBarHasClosedStatus()==BHCS_BAR_HAS_NOT_CLOSED)

return;//do not do any processing if the bar at our current index has not closed

if (sc.SetDefaults != 1 && sc.IsFullRecalculation != 1) {

sc.FlagFullRecalculate= 1;

}

else {

sc.FlagFullRecalculate= 0;

}
}

[2018-03-02 17:17:27]
User35525 - Posts: 180
@Mooshu22, glad to help if I can!

Thanks for your update also, which makes the process more efficient! My understanding is there are at least two different threads in SC (one for data loading, one for calculating studies), and your code is better if there are many bars.

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

Login

Login Page - Create Account