Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 00:48:23 +0000



Post From: Getting Timely and Accurate IB Data (Interactive Brokers) with version 1148+

[2014-06-21 23:36:22]
Kiwi - Posts: 375
First version (ignore inputs and commented out code which relate to my personal requirements):


/*==========================================================================*/
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 oo = sc.Subgraph[10], oh = sc.Subgraph[11],
          ol = sc.Subgraph[12], oc = sc.Subgraph[13],
          ov = sc.Subgraph[14], ot = sc.Subgraph[15],
          o2 = sc.Subgraph[22], o3 = sc.Subgraph[23],
          o4 = sc.Subgraph[24], o5 = sc.Subgraph[25],
          o6 = sc.Subgraph[26], o7 = sc.Subgraph[27];

  if (sc.SetDefaults) {
sc.GraphName = "TrueLive";
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";

oO.Name="oO"; oH.Name="oH"; oL.Name="oL";
oC.Name="oC"; oV.Name="oV"; oT.Name="oT";
o2.Name="o2"; o3.Name="o3"; o4.Name="o4";
o5.Name="o5"; o6.Name="o6"; o7.Name="o7";

sc.Input[4].Name = "Fixed Scale (Set Value)";
  sc.Input[4].SetFloat(180);
sc.Input[5].Name = "Scale Increment";
  sc.Input[5].SetFloat(5);
sc.Input[6].Name = "Offset LO change direcLIon";
  sc.Input[6].SetFloat(1.5);
sc.Input[7].Name = "Use Centred (vs Const Range)";
  sc.Input[7].ValueType=YESNO_VALUE;
sc.Input[8].Name = "Show Inside Bars";
  sc.Input[8].ValueType=YESNO_VALUE;

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& ChartNumber = sc.PersistVars->i3;
int& lastVis = sc.PersistVars->i4;
float& offset = sc.Input[6].FloatValue;
float& ActiveToolIndex = sc.PersistVars->f1;
double& CurrentBarTime = sc.PersistVars->d1;

int i, j, as = sc.ArraySize-1;
  int ap = as - 1;
int& seqno = sc.PersistVars->i1;

if (sc.UpdateStartIndex == 0) {
int os = 0; // os stores the position of the out array
    seqno = 0;
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] ) {
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]) {
    // update this bar
    oO[os] = O[as];
    oH[os] = max(H[as], oH[os]);
    oL[os] = min(L[as], oL[os]);
    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]);
    oC[op] = C[as];
    oV[op] = V[as];
    oT[op] = T[as];
  }

  // then look at live data
  SCTimeAndSalesArray TSArray;
  sc.GetTimeAndSales(TSArray);
  int ts = TSArray.GetArraySize() - 1;
  o4[os] = 0;
  o2[os] = TSArray[ts].Sequence - seqno;
  o3[os] = TSArray[ts].Sequence;
  if (ts >= 0 && TSArray[ts].Sequence > seqno) {
    int tp = ts, adjt = sc.TimeScaleAdjustment.GetTime();
    double adj = sc.TimeScaleAdjustment;
    while (TSArray[tp].Sequence > seqno) {tp--;}
    // tp++;
    // iterate through each time & sales value
    o5[os] = TSArray[tp].DateTime.GetTime() + adjt;
    o6[os] = sc.DateTimeOut[os].GetTime() + sc.SecondsPerBar;
    for ( ; tp <= ts; tp++) {
      if (TSArray[tp].DateTime.GetTime() + adjt >=
         sc.DateTimeOut[os].GetTime() + sc.SecondsPerBar) {
        os++;
        sc.AddElements(1);
        sc.DateTimeOut[os] = TSArray[tp].DateTime + adj;
        oO[os] = oH[os] = oL[os] = oC[os] = TSArray[tp].Price;
        oV[os] = TSArray[tp].Volume;
        o7[os] += 1;
      }
      else if (TSArray[tp].DateTime.GetTime() + adjt >=
           sc.DateTimeOut[os].GetTime()) {
        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;
        oV[os] += TSArray[tp].Volume;
      }
    }
    seqno = TSArray[ts].Sequence;
  }

  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;

// // Swing Colour Marking
// if(sc.UpdateStartIndex < sc.OutArraySize)
  //   i = sc.UpdateStartIndex-1;
  // else
  //   i = sc.OutArraySize-1;
