Login Page - Create Account

Support Board


Date/Time: Thu, 28 Nov 2024 22:30:58 +0000



Custom Made Study Cannot Calculate Back in Time

View Count: 389

[2023-03-22 15:34:58]
User286186 - Posts: 22
Hello I just coded a study in ACSIL that should display a line.

The problem is that it only start to diplay the line from the moment I upload the study to the chart (as you can see on the screenshot).

I tried to add a sc.DataStartIndex statement but it does not solve the problem.


#include "sierrachart.h"

// KST

SCDLLName("KST")

SCSFExport scsf_KST(SCStudyInterfaceRef sc)
{

  SCInputRef Input_W24 = sc.Input[0];
  SCInputRef Input_W18 = sc.Input[1];
  SCInputRef Input_W12 = sc.Input[2];
  SCInputRef Input_W6 = sc.Input[3];

  SCSubgraphRef Subgraph_KST = sc.Subgraph[0];

  SCGraphData SmROC24Data;
  SCGraphData SmROC18Data;
  SCGraphData SmROC12Data;
  SCGraphData SmROC6Data;

  if (sc.SetDefaults)
  {
    sc.GraphName = "KST COMPOSITE INDICATOR";
    sc.StudyDescription = "CFR. P. 788 OF THE BOOK";
    sc.AutoLoop = 1;
    sc.GraphRegion = 0;

    Input_W24.Name = "Weight for 24-period";
    Input_W24.SetInt(4);

    Input_W18.Name = "Weight for 18-period";
    Input_W18.SetInt(3);

    Input_W12.Name = "Weight for 12-period";
    Input_W12.SetInt(2);

    Input_W6.Name = "Weight for 6-period";
    Input_W6.SetInt(1);

    Subgraph_KST.Name = "KST";
    Subgraph_KST.DrawStyle = DRAWSTYLE_LINE;
    Subgraph_KST.PrimaryColor = RGB(0, 255, 0);
    Subgraph_KST.LineWidth = 1;
    Subgraph_KST.DrawZeros = false;

    return;
  }

  if (sc.IsFullRecalculation)
  {
    return;
  }

    // Using sc.GetStudyArraysFromChartUsingID(int ChartNumber, int StudyID, SCGraphData& GraphData).
    sc.GetStudyArraysFromChartUsingID(sc.ChartNumber, 33, SmROC24Data);
    sc.GetStudyArraysFromChartUsingID(sc.ChartNumber, 28, SmROC18Data);
    sc.GetStudyArraysFromChartUsingID(sc.ChartNumber, 26, SmROC12Data);
    sc.GetStudyArraysFromChartUsingID(sc.ChartNumber, 32, SmROC6Data);

    // Define references to subgraph arrays.
    SCFloatArrayRef SmROC24 = SmROC24Data[0];
    SCFloatArrayRef SmROC18 = SmROC18Data[0];
    SCFloatArrayRef SmROC12 = SmROC12Data[0];
    SCFloatArrayRef SmROC6 = SmROC6Data[0];

    float SmROC24LastValue = SmROC24[SmROC24.GetArraySize() - 1];
    float SmROC18LastValue = SmROC18[SmROC18.GetArraySize() - 1];
    float SmROC12LastValue = SmROC12[SmROC12.GetArraySize() - 1];
    float SmROC6LastValue = SmROC6[SmROC6.GetArraySize() - 1];

    int W24Value = Input_W24.GetInt();
    int W18Value = Input_W18.GetInt();
    int W12Value = Input_W12.GetInt();
    int W6Value = Input_W6.GetInt();

    Subgraph_KST[sc.Index] = (W24Value * SmROC24LastValue) + (W18Value * SmROC18LastValue) + (W12Value * SmROC12LastValue) + (W6Value * SmROC6LastValue);

}

Attachment Deleted.
imageCapture d’écran 2023-03-22 163422.png / V - Attached On 2023-03-22 15:34:35 UTC - Size: 61.02 KB - 74 views
[2023-03-22 15:45:42]
User431178 - Posts: 544
The problem is that it only start to diplay the line from the moment I upload the study to the chart (as you can see on the screenshot).


if (sc.IsFullRecalculation)
{
return;
}

You will skip all bars during the initial calculation because of the above code.
[2023-03-22 15:51:14]
User286186 - Posts: 22
Thank you for your help, but it does not solve the problem. I mean, it display the line now, but the value of the line is the same as the first value of when I launch my study (flat line --> see the screenshot).
imageCapture d’écran 2023-03-22 165051.png / V - Attached On 2023-03-22 15:51:01 UTC - Size: 19.21 KB - 77 views
Attachment Deleted.
[2023-03-22 16:44:15]
User431178 - Posts: 544
It solves exactly the problem that you mentioned...

Can you not see why the line would be flat for the initial calculation?


float SmROC24LastValue = SmROC24[SmROC24.GetArraySize() - 1];
float SmROC18LastValue = SmROC18[SmROC18.GetArraySize() - 1];
float SmROC12LastValue = SmROC12[SmROC12.GetArraySize() - 1];
float SmROC6LastValue = SmROC6[SmROC6.GetArraySize() - 1];

Every bar during the initial calculation is referencing the last value in the array, i.e. the last bar.
Date Time Of Last Edit: 2023-03-22 16:45:01
[2023-03-22 16:59:27]
User286186 - Posts: 22
You are right, my bad, sorry. Thanks a lot !

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

Login

Login Page - Create Account