Login Page - Create Account

Support Board


Date/Time: Mon, 21 Apr 2025 16:13:06 +0000



Stop custom study from updating over and over?

View Count: 142

[2025-02-24 20:38:26]
gammamale - Posts: 4
I have a custom study and I read this documentation for When a Study Function is Called ( Working with ACSIL Arrays and Understanding Looping: When the Study Function is Called ). It seems my study (or any studies) function will be called whenever the chart updates intraday if I have live market data going. Is this correct? I noticed this because I was using sc.AddMessageToLog() for debugging and it was spamming the log.

But in the case of my study it doesn't really need to be called over and over. It is drawing some shapes on the intraday chart based on data from previous days that isn't affected by new market data. Is it Sierra Chart practice to just let the study update anyway? I am fine either way but I just want to be following the right practice.

Thank you
[2025-02-25 02:40:05]
cmet - Posts: 690
No idea what your study looks like but essentially, the default is every tick.

You can control that though. Oversimplified example:

if (sc.GetPersistentInt(0) == 1)
return;

if (!sc.IsFullRecalculation)
return;

sc.SetPersistentInt(0, 1);

if (sc.LastCallToFunction)
sc.SetPersistentInt(0, 0);

Date Time Of Last Edit: 2025-02-25 02:40:22
[2025-02-25 06:46:24]
seandunaway - Posts: 348
a snippet showing concepts like running code only on initialization or removing the study or at timed intervals

#include <sierrachart.h>

#define timer_interval_ms 5000

void OnInit (SCStudyGraphRef sc)
{
  sc.AddMessageToLog("OnInit", 1);
}

void OnDeinit (SCStudyInterfaceRef sc)
{
  sc.AddMessageToLog("OnDeinit", 1);
}

void OnTimer (SCStudyInterfaceRef sc)
{
  sc.AddMessageToLog("OnTimer", 1);
}

void OnTick (SCStudyInterfaceRef sc)
{
  sc.AddMessageToLog("OnTick", 1);
}

SCDLLName("concepts")
SCSFExport scsf_concepts (SCStudyInterfaceRef sc)
{
  if (sc.SetDefaults)
  {
    sc.GraphName = "concepts";
    sc.GraphRegion = 0;
    sc.UpdateAlways = 1;
    return;
  }

  // OnInit
  int& initialized = sc.GetPersistentIntFast(0);
  if (!initialized)
  {
    OnInit(sc);
    initialized = 1;
  }

  // OnDeinit
  if (sc.LastCallToFunction)
    return OnDeinit(sc);

  // OnTimer
  SCDateTimeMS& last_datetime = sc.GetPersistentSCDateTimeFast(0);
  SCDateTimeMS now = sc.CurrentSystemDateTimeMS;
  if (now >= last_datetime + SCDateTime::MILLISECONDS(timer_interval_ms))
  {
    OnTimer(sc);
    last_datetime = now;
  }

  // OnTick
  OnTick(sc);
}

Date Time Of Last Edit: 2025-02-25 06:48:18

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

Login

Login Page - Create Account