Login Page - Create Account

Support Board


Date/Time: Tue, 22 Apr 2025 03:00:46 +0000



Post From: Converting From MetaTrader EA (Init, DeInit, OnTick) to Sierra Chart study?

[2025-02-17 21:55:35]
cmet - Posts: 690
If using milliseconds, you want to use SCDateTimeMS. Also, change Seconds to Milliseconds throughout. (IntervalMilliseconds, GetTimeInMilliseconds)

ExecuteTimedFunction is just a placeholder for your function/logic. You would replace that with whatever you needed to call.

Is the study itself called on a regular interval?

Could you explain what you mean there?

From above with a few more notes:

SCSFExport scsf_ModifiableTimer(SCStudyInterfaceRef sc)
{
//modifiable interval (milliseconds)
SCInputRef IntervalMilliseconds = sc.Input[0];

if (sc.SetDefaults)
{
sc.GraphName = "Modifiable Timer Function";
sc.AutoLoop = 0;
sc.UpdateAlways = 1;

IntervalMilliseconds.Name = "Interval Milliseconds";
IntervalMilliseconds.SetInt(250); // interval 250ms
IntervalMilliseconds.SetIntLimits(1, 60000); // max ms

return;
}

// store last execution time
static SCDateTimeMS LastExecutionTime;
SCDateTimeMS CurrentTime = sc.CurrentSystemDateTimeMS;
int Interval = IntervalMilliseconds.GetInt(); // get interval in ms

// execute on specified interval
if ((CurrentTime - LastExecutionTime).GetMilliSeconds() >= Interval)
{
ExecuteTimedFunction(); // replace with your actual function
LastExecutionTime = CurrentTime; // reset
}
}

Date Time Of Last Edit: 2025-02-17 22:01:59