Login Page - Create Account

Support Board


Date/Time: Mon, 21 Apr 2025 16:27:10 +0000



Post From: Stop custom study from updating over and over?

[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