Login Page - Create Account

Support Board


Date/Time: Wed, 22 May 2024 01:39:17 +0000



Post From: How to avoid Subgraph_

[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
    // ------------------------------------------------------------------------------------------------

}