// for ( ; i <= os; i++) {
// int updown=(int)sc.Subgraph[15][i-1];
  //   if(updown==0) updown=1;
  //   float lowesLHigh=sc.Subgraph[17][i-1];
  //   float highesLLow=sc.Subgraph[18][i-1];
// float& h = sc.Subgraph[1][i];
  //   float& l = sc.Subgraph[2][i];
//
  //   if(updown== 1) { if(l>highesLLow) highesLLow=l; }
  //   else { if(h<lowesLHigh) lowesLHigh=h; }
//
// if(h>lowesLHigh+offset && l>=sc.Subgraph[2][i-1]-offset) {
  //     updown=1; highesLLow=l; lowesLHigh=h;
  //   }
  //   else if(l<highesLLow-offset && h<=sc.Subgraph[1][i-1]+offset) {
  //     updown=-1;lowesLHigh=h; highesLLow=l;
  //   }
//
// if(((L[i] > L[i-1] && H[i] <= H[i-1]) ||
  //     (L[i] >= L[i-1] && H[i] < H[i-1])) && sc.Input[8].BooleanValue) {
  //     oO.DataColor[i] = oH.DataColor[i] = sc.Subgraph[7].PrimaryColor;
  //     oL.DataColor[i] = oC.DataColor[i] = sc.Subgraph[7].PrimaryColor;
  //   } else if(updown==1) {
  //     oO.DataColor[i] = oH.DataColor[i] = sc.Subgraph[6].PrimaryColor;
  //     oL.DataColor[i] = oC.DataColor[i] = sc.Subgraph[6].PrimaryColor;
  //   } else if(updown==-1) {
  //     oO.DataColor[i] = oH.DataColor[i] = sc.Subgraph[6].SecondaryColor;
  //     oL.DataColor[i] = oC.DataColor[i] = sc.Subgraph[6].SecondaryColor;
  //   }
//
// sc.Subgraph[15][i]=updown;
  //   sc.Subgraph[17][i]=lowesLHigh;
  //   sc.Subgraph[18][i]=highesLLow;
// }
//
// // Scale adjustments driven by LogariLHmic trigger
// if(sc.ActiveToolIndex!=0) ActiveToolIndex=sc.ActiveToolIndex;
// if(sc.ScaleType == SCALE_LOGARITHMIC || sc.UpdateStartIndex == 0) {
// if(ActiveToolIndex <= sc.IndexOfLastVisibleBar && ActiveToolIndex > as-50)
// lastVis=as;
  //   else lastVis=sc.IndexOfLastVisibleBar;
//
// float mid=sc.Subgraph[3][lastVis-1], high=sc.Subgraph[1][lastVis],
  //      low=sc.Subgraph[2][lastVis], userrange=sc.Input[4].FloatValue;
// for(j=1;j<100;j++) {
  //     if(high<sc.Subgraph[1][lastVis-j]) high=sc.Subgraph[1][lastVis-j];
  //     if(low>sc.Subgraph[2][lastVis-j]) low=sc.Subgraph[2][lastVis-j];
  //   }
//
// if((high-low)<=userrange) mid=(high+low)/2;
  //     else if((mid-userrange/2)<low) mid=low+userrange/2-2;
  //       else if((mid+userrange/2)>high) mid=high-userrange/2+2;
// sc.ScaleRangeTop=mid+userrange/2;
// sc.ScaleRangeBottom=mid-userrange/2;
//
// sc.Subgraph[9][as] = sc.ActiveToolIndex;
  //   sc.Subgraph[9][as-1] = sc.IndexOfLastVisibleBar;
  //   sc.Subgraph[9][as-1]=lastVis;
//
// if(sc.ScaleType == SCALE_LOGARITHMIC) { if(sc.ScaleRangeType==SCALE_AUTO) {
// if(sc.Input[5].FloatValue != 0) sc.ScaleIncrement = sc.Input[5].FloatValue;
// if(sc.Input[4].BooleanValue) {
// if(sc.Input[7].BooleanValue) {
  //           sc.ScaleRangeType=SCALE_CONSTRANGECENTER;
  //           sc.ScaleConstRange=sc.Input[4].GetFloat();
  //         }
  //         else sc.ScaleRangeType=SCALE_USERDEFINED;
// }
// } else {
// sc.ScaleIncrement = sc.Input[5].FloatValue;
// sc.ScaleRangeType= sc.ScaleRangeType=SCALE_AUTO;
// }
// sc.ScaleType = SCALE_LINEAR;
// }
// }
}



Date Time Of Last Edit: 2014-06-21 23:42:57