Login Page - Create Account

Support Board


Date/Time: Mon, 06 Apr 2020 14:00:17 +0000



[User Discussion] - Automatically Plot Lines For High/Low of First Bar of Session Only

[2015-01-29 15:34:35]
pst - Posts: 366 | Ending Date: 2020-05-07
I'm looking to automatically plot extended horizontal lines of both the high and low of the first bar of the session only.
Is this possible? If so, what is the best approach to use? This needs to be based on the bar and not on time.

Looking for something simple like this:

http://s4.postimg.org/vo0pj1kpp/ohilo.jpg

Thanks in advance for any help.

Date Time Of Last Edit: 2015-01-29 15:34:52
[2015-01-29 16:00:47]
tickHunter - Posts: 14 | Ending Date: 2016-02-02 [Expired]
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];
  }

}

[2015-01-29 16:11:19]
pst - Posts: 366 | Ending Date: 2020-05-07
Perfect. Thanks a lot for this.
[2015-01-29 17:49:17]
Sierra Chart Engineering - Posts: 83164 | Ending Date: 2020-06-09
Try using the High/Low for Time Period - Extended study and set the Start and End time to cover 1 minute.
Sierra Chart Support - Engineering Level

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

If your question/request has been answered and you do not have anything further, then it is easiest for us if you do not reply again to say thank you.
[2015-01-29 17:51:56]
pst - Posts: 366 | Ending Date: 2020-05-07
Thanks but accurate opening swing is based on price, not time. Floor guy's I know who trade CL may use 1 minute but it's simply not useful in markets like ES (imo).
[2015-01-29 21:17:45]
Sierra Chart Engineering - Posts: 83164 | Ending Date: 2020-06-09
When the time period is set to a short time like 1 minute, unless the chart bars are less than 1 minute, it will always map to the first bar only containing the specified Start Time.
Sierra Chart Support - Engineering Level

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

If your question/request has been answered and you do not have anything further, then it is easiest for us if you do not reply again to say thank you.
Date Time Of Last Edit: 2015-01-29 22:47:07
[2015-01-29 21:47:40]
ejtrader - Posts: 545 | Ending Date: 2021-04-19
pst - Pulled up this code from some other studies I have built and modified to meet this request.

There are no inputs to this study. If you set your session time correctly - it would pick the very first bar of the session and calculates the high/low for that chart ( chart can be of any type - not necessarily time based chart as long as session times are defined properly for the chart).

If you need any small customizations on this - can help you with that.

http://www.sierrachart.com/image.php?l=1422568017773.png

#include "sierrachart.h"

SCDLLName("HighLowBar")

SCSFExport scsf_HighLowBar(SCStudyInterfaceRef sc)
{

SCSubgraphRef hValue = sc.Subgraph[0];
SCSubgraphRef lValue = sc.Subgraph[1];

if (sc.SetDefaults) {

sc.GraphName = "HighLowBar";
sc.StudyDescription = "HighLowBar - Calculate High/Low for a Single Bar";
sc.GraphDrawType = GDT_CUSTOM;
sc.GraphRegion = 0;
sc.FreeDLL = 0;
sc.AutoLoop = 1;

hValue.Name = "HighValue";
hValue.DrawStyle = DRAWSTYLE_RIGHTHASH;
hValue.PrimaryColor = COLOR_DARKGRAY;
hValue.DrawZeros = false;

lValue.Name = "LowValue";
lValue.DrawStyle = DRAWSTYLE_RIGHTHASH;
lValue.PrimaryColor = COLOR_DARKGRAY;
lValue.DrawZeros = false;

return;
}

int &lastIndex = sc.GetPersistentInt(0);

if (sc.UpdateStartIndex == 0) {
lastIndex = -1;
}

int i = sc.Index;

if (lastIndex == sc.Index) {
return;
}
lastIndex = sc.Index;

hValue[i] = hValue[i - 1];
lValue[i] = lValue[i - 1];

if (sc.BaseDateTimeIn[i - 2].GetTime() < sc.SessionStartTime()
&& sc.BaseDateTimeIn[i - 1].GetTime() >= sc.SessionStartTime()) {
hValue[i] = sc.High[i - 1];
lValue[i] = sc.Low[i - 1];
}

return;
}

Date Time Of Last Edit: 2015-01-29 22:20:24
[2015-01-29 22:13:22]
pst - Posts: 366 | Ending Date: 2020-05-07
Thanks. Use non time based bars so it can take more than 1 minute for the swing.

The code from tickHunter works perfectly.

Appreciate the help.
Date Time Of Last Edit: 2015-01-29 22:14:39

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

Login

Login Page - Create Account