Login Page - Create Account

Support Board


Date/Time: Mon, 21 Apr 2025 16:56:49 +0000



Post From: ACSIL sc.GetOrderFillArraySize() returning transient 0 after chart relo

[2025-04-18 10:21:31]
TedMar - Posts: 191
My Workaround for transient “0” from sc.GetOrderFillArraySize() after chart reload

I’ve updated the debug study to reliably skip the transient “0” value that appears immediately after a chart reload or timeframe change. Since fills never actually disappear, the workaround simply ignores any drop to zero when the previous count was greater than zero.

Workaround summary:

Initialize PreviousFillCount on the very first run.

On every call, read CurrentFillCount = sc.GetOrderFillArraySize().

If CurrentFillCount == 0 and PreviousFillCount > 0, skip that cycle (treat as transient).

Otherwise, log any real change (CurrentFillCount != PreviousFillCount) and update the stored count.

This approach is much simpler than trying to detect every reload scenario, and it handles both manual Reload & Recalculate and timeframe switches.



#include "sierrachart.h"

// Debug study: skip transient zero and only log real fill-count changes
SCSFExport scsf_DebugFillCountChange_Simple(SCStudyInterfaceRef sc)
{
if (sc.SetDefaults)
{
sc.GraphName = "Debug Fill Count + Simple Skip";
sc.StudyDescription = "Logs fill-count changes, skips any transient 0.";
sc.AutoLoop = 0; // No auto-loop over bars
sc.UpdateAlways = 1; // Always call, even without new ticks
sc.GraphRegion = 0; // Draw in the main chart region
sc.HideStudy = 1; // Keep this study hidden
sc.MaintainTradeStatisticsAndTradesData = 1; // Required for fill data

// --- Persistent variables ---
sc.SetPersistentInt(0, 0); // IsInitialized flag
sc.SetPersistentInt(1, -1); // PreviousFillCount
return;
}

// Do not run during a full recalculation or while downloading historical data
if (sc.IsFullRecalculation || sc.DownloadingHistoricalData)
return;

// Retrieve persistent variables
int& IsInitialized = sc.GetPersistentInt(0);
int& PreviousFillCount = sc.GetPersistentInt(1);
int CurrentFillCount = sc.GetOrderFillArraySize();

// First-time initialization
if (IsInitialized == 0)
{
if (CurrentFillCount == 0)
return; // still loading, skip until the real count arrives, is required if you want to duplicate chart with the study

PreviousFillCount = CurrentFillCount;
IsInitialized = 1;
SCString initMsg;
initMsg.Format("Init: PrevFillCount=%d", PreviousFillCount);
sc.AddMessageToLog(initMsg, 0);
return;
}

// Skip any transient drop to zero immediately after reload
if (CurrentFillCount == 0 && PreviousFillCount > 0)
{
sc.AddMessageToLog("Skipping transient zero after reload", 0);
PreviousFillCount = 0; // Sync up so next real change is detected
return;
}

// Log any real change in fill count
if (CurrentFillCount != PreviousFillCount)
{
SCString logMsg;
logMsg.Format(">>> Fill count changed: Prev=%d, Curr=%d",
PreviousFillCount, CurrentFillCount);
sc.AddMessageToLog(logMsg, 1);
PreviousFillCount = CurrentFillCount;
}
}



With this version, every time the chart reloads you’ll see exactly one “Skipping transient zero after reload” entry, followed by a single correct fill-count change. Let me know if this solves the issue in all your reload scenarios!

— Ted
Date Time Of Last Edit: 2025-04-18 11:01:15