Login Page - Create Account

Support Board


Date/Time: Fri, 27 Dec 2024 02:24:47 +0000



Post From: Timeframe Overlay

[2016-02-17 07:58:21]
Kiwi - Posts: 375
You could use one on top of the other (one is stairsteps maybe and the other is vertical boxes).

Or here is code for some 2 TF on one TF variations that I use myself ... I don't recall the last time I used the third one which mixes some things up ... but try them and see what works for you.

http://i.imgur.com/T75aS0Y.png





/***********************************************************************/
SCSFExport scsf_TwoTFBars(SCStudyGraphRef sc)
{
  if (sc.SetDefaults)
  {
    sc.GraphName = "Two TimeFrame Bars";
    sc.StudyDescription = " ";
    sc.Subgraph[0].Name = "sH";
    sc.Subgraph[1].Name = "sL";
    sc.Subgraph[2].Name = "fH";
    sc.Subgraph[3].Name = "fL";
    sc.Subgraph[6].Name = "D";
    sc.Subgraph[7].Name = "o1";
    sc.Subgraph[8].Name = "o2";
    sc.Subgraph[10].Name = "high";
    sc.Subgraph[11].Name = "low";
    sc.Subgraph[12].Name = "lowesthigh";
    sc.Subgraph[13].Name = "highestlow";
    sc.Input[1].Name = "slow multiplier";
    sc.Input[2].Name = "fast multiplier";
    sc.Input[1].SetFloat(15.0);
    sc.Input[2].SetFloat(5.0);
    sc.Input[3].Name = "ValueOffset";
    sc.Input[4].Name = "Cosmetic Offset Down";
    sc.Input[3].SetFloat(1.5);
    sc.Input[4].SetFloat(0.05);
    sc.DrawZeros = 0;
    sc.FreeDLL = 0;
    return;
  }

  if(sc.Subgraph[9][1] == sc.BaseDateTimeIn[sc.ArraySize-1].GetTime()
   && sc.UpdateStartIndex != 0
   && sc.BaseDataIn[1][sc.ArraySize-1] < (sc.Subgraph[1][sc.ArraySize-1] - sc.Input[4].FloatValue)
   && sc.BaseDataIn[2][sc.ArraySize-1] > (sc.Subgraph[2][sc.ArraySize-1] + sc.Input[4].FloatValue)
   ) return;
  sc.Subgraph[9][1] = sc.BaseDateTimeIn[sc.ArraySize-1].GetTime();

  int& updown = sc.GetPersistentInt(9);
  float& Color = sc.GetPersistentFloat(9);
  float& cosmetic_offset = sc.Input[4].FloatValue;
  unsigned int& UpColor = sc.Subgraph[0].PrimaryColor;
  unsigned int& DnColor = sc.Subgraph[1].PrimaryColor;
  unsigned int& sUpColor = sc.Subgraph[2].PrimaryColor;
  unsigned int& sDnColor = sc.Subgraph[3].PrimaryColor;

  int pos, i;
  int h0, m, m0;
  float& offset = sc.Input[3].FloatValue;
  float &timeh = sc.Input[1].FloatValue;

  float& High = sc.GetPersistentFloat(1);
  float& Low = sc.GetPersistentFloat(2);
  float& pHigh = sc.GetPersistentFloat(5);
  float& pLow = sc.GetPersistentFloat(6);
  float& highestlow = sc.GetPersistentFloat(3);
  float& lowesthigh = sc.GetPersistentFloat(4);
  int& startbar = sc.GetPersistentInt(1);
  int& bar = sc.GetPersistentInt(2);

  float& sHigh = sc.GetPersistentFloat(11);
  float& sLow = sc.GetPersistentFloat(12);
  float& times = sc.Input[2].FloatValue;
  float& tPerBar = sc.GetPersistentFloat(13);

  if (sc.UpdateStartIndex == 0) {
    highestlow = 0.0;
    lowesthigh = 999999.9;
    updown = 1;
    startbar = 0;
    tPerBar = sc.SecondsPerBar/60.0;
  }
  else startbar = min(bar-timeh, sc.ArraySize);

  for (pos = startbar ; pos < sc.ArraySize; pos++)
  {
    int p = pos - 1;
    High = sc.Subgraph[10][p];
    Low = sc.Subgraph[11][p];
    lowesthigh = sc.Subgraph[12][p];
    highestlow = sc.Subgraph[13][p];
  
    TIME_TO_HMS(sc.BaseDateTimeIn[pos].GetTime(),h0,m0,m);
    float time_now = float(h0*60.0 + m0);
    //sc.Subgraph[7][pos] = time_now;
    //sc.Subgraph[8][pos] = fmod(time_now, timeh);

    if( fmod(time_now, timeh) == 0 )
    {
      bar = pos;
      pHigh = High;
      pLow = Low;
      High = 0; Low = 99999;
      for(i = 0; i < timeh/tPerBar && (pos+i)<sc.ArraySize; i++)
      {
        if(sc.BaseDataIn[1][pos+i] > High)
          High = sc.BaseDataIn[1][pos+i];
        if(sc.BaseDataIn[2][pos+i] < Low)
          Low = sc.BaseDataIn[2][pos+i];
      }
      if(updown == 1)
        {if(Low > highestlow) highestlow = Low;}
      else
        if(High < lowesthigh) lowesthigh = High;
      if(High > lowesthigh+offset
       && Low >= pLow) {
        updown = 1;
        highestlow = Low;
        lowesthigh = High;
      }
      else
      if(Low<highestlow-offset
       && High <= pHigh) {
        updown = -1;
        lowesthigh = High;
        highestlow = Low;
      }
    }

    sc.Subgraph[6][pos] = updown; //fmod(float(m0),5);
    if(updown == 1) {
      sc.Subgraph[0].DataColor[pos] = UpColor;
      sc.Subgraph[2].DataColor[pos] = sUpColor;
    }
    else if(updown == -1) {
      sc.Subgraph[0].DataColor[pos] = DnColor;
      sc.Subgraph[2].DataColor[pos] = sDnColor;
    }

    sc.Subgraph[0][pos] = High+cosmetic_offset;
    sc.Subgraph[1][pos] = Low-cosmetic_offset;
    if(timeh == times || times == 0) return;
    if(fmod(time_now, times) == 0)
    {
      sHigh = 0; sLow = 99999;
      for(i = 0; i < times/tPerBar && (pos+i)<sc.ArraySize; i++)
      {
        if(sc.BaseDataIn[1][pos+i] > sHigh)
          sHigh = sc.BaseDataIn[1][pos+i];
        if(sc.BaseDataIn[2][pos+i] < sLow)
          sLow = sc.BaseDataIn[2][pos+i];
      }
    }

    sc.Subgraph[2][pos] = sHigh+cosmetic_offset;
    sc.Subgraph[3][pos] = sLow-cosmetic_offset;
    sc.Subgraph[10][pos] = High;
    sc.Subgraph[11][pos] = Low;
    sc.Subgraph[12][pos] = lowesthigh;
    sc.Subgraph[13][pos] = highestlow;
  }
}



