Login Page - Create Account

Support Board


Date/Time: Wed, 01 May 2024 07:25:37 +0000



[Programming Help] - How to avoid Subgraph_

View Count: 608

[2020-05-31 06:30:23]
gfx2trade - Posts: 48
Hi,
New to SC, and C++... I am currently working on a trading system that relies on several intermediate calculations.
I could build part of it, and run it on the plateform, but I wonder if there is a way to avoid using the Subgraph_ "variable"

For example, I currently write sc.simpleAverage(sc.Close, Subgraph_SMA, sc.Index, 21);
Is there another syntax to bypass Subgraph_SMA, e.g. float mySMA = sc.simpleAverage(sc.Close, sc.Index, 21);

In other words, I would like not to see my indicator in the setting/Subgraph of the trading system.

Thanks in advance.

B. Gfx
[2020-06-01 15:11:46]
bradh - Posts: 854
Lookup SCFloatArray. Subgraphs are one form of the SCFloatArray structure. They have the same number of elements as the subgraphs, and can be indexed with sc.Index or with manual looping indices.

Persistent variables can also be used for intermediate calculations, as they do not get reinitialized every time the study runs, and you may only need one of the values, not an array of them.
[2020-06-03 13:25:09]
gfx2trade - Posts: 48
Thks! I guess I am lost with this language.
currently when I display an indicator from a native study it is fully calculated and displayed on the graph.
The same indicator, built in my personal study, results in different values, and it is only calculated and displayed from the current candle onward.
All I want is ...
1- Be able to calculate the indicator in my study
2- Have this indicator values displayed on chart... and give the same result as the native one

how come it is so difficult with SC to code a loop and get the result in an array that I can use for trading signal.

Below is an example... built is succesfull... result is ... not on the graph


#include "sierrachart.h"

SCDLLName("Gfx") // Set DLL Name


/*==========================================================================*/
SCSFExport scsf_gfx(SCStudyInterfaceRef sc)
{

  SCSubgraphRef Subgraph_DMA = sc.Subgraph[0];

  SCInputRef Input_DMAInData = sc.Input[1];
  SCInputRef Input_DMALength = sc.Input[2];
  SCInputRef Input_DMAMultiplier = sc.Input[3];
  SCInputRef Input_DMACount = sc.Input[4];


  if (sc.SetDefaults)
  {

    // Setup - Graph Name
    sc.GraphName = "Gfx";


    Subgraph_DMA.Name = "GFX DMA";
    Subgraph_DMA.DrawStyle = DRAWSTYLE_LINE;
    Subgraph_DMA.AutoColoring = AUTOCOLOR_SLOPE;
    Subgraph_DMA.LineWidth = 2;
    Subgraph_DMA.PrimaryColor = RGB(0, 0, 255);
    Subgraph_DMA.SecondaryColor = RGB(255, 255, 0);
    Subgraph_DMA.DrawZeros = false;

    // *************************************************************************************************************
    // System parameters
    // *************************************************************************************************************
    
    sc.StudyDescription = "ACSIL investigation";
    sc.AutoLoop = 1;
    sc.GraphRegion = 1;

    Input_DMAInData.Name = "Input DMA";
    Input_DMAInData.SetInputDataIndex(SC_LAST);

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

    Input_DMAMultiplier.Name = "Multiplier";
    Input_DMAMultiplier.SetFloat(1.0f);

    Input_DMACount.Name = "GDEMA Count";
    Input_DMACount.SetInt(1);
    Input_DMACount.SetIntLimits(1, SC_SUBGRAPHS_AVAILABLE - 1);


    return;
  }
    // ------------------------------------------------------------------------------------------------
    // GFX DMA - START
    // ------------------------------------------------------------------------------------------------
  
    int Length = Input_DMALength.GetInt();
    float Multiplier = Input_DMAMultiplier.GetFloat();
    int Count = Input_DMACount.GetInt();

      sc.DataStartIndex = Length * Count;

      if (sc.Index == 0)
      {
        for (int SubgraphIndex = 1; SubgraphIndex <= Count; SubgraphIndex++)
        {
        Subgraph_DMA.Name.Format("%d", SubgraphIndex);
        Subgraph_DMA.DrawStyle = DRAWSTYLE_LINE;
        Subgraph_DMA.DisplayNameValueInWindowsFlags = 0;
        }
      }

      sc.ExponentialMovAvg(sc.BaseDataIn[Input_DMAInData.GetInputDataIndex()], Subgraph_DMA.Arrays[0], Length);
      sc.ExponentialMovAvg(Subgraph_DMA.Arrays[0], Subgraph_DMA.Arrays[1], Length);
      Subgraph_DMA.Arrays[3][sc.Index] = (1 + Multiplier) * Subgraph_DMA.Arrays[0][sc.Index] - Multiplier * Subgraph_DMA.Arrays[1][sc.Index];

    for (int SubgraphIndex = 2; SubgraphIndex <= Count; SubgraphIndex++)
    {
      sc.ExponentialMovAvg(Subgraph_DMA, Subgraph_DMA.Arrays[0], Length);
      sc.ExponentialMovAvg(Subgraph_DMA.Arrays[0], Subgraph_DMA.Arrays[1], Length);
      Subgraph_DMA.Arrays[3][sc.Index] = (1 + Multiplier) * Subgraph_DMA.Arrays[0][sc.Index] - Multiplier * Subgraph_DMA.Arrays[1][sc.Index];
    }

    Subgraph_DMA[sc.Index] = sc.Subgraph[Count][sc.Index];


    // ------------------------------------------------------------------------------------------------
    // GFX DMA - END
    // ------------------------------------------------------------------------------------------------

}

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

Login

Login Page - Create Account