Login Page - Create Account

Support Board


Date/Time: Fri, 26 Apr 2024 05:11:56 +0000



Post From: Automatically Plot Lines For High/Low of First Bar of Session Only

[2015-01-29 16:00:47]
tickHunter - Posts: 14
I do this on a volume based chart, here is the code:



/*****************************************************************************
  This is a C++ source code file. This file contains example Advanced Custom
  Study functions. It also contains functions for some built-in studies
  in Sierra Chart.
*****************************************************************************/

#include "sierrachart.h"

/****************************************************************************/

SCDLLName("OS Marker")


SCSFExport scsf_OSMarker(SCStudyInterfaceRef sc)
{
  SCSubgraphRef OSHigh = sc.Subgraph[0];
  SCSubgraphRef OSLow = sc.Subgraph[1];
  SCSubgraphRef OSRange = sc.Subgraph[2];
  
  
  // Set configuration variables
  if (sc.SetDefaults)
  {
    
    sc.GraphName = "OS Marker";
    sc.StudyDescription = "Marks the Opening Swing High and Low";
    
    sc.Input[1].Name = "Day Session Start";
    sc.Input[1].SetTime(HMS_TIME(8,30,0));
    
    sc.Input[2].Name = "Day Session End";
    sc.Input[2].SetTime(HMS_TIME(15,14,59));    
    
    
    // Set the region to draw the graph in. Region zero is the main
    // price graph region.
    sc.GraphRegion = 0;
    
    // Set the name of the first subgraph
    OSHigh.Name = "Opening Swing High";
    OSLow.Name = "Opening Swing Low";
    
    sc.AutoLoop = 1;
    
    // During development set this flag to 1, so the DLL can be modified. When development is completed, set it to 0 to improve performance.
    sc.FreeDLL = 0;
    
    // Must return before doing any data processing if sc.SetDefaults is set
    return;
  }
// Bar index of beginning of trading day for bar at current index. This depends upon auto looping being true.

int &dateToday = sc.PersistVars->i1;

SCDateTime BarDateTime = sc.BaseDateTimeIn[sc.Index];
dateToday = BarDateTime.GetDate();
SCDateTime StartTimeToday;
SCDateTime EndTimeToday;
float OSHighNum = sc.PersistVars->f1;
float OSLowNum = sc.PersistVars->f2;

StartTimeToday.SetDateTime(dateToday, sc.Input[1].GetTime());
EndTimeToday.SetDateTime(dateToday, sc.Input[2].GetTime());

int StartOfDayIndex = sc.GetContainingIndexForSCDateTime(sc.ChartNumber, StartTimeToday);
int EndOfDayIndex = sc.GetContainingIndexForSCDateTime(sc.ChartNumber, EndTimeToday);

if(sc.Index == StartOfDayIndex) {
  OSHighNum = sc.BaseData[SC_HIGH][StartOfDayIndex];
  OSLowNum = sc.BaseData[SC_LOW][StartOfDayIndex];
  OSHigh[sc.Index] = OSHighNum;
OSLow[sc.Index] = OSLowNum;
  
  OSHigh.ExtendedArrayElementsToGraph = 10;
  OSLow.ExtendedArrayElementsToGraph = 10;

}  
  else {
    OSHigh[sc.Index] = OSHigh[sc.Index - 1];
    OSLow[sc.Index] = OSLow[sc.Index - 1];
  }

}