any experienced programmers out there that would be willing to help me code a bar by bar degap study using sierra charts. I have a daily shifted de gap written by rainman, and would like to do something similar for each bar intra-day.
Any help here would be greatly appreciated
here is the code for the daily shifted degap:
#include "sierrachart.h"
SCDLLName("Shifted Study DLL")
/***********************************************************************/
SCSFExport scsf_ShiftedStudy(SCStudyGraphRef sc)
{
// Set configuration variables
if (sc.SetDefaults)
{
// Set the defaults
sc.GraphName = "Shifted BaseGraph";
sc.StudyDescription = "The Open value of the next day is set to the Close value of the previous day for all the days, starting with 2nd.";
sc.IsCustomChart = 1;
sc.GraphRegion = 0;
sc.DrawZeros = 0;
sc.GraphDrawType = GDT_OHLCBAR;
sc.StandardChartHeader = 1;
sc.DisplayAsMainPriceGraph = 1;
// Subgraphs
sc.Subgraph[0].Name = "Open";
sc.Subgraph[0].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[1].Name = "High";
sc.Subgraph[1].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[2].Name = "Low";
sc.Subgraph[2].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[3].Name = "Last";
sc.Subgraph[3].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[4].Name = "Open Base";
sc.Subgraph[4].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[5].Name = "High Base";
sc.Subgraph[5].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[6].Name = "Low Base";
sc.Subgraph[6].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[7].Name = "Last Base";
sc.Subgraph[7].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[4].Name = "Volume";
sc.Subgraph[4].DrawStyle = DRAWSTYLE_IGNORE;
sc.Subgraph[5].Name = "# of Trades / OI";
sc.Subgraph[5].DrawStyle = DRAWSTYLE_IGNORE;
sc.Subgraph[6].Name = "OHLC Avg";
sc.Subgraph[6].DrawStyle = DRAWSTYLE_IGNORE;
sc.Subgraph[7].Name = "HLC Avg";
sc.Subgraph[7].DrawStyle = DRAWSTYLE_IGNORE;
sc.Subgraph[8].Name = "HL Avg";
sc.Subgraph[8].DrawStyle = DRAWSTYLE_IGNORE;
sc.Subgraph[9].Name = "Bid Vol";
sc.Subgraph[9].DrawStyle = DRAWSTYLE_IGNORE;
sc.Subgraph[10].Name = "Ask Vol";
sc.Subgraph[10].DrawStyle = DRAWSTYLE_IGNORE;
sc.PersistVars->i1 = -1;
sc.AutoLoop = 1;
return;
}
SCFloatArrayRef ShiftArray = sc.Subgraph[0].Arrays[0];
if (sc.Index == 0)
{
sc.ResizeArrays(0);
sc.PersistVars->i1 = -1;
}
int Index = sc.Index;
if (sc.OutArraySize - 1 < Index)
sc.AddElements(Index - sc.OutArraySize + 1);
//this tick is last day, so just copy everything
for (int SubGraph = 0; SubGraph <= 10; SubGraph++)
sc.Subgraph[SubGraph][Index] = sc.BaseDataIn[SubGraph][Index];
sc.CalculateOHLCAverages(Index);
sc.DateTimeOut[Index] = sc.BaseDateTimeIn[Index];
ShiftArray[Index] = 0;
if(Index < 1)
return;
// don't process the same index again
if (sc.PersistVars->i1 >= sc.Index)
return;
// calculate start date for current index
SCDateTime StartDateTimeOfCurIndex = sc.BaseDateTimeIn[sc.Index].GetDate();
StartDateTimeOfCurIndex.SetTime(sc.StartTimeOfDay);
if(sc.StartTimeOfDay > sc.BaseDateTimeIn[sc.Index].GetTime())
StartDateTimeOfCurIndex -= DAYS;
if(sc.BaseDateTimeIn[Index-1] >= StartDateTimeOfCurIndex)
return;
// save last processed index. We should process it only once
sc.PersistVars->i1 = Index;
float Shift = sc.Subgraph[SC_OPEN][Index] - sc.BaseDataIn[SC_LAST][Index-1];;
for (int i = Index - 1; i >= 0; i--)
{
float CumulativeShift = Shift + ShiftArray;
// shift prices prices
sc.Subgraph[SC_OPEN] = sc.BaseDataIn[SC_OPEN] + CumulativeShift;
sc.Subgraph[SC_HIGH] = sc.BaseDataIn[SC_HIGH] + CumulativeShift;
sc.Subgraph[SC_LOW] = sc.BaseDataIn[SC_LOW] + CumulativeShift;
sc.Subgraph[SC_LAST] = sc.BaseDataIn[SC_LAST] + CumulativeShift;
//recalculate averages
sc.CalculateOHLCAverages(i);
// update shift value
ShiftArray += Shift;
}
}
Any help here would be greatly appreciated
here is the code for the daily shifted degap:
#include "sierrachart.h"
SCDLLName("Shifted Study DLL")
/***********************************************************************/
SCSFExport scsf_ShiftedStudy(SCStudyGraphRef sc)
{
// Set configuration variables
if (sc.SetDefaults)
{
// Set the defaults
sc.GraphName = "Shifted BaseGraph";
sc.StudyDescription = "The Open value of the next day is set to the Close value of the previous day for all the days, starting with 2nd.";
sc.IsCustomChart = 1;
sc.GraphRegion = 0;
sc.DrawZeros = 0;
sc.GraphDrawType = GDT_OHLCBAR;
sc.StandardChartHeader = 1;
sc.DisplayAsMainPriceGraph = 1;
// Subgraphs
sc.Subgraph[0].Name = "Open";
sc.Subgraph[0].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[1].Name = "High";
sc.Subgraph[1].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[2].Name = "Low";
sc.Subgraph[2].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[3].Name = "Last";
sc.Subgraph[3].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[4].Name = "Open Base";
sc.Subgraph[4].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[5].Name = "High Base";
sc.Subgraph[5].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[6].Name = "Low Base";
sc.Subgraph[6].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[7].Name = "Last Base";
sc.Subgraph[7].DrawStyle = DRAWSTYLE_LINE;
sc.Subgraph[4].Name = "Volume";
sc.Subgraph[4].DrawStyle = DRAWSTYLE_IGNORE;
sc.Subgraph[5].Name = "# of Trades / OI";
sc.Subgraph[5].DrawStyle = DRAWSTYLE_IGNORE;
sc.Subgraph[6].Name = "OHLC Avg";
sc.Subgraph[6].DrawStyle = DRAWSTYLE_IGNORE;
sc.Subgraph[7].Name = "HLC Avg";
sc.Subgraph[7].DrawStyle = DRAWSTYLE_IGNORE;
sc.Subgraph[8].Name = "HL Avg";
sc.Subgraph[8].DrawStyle = DRAWSTYLE_IGNORE;
sc.Subgraph[9].Name = "Bid Vol";
sc.Subgraph[9].DrawStyle = DRAWSTYLE_IGNORE;
sc.Subgraph[10].Name = "Ask Vol";
sc.Subgraph[10].DrawStyle = DRAWSTYLE_IGNORE;
sc.PersistVars->i1 = -1;
sc.AutoLoop = 1;
return;
}
SCFloatArrayRef ShiftArray = sc.Subgraph[0].Arrays[0];
if (sc.Index == 0)
{
sc.ResizeArrays(0);
sc.PersistVars->i1 = -1;
}
int Index = sc.Index;
if (sc.OutArraySize - 1 < Index)
sc.AddElements(Index - sc.OutArraySize + 1);
//this tick is last day, so just copy everything
for (int SubGraph = 0; SubGraph <= 10; SubGraph++)
sc.Subgraph[SubGraph][Index] = sc.BaseDataIn[SubGraph][Index];
sc.CalculateOHLCAverages(Index);
sc.DateTimeOut[Index] = sc.BaseDateTimeIn[Index];
ShiftArray[Index] = 0;
if(Index < 1)
return;
// don't process the same index again
if (sc.PersistVars->i1 >= sc.Index)
return;
// calculate start date for current index
SCDateTime StartDateTimeOfCurIndex = sc.BaseDateTimeIn[sc.Index].GetDate();
StartDateTimeOfCurIndex.SetTime(sc.StartTimeOfDay);
if(sc.StartTimeOfDay > sc.BaseDateTimeIn[sc.Index].GetTime())
StartDateTimeOfCurIndex -= DAYS;
if(sc.BaseDateTimeIn[Index-1] >= StartDateTimeOfCurIndex)
return;
// save last processed index. We should process it only once
sc.PersistVars->i1 = Index;
float Shift = sc.Subgraph[SC_OPEN][Index] - sc.BaseDataIn[SC_LAST][Index-1];;
for (int i = Index - 1; i >= 0; i--)
{
float CumulativeShift = Shift + ShiftArray;
// shift prices prices
sc.Subgraph[SC_OPEN] = sc.BaseDataIn[SC_OPEN] + CumulativeShift;
sc.Subgraph[SC_HIGH] = sc.BaseDataIn[SC_HIGH] + CumulativeShift;
sc.Subgraph[SC_LOW] = sc.BaseDataIn[SC_LOW] + CumulativeShift;
sc.Subgraph[SC_LAST] = sc.BaseDataIn[SC_LAST] + CumulativeShift;
//recalculate averages
sc.CalculateOHLCAverages(i);
// update shift value
ShiftArray += Shift;
}
}
