Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 02:22:37 +0000



Post From: TrueLive 2014 for SC V1149 Onwards

[2014-06-25 06:59:39]
Kiwi - Posts: 375
All of those things improved the presentation. I also changed it so that the 5 second close can't ever set the close on the active bar - its always set by T&S. Why? Because I noted that as the new T&S based bar starts (first 5 seconds) you can get two 5 second bars and sometimes the close would swing wildly before the first 5 sec packet for the new bar arrived. Basically I think that one 5 sec bar and a T&S value (or 2) get out of sequence.

When I eliminated the ability of that 5 second packet to reset the close the behaviour settles nicely and all the closes were orderly.

So heres the new edition.

/*==========================================================================*/
SCSFExport scsf_TrueLive_2014(SCStudyInterfaceRef sc) {

SCFloatArray& O = sc.BaseDataIn[0], H = sc.BaseDataIn[1],
L = sc.BaseDataIn[2], C = sc.BaseDataIn[3],
V = sc.BaseDataIn[4], T = sc.BaseDataIn[5];
SCSubgraphRef oO = sc.Subgraph[0], oH = sc.Subgraph[1],
oL = sc.Subgraph[2], oC = sc.Subgraph[3],
oV = sc.Subgraph[4], oT = sc.Subgraph[5];
SCSubgraphRef o = sc.Subgraph[10], h = sc.Subgraph[11],
l = sc.Subgraph[12], c = sc.Subgraph[13],
v = sc.Subgraph[14], t = sc.Subgraph[15],
o2 = sc.Subgraph[22], o3 = sc.Subgraph[23],
o4 = sc.Subgraph[24], o5 = sc.Subgraph[25];

if (sc.SetDefaults) {
sc.GraphName = "TrueLive 2014";
sc.StudyDescription = "True Live using Custom Chart 2014 Release";
sc.Subgraph[0].Name = "Open";
sc.Subgraph[1].Name = "High";
sc.Subgraph[2].Name = "Low";
sc.Subgraph[3].Name = "Last";
sc.Subgraph[4].Name = "Volume";
sc.Subgraph[5].Name = "# of Trades";
sc.Subgraph[6].Name = "HL";
sc.Subgraph[7].Name = "HLC";
sc.Subgraph[8].Name = "OHLC";
o2.Name="o2"; o3.Name="o3";
o4.Name="o4"; o5.Name="o5";
sc.GraphRegion = 0; // First region
sc.GraphDrawType = GDT_CANDLESTICK;
sc.DisplayAsMainPriceGraph=1;
sc.IsCustomChart = 1;
sc.UpdateAlways=1;
sc.DrawZeros=0;
return;
}
// sc.FreeDLL = 1;

int as = sc.ArraySize-1;
int ap = as - 1;
int& seqno = sc.PersistVars->i1;
int& tnsno = sc.PersistVars->i2;
SCTimeAndSalesArray TSArray;
sc.GetTimeAndSales(TSArray);
int ts = TSArray.GetArraySize() - 1;

if (sc.UpdateStartIndex == 0) {
int os = 0; // os stores the position of the out array
tnsno = seqno = 0;
if (ts >= 0)
seqno = TSArray[ts].Sequence;
sc.ResizeArrays(0);
for ( ; os < sc.ArraySize; os++) {
sc.AddElements(1);
sc.DateTimeOut[os] = sc.BaseDateTimeIn[os];
oO[os] = O[os];
oH[os] = H[os];
oL[os] = L[os];
oC[os] = C[os];
oV[os] = V[os];
oT[os] = T[os];
sc.Subgraph[SC_HL][os] = (oH[os] + oL[os]) / 2;
sc.Subgraph[SC_HLC][os] = (oH[os] + oL[os] + oC[os]) / 3;
sc.Subgraph[SC_OHLC][os] = (oH[os] + oL[os] + oC[os] + oO[os]) / 4;
}
}

// First deal with underlying data
int os = sc.OutArraySize-1;
// add an extra bar if the underlying is later than the output bar
if( sc.BaseDateTimeIn[as] > sc.DateTimeOut[os] ) {
// only add element if there isn't a spurious t&s element present
if(tnsno == 0) os++;
sc.AddElements(1);
sc.DateTimeOut[os] = sc.BaseDateTimeIn[as];
oO[os] = oH[os] = oL[os] = oC[os] = O[as];
}
int op = os - 1;
if (sc.DateTimeOut[os] == sc.BaseDateTimeIn[as]) {
// Only apply 5 second data if its changed (ie dont reset live changes)
if(c[os] != C[as] || v[os] != V[as] || h[os] != H[as] || l[os] != L[as])
{
tnsno = 0;
h[os] = H[as]; l[os] = L[as];
c[os] = C[as]; v[os] = V[as];
// update this bar
oO[os] = O[as]; oH[os] = H[as];
oL[os] = L[as]; // oC[os] = C[as];
oV[os] = V[as]; oT[os] = T[as];
// match prior bar to 5 second data
oO[op] = O[ap]; oH[op] = H[ap];
oL[op] = L[ap]; oC[op] = C[ap];
oV[op] = V[ap]; oT[op] = T[ap];
}
}
else if (sc.DateTimeOut[op] == sc.BaseDateTimeIn[as]) {
// must be in first 5 seconds of new bar so
// update prior bar with 5 second data
oO[op] = O[as];
oH[op] = max(H[as], oH[op]);
oL[op] = min(L[as], oL[op]);
if (sc.CurrentSystemDateTime.GetTime() >
sc.BaseDateTimeIn[as].GetTime() + sc.SecondsPerBar + 15) {
oC[op] = C[as];
}
oV[op] = V[as]; oT[op] = T[as];
}

// then look at live data
if (ts >= 0 && TSArray[ts].Sequence > seqno) {
int tp = ts;
int adjt = sc.TimeScaleAdjustment.GetTime();
double adj = sc.TimeScaleAdjustment;
while (TSArray[tp].Sequence > seqno) {tp--;}
// iterate through each time & sales value
for ( ; tp <= ts; tp++) {
// if its a new bar start one
if (tnsno == 0 && TSArray[tp].DateTime.GetTime() + adjt >=
sc.DateTimeOut[os].GetTime() + sc.SecondsPerBar) {
tnsno = 1; // flag that a time&sales bar has been created
os++;
sc.AddElements(1);
sc.DateTimeOut[os].SetDate(sc.DateTimeOut[as].GetDate());
sc.DateTimeOut[os].SetTime(sc.DateTimeOut[as].GetTime() +
sc.SecondsPerBar);
// note that for new session this bar time is wrong
// and it will be cancelled as spurious so the new bar
// will be formed when the first 5 sec bar arrives
oO[os] = oH[os] = oL[os] = oC[os] = TSArray[tp].Price;
oV[os] = TSArray[tp].Volume;
}
// else update high low and close for this bar
else if (TSArray[tp].DateTime.GetTime() + adjt >=
sc.DateTimeOut[os].GetTime() &&
TSArray[tp].DateTime.GetTime() + adjt <
sc.DateTimeOut[os].GetTime() + sc.SecondsPerBar) {
oH[os] = max(TSArray[tp].Price, oH[os]);
if (TSArray[tp].Price > 0 && oL[os] > 0)
oL[os] = min(TSArray[tp].Price, oL[os]);
else
oL[os] = max(TSArray[tp].Price, oL[os]);
oC[os] = TSArray[tp].Price;
}
}
seqno = TSArray[ts].Sequence;
}
// Check for spurious time & sales based bars (> 10 seconds with no 5sec)
if(tnsno != 0) {
// spurious if no 5 second confirmation within 15 seconds
if(sc.CurrentSystemDateTime.GetDate() > sc.DateTimeOut[os].GetDate() ||
sc.CurrentSystemDateTime.GetTime() > sc.DateTimeOut[os].GetTime()
+ 15) {
sc.AddElements(-1);
tnsno = 0;
}
}

sc.Subgraph[SC_HL][os] = (oH[os] + oL[os]) / 2;
sc.Subgraph[SC_HLC][os] = (oH[os] + oL[os] + oC[os]) / 3;
sc.Subgraph[SC_OHLC][os] = (oH[os] + oL[os] + oC[os] + oO[os]) / 4;
sc.Subgraph[SC_HL][op] = (oH[op] + oL[op]) / 2;
sc.Subgraph[SC_HLC][op] = (oH[op] + oL[op] + oC[op]) / 3;
sc.Subgraph[SC_OHLC][op] = (oH[op] + oL[op] + oC[op] + oO[op]) / 4;
}



Date Time Of Last Edit: 2014-06-28 05:33:37
attachmentkiwi14.dll - Attached On 2014-06-25 06:56:53 UTC - Size: 157 KB - 540 views
attachmentkiwi14.cpp - Attached On 2014-06-25 06:58:04 UTC - Size: 12.6 KB - 699 views
attachmentkiwi14.dll - Attached On 2014-06-25 06:56:53 UTC - Size: 157 KB - 540 views
attachmentkiwi14.cpp - Attached On 2014-06-25 06:58:04 UTC - Size: 12.6 KB - 699 views