Login Page - Create Account

Support Board


Date/Time: Mon, 25 Nov 2024 16:34:02 +0000



Post From: App is slow to respond after installing this study

[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);
}
}


}