/***********************************************************************/
SCSFExport scsf_TwoTFBarsSecs(SCStudyGraphRef sc)
{
  if (sc.SetDefaults)
  {
    sc.GraphName = "Two TimeFrame Bars using Seconds";
    sc.StudyDescription = " ";
    sc.Subgraph[0].Name = "hH";
    sc.Subgraph[1].Name = "hL";
    sc.Subgraph[2].Name = "mH";
    sc.Subgraph[3].Name = "mL";
    sc.Subgraph[6].Name = "D";
    sc.Subgraph[7].Name = "o1";
    sc.Subgraph[8].Name = "o2";
    sc.Subgraph[10].Name = "high";
    sc.Subgraph[11].Name = "low";
    sc.Subgraph[12].Name = "lowesthigh";
    sc.Subgraph[13].Name = "highestlow";
    sc.Input[1].Name = "secs for high tf";
    sc.Input[2].Name = "secs for short tf";
    sc.Input[1].SetFloat(900.0);
    sc.Input[2].SetFloat(300.0);
    sc.Input[3].Name = "ValueOffset";
    sc.Input[4].Name = "Cosmetic Offset Down";
    sc.Input[3].SetFloat(1.5);
    sc.Input[4].SetFloat(0.05);
    sc.DrawZeros = 0;
    sc.FreeDLL = 0;
    return;
  }

  if(sc.Subgraph[9][1] == sc.BaseDateTimeIn[sc.ArraySize-1].GetTime()
   && sc.UpdateStartIndex != 0
   && sc.BaseDataIn[1][sc.ArraySize-1] <
     (sc.Subgraph[1][sc.ArraySize-1] - sc.Input[4].FloatValue)
   && sc.BaseDataIn[2][sc.ArraySize-1] >
     (sc.Subgraph[2][sc.ArraySize-1] + sc.Input[4].FloatValue))
    return;
  sc.Subgraph[9][1] = sc.BaseDateTimeIn[sc.ArraySize-1].GetTime();

  int& updown = sc.GetPersistentInt(9);
  float& Color = sc.GetPersistentFloat(9);
  float& cosmetic_offset = sc.Input[4].FloatValue;
  unsigned int& UpColor = sc.Subgraph[0].PrimaryColor;
  unsigned int& DnColor = sc.Subgraph[1].PrimaryColor;
  unsigned int& sUpColor = sc.Subgraph[2].PrimaryColor;
  unsigned int& sDnColor = sc.Subgraph[3].PrimaryColor;

  int pos, i;
  int h0, m0, s0;
  float& offset = sc.Input[3].FloatValue;
  float &timeh = sc.Input[1].FloatValue;

  float& High = sc.GetPersistentFloat(1);
  float& Low = sc.GetPersistentFloat(2);
  float& pHigh = sc.GetPersistentFloat(5);
  float& pLow = sc.GetPersistentFloat(6);
  float& highestlow = sc.GetPersistentFloat(3);
  float& lowesthigh = sc.GetPersistentFloat(4);
  int& startbar = sc.GetPersistentInt(1);
  int& bar = sc.GetPersistentInt(2);

  float& sHigh = sc.GetPersistentFloat(11);
  float& sLow = sc.GetPersistentFloat(12);
  float& times = sc.Input[2].FloatValue;
  float& tPerBar = sc.GetPersistentFloat(13);

  if (sc.UpdateStartIndex == 0) {
    highestlow = 0.0;
    lowesthigh = 999999.9;
    updown = 1;
    startbar = 0;
    tPerBar = sc.SecondsPerBar;
  }
  else startbar = min(bar, sc.ArraySize);

  for (pos = startbar ; pos < sc.ArraySize; pos++)
  {
    int p = pos - 1;
    High = sc.Subgraph[10][p];
    Low = sc.Subgraph[11][p];
    lowesthigh = sc.Subgraph[12][p];
    highestlow = sc.Subgraph[13][p];
  
    TIME_TO_HMS(sc.BaseDateTimeIn[pos].GetTime(),h0,m0,s0);
    float time_now = float(h0*3600.0 + m0*60.0 + s0);
    //sc.Subgraph[7][pos] = time_now;
    //sc.Subgraph[8][pos] = fmod(time_now, timeh);

    if( fmod(time_now, timeh) == 0 )
    {
      bar = pos;
      pHigh = High;
      pLow = Low;
      High = 0; Low = 99999;
      for(i = 0; i < timeh/tPerBar && (pos+i)<sc.ArraySize; i++)
      {
        if(sc.BaseDataIn[1][pos+i] > High)
          High = sc.BaseDataIn[1][pos+i];
        if(sc.BaseDataIn[2][pos+i] < Low)
          Low = sc.BaseDataIn[2][pos+i];
      }
      if(updown == 1)
        {if(Low > highestlow) highestlow = Low;}
      else
        if(High < lowesthigh) lowesthigh = High;
      if(High > lowesthigh+offset
       && Low >= pLow) {
        updown = 1;
        highestlow = Low;
        lowesthigh = High;
      }
      else
      if(Low<highestlow-offset
       && High <= pHigh) {
        updown = -1;
        lowesthigh = High;
        highestlow = Low;
      }
    }

    sc.Subgraph[6][pos] = updown; //fmod(float(m0),5);
    if(updown == 1) {
      sc.Subgraph[0].DataColor[pos] = UpColor;
      sc.Subgraph[2].DataColor[pos] = sUpColor;
    }
    else if(updown == -1) {
      sc.Subgraph[0].DataColor[pos] = DnColor;
      sc.Subgraph[2].DataColor[pos] = sDnColor;
    }

    sc.Subgraph[0][pos] = High+cosmetic_offset;
    sc.Subgraph[1][pos] = Low-cosmetic_offset;
    if(timeh == times || times == 0) return;
    if(fmod(time_now, times) == 0)
    {
      sHigh = 0; sLow = 99999;
      for(i = 0; i < times/tPerBar && (pos+i)<sc.ArraySize; i++)
      {
        if(sc.BaseDataIn[1][pos+i] > sHigh)
          sHigh = sc.BaseDataIn[1][pos+i];
        if(sc.BaseDataIn[2][pos+i] < sLow)
          sLow = sc.BaseDataIn[2][pos+i];
      }
    }

    sc.Subgraph[2][pos] = sHigh+cosmetic_offset;
    sc.Subgraph[3][pos] = sLow-cosmetic_offset;
    sc.Subgraph[10][pos] = High;
    sc.Subgraph[11][pos] = Low;
    sc.Subgraph[12][pos] = lowesthigh;
    sc.Subgraph[13][pos] = highestlow;
  }
}



