Login Page - Create Account

Support Board


Date/Time: Tue, 22 Apr 2025 02:36:33 +0000



[Programming Help] - Custom ASCII Study is interfering with other studies

View Count: 202

[2025-02-10 22:18:52]
Luchs - Posts: 23
Unfortunately, I am not a programmer. But with some SC experience and a big help from AI, I created this very useful study to help me track the market movement.

Anyway: there must be a serious, fundamental flaw in all the studies I've done so far: They interfere with the next study that immediately follows in the list. Whatever I do, the next study is taken over by my own study and displays the values of my study.

I have solved the problem by putting my study at the end of the list so that there is no other study that interferes with it. But this is just a cheat.

Does anyone know what the problem is?




#include "sierrachart.h"

SCDLLName("HighTrackerLine")

SCSFExport scsf_DynamicHighLine(SCStudyInterfaceRef sc)
{
if (sc.SetDefaults)
{
sc.GraphName = "Dynamic High Line";
sc.StudyDescription = "Stores the highest high from the start of live data or replay and visualizes it as a horizontal line in the subgraph.";
sc.AutoLoop = 0; // Manual looping for full control

// Subgraph for the line
sc.Subgraph[0].Name = "High Line";
sc.Subgraph[0].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[0].PrimaryColor = RGB(255, 0, 0);
sc.Subgraph[0].LineWidth = 2;
sc.Subgraph[0].DrawZeros = false;

return;
}

static float HighestHigh = -FLT_MAX;
static int StartIndex = -1;
bool DataActive = (sc.ReplayStatus == REPLAY_RUNNING || sc.ServerConnectionState == SCS_CONNECTED);

// If no live data is received or replay is stopped, do not display the line
if (!DataActive)
{
for (int i = 0; i < sc.ArraySize; i++)
{
sc.Subgraph[0][i] = 0;
}
StartIndex = -1;
HighestHigh = -FLT_MAX;
return;
}

// Set the high based on the first new bar after live data or replay starts
if (StartIndex == -1 && sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED)
{
StartIndex = sc.Index;
HighestHigh = sc.High[sc.Index];
}

// Update the highest high only if a new higher high occurs
if (sc.Index >= StartIndex && sc.High[sc.Index] > HighestHigh)
{
HighestHigh = sc.High[sc.Index];
}

// Store the highest value and visualize it as a horizontal line in the subgraph
for (int i = 0; i < sc.ArraySize; i++)
{
sc.Subgraph[0][i] = HighestHigh;
}
}


Date Time Of Last Edit: 2025-02-10 22:28:06
[2025-02-11 00:04:21]
Sierra_Chart Engineering - Posts: 19290
This study is not well structured and it is very inefficient. It does a full calculation of the array every call. Before the for loop the code is not using the proper variable for the current index and it does not really seem to makes sense that it would be always relying on the sc.UpdateStartIndex for the code before the for loop ( which you are using by using sc.Index).
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2025-02-19 07:51:12
[2025-02-16 18:53:28]
ForgivingComputers.com - Posts: 1042
Unfortunately, I am not a programmer.

The feedback given in message #2 is probably not what you expected. There is a lot of stuff going on in the code that you don't understand. Not that AI won't improve over time, but you are getting questionable results (aka "hallucinations").

One of the drawbacks of using AI to generate code is that it regurgitates what it thinks will work, with no way of testing the results. When it does strange things, you are left scratching your head.

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

Login

Login Page - Create Account