Login Page - Create Account

Support Board


Date/Time: Sat, 22 Feb 2025 04:16:55 +0000



Post From: Historical Data for sc.GetBasicSymbolData

[2025-02-20 03:34:53]
cmet - Posts: 640
Well, there you go.

Not too difficult to pull data from separate charts and plot the index.

Can manually adjust weights with inputs or, if you have a dynamic way to calc those, you can add an auto update functionality.

Quick example if you need it. Add as many symbols/weights as you want as long as it has an open chart.

#include "sierrachart.h"

SCDLLName("WeightedIndexStudy")

SCSFExport scsf_WeightedIndex(SCStudyInterfaceRef sc)
{
SCSubgraphRef IndexValue = sc.Subgraph[0];

SCInputRef Chart1 = sc.Input[0];
SCInputRef Chart2 = sc.Input[1];
SCInputRef Chart3 = sc.Input[2];

SCInputRef Weight1 = sc.Input[3];
SCInputRef Weight2 = sc.Input[4];
SCInputRef Weight3 = sc.Input[5];

if (sc.SetDefaults)
{
sc.GraphName = "Weighted Index";
sc.AutoLoop = 1;

IndexValue.Name = "Index Value";
IndexValue.DrawStyle = DRAWSTYLE_LINE;
IndexValue.PrimaryColor = RGB(0, 255, 0);
IndexValue.LineWidth = 2;

Chart1.Name = "Chart Number 1"; Chart1.SetChartNumber(1);
Chart2.Name = "Chart Number 2"; Chart2.SetChartNumber(2);
Chart3.Name = "Chart Number 3"; Chart3.SetChartNumber(3);

Weight1.Name = "Weight 1"; Weight1.SetFloat(0.5f);
Weight2.Name = "Weight 2"; Weight2.SetFloat(0.3f);
Weight3.Name = "Weight 3"; Weight3.SetFloat(0.2f);

return;
}

SCFloatArray Stock1, Stock2, Stock3;
sc.GetChartArray(Chart1.GetChartNumber(), SC_LAST, Stock1);
sc.GetChartArray(Chart2.GetChartNumber(), SC_LAST, Stock2);
sc.GetChartArray(Chart3.GetChartNumber(), SC_LAST, Stock3);

if (Stock1.GetArraySize() > sc.Index && Stock2.GetArraySize() > sc.Index && Stock3.GetArraySize() > sc.Index)
{
IndexValue[sc.Index] = (Stock1[sc.Index] * Weight1.GetFloat()) +
(Stock2[sc.Index] * Weight2.GetFloat()) +
(Stock3[sc.Index] * Weight3.GetFloat());
}
}

Date Time Of Last Edit: 2025-02-20 04:04:18