Login Page - Create Account

Support Board


Date/Time: Mon, 25 Nov 2024 14:47:19 +0000



App is slow to respond after installing this study

View Count: 202

[2024-02-23 15:56:37]
User856926 - Posts: 9
I created a study that draws an X and a line and have reduced my interval to 1 day but there is a delay in my app response to right clicks. It's not overly complex and I wondered if you could take a look at it below

#include "sierrachart.h"
SCDLLName("powa - 15min arrow")

/*
to create a custom study in sierra chart to draw an arrow on a 15min chart when the last candle is green
and the next candle is red but closes within the body of the green candle

in sierra chart to draw an arrow on a 15min chart when the last candle is red
and the next candle is green but closes within the body of the red candle
*/


SCSFExport scsf_HighlightCandlesBelowEMA(SCStudyInterfaceRef sc)
{
SCSubgraphRef EMA = sc.Subgraph[0];
SCInputRef Length = sc.Input[0];

if (sc.SetDefaults)
{
sc.GraphName = "Candles Below 8-EMA";
sc.StudyDescription = "Highlights candles below the 8-period EMA";
sc.GraphRegion = 0;
sc.AutoLoop = 1;

EMA.Name = "EMA";
EMA.DrawStyle = DRAWSTYLE_LINE;
EMA.PrimaryColor = RGB(0, 255, 0);

Length.Name = "Length";
Length.SetInt(8);
Length.SetIntLimits(1, MAX_STUDY_LENGTH);

return;
}

// Calculate the EMA
sc.ExponentialMovAvg(sc.Close, EMA, Length.GetInt());

// Check if the close price of the current candle is below the EMA
if (sc.Close[sc.Index] < EMA[sc.Index])
{
// This is where you would add your logic to highlight the candle.
// For example, changing the candle color, adding a marker, etc.
// This script only logs a message for simplicity.
// SCString logMessage;
// logMessage.Format("Candle below 8-EMA at index: %d", sc.Index);
// sc.AddMessageToLog(logMessage, 0);
sc.Subgraph[0].DataColor[sc.Index] = RGB(255, 255, 255);

}
// Calculate the 8-period EMA
// sc.ExponentialMovAvg(sc.Close, sc.Subgraph[0], 8);
for (int Index = sc.UpdateStartIndex; Index < sc.ArraySize - 1; ++Index) // Ensure there's a next candle to compare
{
bool isLastCandleGreen = sc.Close[Index - 1] > sc.Open[Index - 1];
bool isCurrentCandleRed = sc.Close[Index] < sc.Open[Index];
bool closesWithinLastCandle = sc.Close[Index] > sc.Open[Index - 1] && sc.Close[Index] < sc.Close[Index - 1];
bool isUnderEMA = sc.Close[Index] < sc.Subgraph[0][Index];

if (isLastCandleGreen && isCurrentCandleRed && closesWithinLastCandle && isUnderEMA)
{
s_UseTool tool;
tool.Clear();
tool.ChartNumber = sc.ChartNumber;
tool.DrawingType = DRAWING_MARKER;
tool.MarkerType = MARKER_X;
tool.LineWidth = 5;
tool.MarkerSize = 4;
tool.BeginIndex = Index; // Current candle index
tool.BeginValue = sc.High[Index] + sc.TickSize * 10; // Adjust position above the high
tool.Color = RGB(255, 255, 255); // White
tool.AddMethod = UTAM_ADD_ALWAYS;

sc.UseTool(tool);

// Additional code to draw a horizontal line 1 tick below the lowest price of the candle
s_UseTool lineTool;
lineTool.Clear();
lineTool.ChartNumber = sc.ChartNumber;
lineTool.DrawingType = DRAWING_LINE;
lineTool.BeginIndex = Index;
lineTool.EndIndex = Index + 10;
lineTool.BeginValue = sc.Low[Index] - sc.TickSize; // 1 tick below the low of the candle
lineTool.EndValue = lineTool.BeginValue;
lineTool.Color = RGB(255, 255, 255); // White
lineTool.LineWidth = 1; // Adjust line width as needed
lineTool.AddMethod = UTAM_ADD_ONLY_IF_NEW;

sc.UseTool(lineTool);
}
bool isLastCandleRed = sc.Close[Index - 1] < sc.Open[Index - 1];
bool isCurrentCandleGreen = sc.Close[Index] > sc.Open[Index];
closesWithinLastCandle = sc.Close[Index] > sc.Open[Index - 1] && sc.Close[Index] > sc.Close[Index - 1];
bool isOverEMA = sc.Close[Index] > sc.Subgraph[0][Index];

if (isLastCandleRed && isCurrentCandleGreen && isOverEMA && closesWithinLastCandle)
{
s_UseTool tool;
tool.Clear();
tool.ChartNumber = sc.ChartNumber;
tool.DrawingType = DRAWING_MARKER;
tool.MarkerType = MARKER_X;
tool.LineWidth = 5;
tool.MarkerSize = 4;
tool.BeginIndex = Index; // Current candle index
tool.BeginValue = sc.Low[Index] + sc.TickSize * 1; // Adjust position above the high
tool.Color = RGB(0, 0, 255); // Blue
tool.AddMethod = UTAM_ADD_ALWAYS;

sc.UseTool(tool);

// Additional code to draw a horizontal line 1 tick below the lowest price of the candle
s_UseTool lineTool;
lineTool.Clear();
lineTool.ChartNumber = sc.ChartNumber;
lineTool.DrawingType = DRAWING_LINE;
lineTool.BeginIndex = Index;
lineTool.EndIndex = Index + 10;
lineTool.BeginValue = sc.High[Index] - sc.TickSize; // 1 tick below the low of the candle
lineTool.EndValue = lineTool.BeginValue;
lineTool.Color = RGB(0, 0, 255); // White
lineTool.LineWidth = 1; // Adjust line width as needed
lineTool.AddMethod = UTAM_ADD_ONLY_IF_NEW;

sc.UseTool(lineTool);
}
}


}
[2024-02-23 22:00:47]
User856926 - Posts: 9
So I followed some suggestions per Help topic30 High CPU Usage | Inactive User Interface | Poor Performance | Long Time to Load Chart Data | Charts Reloading Often
however, now my chart doesn't even finish loading even though the study looks like it completed. It's like it's stuck endlessly with the circular wait icon spinning. I have plenty of memory 64GB and an i9 processor so I it's not an IO issue. The charts will come up normally if I remove the study but I'm wondering why it hangs after it loads. It seems that there might be a parameter that I changed that is creating this behavior.

I tried:
Intraday Data Storage Time Unit: 1 Second -> 2 Second
Maximum Historical Intraday Days to Download -> 10
Maximum Historical Days to Download For Daily Data -> 10
Chart >> Chart Settings >> Data Limiting -> 10 days

I think there is a problem with the 2nd block of code however that is used to paint the blue X's. When I comment it out, the study shows up fine. The blue x's is just the reverse of the white's x's so I'm at a loss as to why the addition of this code causes a performance issue. It seems that 2nd block of code which is the same as the first block of code but for the price movement up is triggering some background event endlessly. I thought it might be the .AddMethod and tried different options instead of UTAM_ADD_ALWAYS but to no prevail.
image2024-02-23_13-43-53.png / V - Attached On 2024-02-23 21:44:19 UTC - Size: 35.69 KB - 49 views
[2024-02-23 22:56:01]
User856926 - Posts: 9
Ok...I found the issue.

I was using Autoloop and manual loop inadvertently. Now it's lightening fast. You can close the ticket.

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

Login

Login Page - Create Account