/***********************************************************************/
SCSFExport scsf_TwoTFBarsX(SCStudyGraphRef sc)
{
  if (sc.SetDefaults)
  {
    sc.GraphName = "Two TimeFrame Bars";
    sc.StudyDescription = " ";
    sc.Subgraph[0].Name = "hH";
    sc.Subgraph[1].Name = "hL";
    sc.Subgraph[2].Name = "mH";
    sc.Subgraph[3].Name = "mL";
    sc.Subgraph[6].Name = "D";
    sc.Subgraph[7].Name = "o1";
    sc.Subgraph[8].Name = "o2";
    sc.Subgraph[10].Name = "high";
    sc.Subgraph[11].Name = "low";
    sc.Subgraph[12].Name = "lowesthigh";
    sc.Subgraph[13].Name = "highestlow";
    sc.Subgraph[20].Name = "vwsess";
    sc.Subgraph[21].Name = " ";
    sc.Subgraph[22].Name = " ";
    sc.Subgraph[23].Name = "vwday";
    sc.Subgraph[24].Name = " ";
    sc.Subgraph[25].Name = " ";
    sc.Input[1].Name = "high multiplier";
    sc.Input[2].Name = "medium multiplier";
    sc.Input[1].SetFloat(15.0);
    sc.Input[2].SetFloat(5.0);
    sc.Input[3].Name = "ValueOffset";
    sc.Input[4].Name = "Cosmetic Offset Down";
    sc.Input[3].SetFloat(1.5);
    sc.Input[4].SetFloat(0.05);
    sc.Input[8].Name="VWAP Chart";
    sc.Input[8].SetChartNumber(1);
    sc.DrawZeros = 0;
    sc.FreeDLL = 0;
    return;
  }

  if(sc.Subgraph[9][1] == sc.BaseDateTimeIn[sc.ArraySize-1].GetTime()
   && sc.UpdateStartIndex != 0
   && sc.BaseDataIn[1][sc.ArraySize-1] <
     (sc.Subgraph[1][sc.ArraySize-1] - sc.Input[4].FloatValue)
   && sc.BaseDataIn[2][sc.ArraySize-1] >
     (sc.Subgraph[2][sc.ArraySize-1] + sc.Input[4].FloatValue))
    return;
  sc.Subgraph[9][1] = sc.BaseDateTimeIn[sc.ArraySize-1].GetTime();

  int& updown = sc.GetPersistentInt(9);
  float& Color = sc.GetPersistentFloat(9);
  float& cosmetic_offset = sc.Input[4].FloatValue;
  unsigned int& UpColor = sc.Subgraph[0].PrimaryColor;
  unsigned int& DnColor = sc.Subgraph[1].PrimaryColor;
  unsigned int& sUpColor = sc.Subgraph[2].PrimaryColor;
  unsigned int& sDnColor = sc.Subgraph[3].PrimaryColor;

  int pos, i;
  int h0, m, m0;
  float& offset = sc.Input[3].FloatValue;
  float &timeh = sc.Input[1].FloatValue;

  float& High = sc.GetPersistentFloat(1);
  float& Low = sc.GetPersistentFloat(2);
  float& pHigh = sc.GetPersistentFloat(5);
  float& pLow = sc.GetPersistentFloat(6);
  float& highestlow = sc.GetPersistentFloat(3);
  float& lowesthigh = sc.GetPersistentFloat(4);
  int& startbar = sc.GetPersistentInt(1);
  int& bar = sc.GetPersistentInt(2);
  int& showvwap = sc.GetPersistentInt(3);

  float& sHigh = sc.GetPersistentFloat(11);
  float& sLow = sc.GetPersistentFloat(12);
  float& times = sc.Input[2].FloatValue;
  float& tPerBar = sc.GetPersistentFloat(13);

  int vwapchart = sc.Input[8].GetChartNumber();
  int vwap = sc.Input[8].GetStudyID();

  if (sc.UpdateStartIndex == 0) {
    highestlow = 0.0;
    lowesthigh = 999999.9;
    updown = 1;
    startbar = 0;
    tPerBar = sc.SecondsPerBar/60.0;
    if(showvwap == 3) showvwap = 0; else showvwap +=1;
  }
  else startbar = min(bar, sc.ArraySize);

  SCFloatArray v1, v1h, v1l, v2, v2h, v2l;
  int vwcht = sc.Input[8].GetChartNumber();
  
  if(showvwap > 1) {
    sc.GetStudyArrayFromChart(vwcht, 1, 1, v1);
    sc.GetStudyArrayFromChart(vwcht, 1, 2, v1h);
    sc.GetStudyArrayFromChart(vwcht, 1, 3, v1l);
    sc.GetStudyArrayFromChart(vwcht, 2, 1, v2);
    sc.GetStudyArrayFromChart(vwcht, 2, 2, v2h);
    sc.GetStudyArrayFromChart(vwcht, 2, 3, v2l);
  }


  for (pos = startbar ; pos < sc.ArraySize; pos++)
  {
    sc.Subgraph[7][pos] = 0;
    sc.Subgraph[8][pos] = 0;

    if(showvwap != 0 && v1.GetArraySize() != 0 && ((pos == sc.ArraySize - 1) ||
     (sc.BaseDateTimeIn[pos+1].GetDate() == sc.BaseDateTimeIn[pos].GetDate() &&
     sc.BaseDateTimeIn[pos+1].GetTime() != sc.SessionStartTime()))) {
      sc.Subgraph[20][pos] = v1[pos];
      sc.Subgraph[21][pos] = v1h[pos];
      sc.Subgraph[22][pos] = v1l[pos];
      sc.Subgraph[23][pos] = v2[pos];
      sc.Subgraph[24][pos] = v2h[pos];
      sc.Subgraph[25][pos] = v2l[pos];
    }
    int p = pos - 1;
    High = sc.Subgraph[10][p];
    Low = sc.Subgraph[11][p];
    lowesthigh = sc.Subgraph[12][p];
    highestlow = sc.Subgraph[13][p];
  
    TIME_TO_HMS(sc.BaseDateTimeIn[pos].GetTime(),h0,m0,m);
    float time_now = float(h0*60.0 + m0);
    //sc.Subgraph[7][pos] = time_now;
    //sc.Subgraph[8][pos] = fmod(time_now, timeh);

    if( fmod(time_now, timeh) == 0 )
    {
      bar = pos;
      pHigh = High;
      pLow = Low;
      High = 0; Low = 99999;
      for(i = 0; i < timeh/tPerBar && (pos+i)<sc.ArraySize; i++)
      {
        if(sc.BaseDataIn[1][pos+i] > High)
          High = sc.BaseDataIn[1][pos+i];
        if(sc.BaseDataIn[2][pos+i] < Low)
          Low = sc.BaseDataIn[2][pos+i];
      }
      if(updown == 1)
        {if(Low > highestlow) highestlow = Low;}
      else
        if(High < lowesthigh) lowesthigh = High;
      if(High > lowesthigh+offset
       && Low >= pLow) {
        updown = 1;
        highestlow = Low;
        lowesthigh = High;
      }
      else
      if(Low<highestlow-offset
       && High <= pHigh) {
        updown = -1;
        lowesthigh = High;
        highestlow = Low;
      }
    }

    sc.Subgraph[6][pos] = updown; //fmod(float(m0),5);
    if(updown == 1) {
      sc.Subgraph[0].DataColor[pos] = UpColor;
      sc.Subgraph[2].DataColor[pos] = sUpColor;
    }
    else if(updown == -1) {
      sc.Subgraph[0].DataColor[pos] = DnColor;
      sc.Subgraph[2].DataColor[pos] = sDnColor;
    }

    sc.Subgraph[0][pos] = High+cosmetic_offset;
    sc.Subgraph[1][pos] = Low-cosmetic_offset;
    if(timeh == times || times == 0) return;
    if(fmod(time_now, times) == 0)
    {
      sHigh = 0; sLow = 99999;
      for(i = 0; i < times/tPerBar && (pos+i)<sc.ArraySize; i++)
      {
        if(sc.BaseDataIn[1][pos+i] > sHigh)
          sHigh = sc.BaseDataIn[1][pos+i];
        if(sc.BaseDataIn[2][pos+i] < sLow)
          sLow = sc.BaseDataIn[2][pos+i];
      }
    }

    sc.Subgraph[2][pos] = sHigh+cosmetic_offset;
    sc.Subgraph[3][pos] = sLow-cosmetic_offset;
    sc.Subgraph[10][pos] = High;
    sc.Subgraph[11][pos] = Low;
    sc.Subgraph[12][pos] = lowesthigh;
    sc.Subgraph[13][pos] = highestlow;
    if(showvwap == 0 || showvwap == 3) {
      sc.Subgraph[0][pos] = sc.Subgraph[1][pos] = 0;
      sc.Subgraph[2][pos] = sc.Subgraph[3][pos] = 0;
    }
  }
}