Login Page - Create Account

Support Board


Date/Time: Sun, 19 May 2024 15:32:59 +0000



Post From: Percent Change Since Open study - not starting from zero

[2014-08-28 07:43:43]
Sierra Chart Engineering - Posts: 104368
Below is the source code for the study.

Make changes to it as you require.

Here is the documentation for compiling source code into a DLL:
https://www.sierrachart.com/index.php?page=doc/doc_BuildCustomStudiesDLL.html


/*==========================================================================*/
SCSFExport scsf_PercentChangeSinceOpen(SCStudyInterfaceRef sc)
{
  SCSubgraphRef PercentChange = sc.Subgraph[0];
  SCSubgraphRef ZeroLine = sc.Subgraph[1];
  SCInputRef StartTime = sc.Input[0];

  if (sc.SetDefaults)
  {
    sc.GraphName = "Percent Change Since Open";
    sc.AutoLoop = 1;
    sc.GraphRegion = 1;
    sc.ValueFormat = 2;

    PercentChange.Name = "Percent Change";
    PercentChange.PrimaryColor = RGB(0,255,0);
    PercentChange.DrawStyle = DRAWSTYLE_LINE;
    PercentChange.LineWidth = 1;
    PercentChange.DrawZeros= true;

    ZeroLine. Name= "Zero Line";
    ZeroLine.PrimaryColor = RGB(255,255,0);
    ZeroLine.DrawStyle = DRAWSTYLE_LINE;
    ZeroLine.LineWidth = 1;
    ZeroLine.DrawZeros= true;

    StartTime.Name = "Start Time";
    StartTime.SetCustomInputStrings("Trading Day Start Time;First Bar In Chart");
    StartTime.SetCustomInputIndex(0);

    return;
  }

  float&    OpenValue = sc.PersistVars->f1;
  SCDateTime& SessionStart = sc.PersistVars->scdt1;

  if (sc.Index == 0)
  {
    OpenValue = sc.Open[0];
    SessionStart = sc.GetTradingDayStartDateTimeOfBar(sc.BaseDateTimeIn[0]);
  }

  SCDateTime BarSessionStart = sc.GetTradingDayStartDateTimeOfBar(sc.BaseDateTimeIn[sc.Index]);

  if (BarSessionStart != SessionStart)
  {
    if(StartTime.GetIndex() == 0)
      OpenValue = sc.Open[sc.Index];

    SessionStart = BarSessionStart;
  }

  if(OpenValue == 0)
    PercentChange[sc.Index] = 0;
  else
    PercentChange[sc.Index] = (sc.Close[sc.Index] - OpenValue) / OpenValue * 100.0f;
}

Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing