Login Page - Create Account

Support Board


Date/Time: Sun, 11 May 2025 22:59:36 +0000



Anyone know math behind Woodies CCI Trend study?

View Count: 1692

[2016-05-17 15:50:53]
User14953 - Posts: 252
Is the math available behind the "Woodies CCI Trend" study?
[2016-05-17 17:02:14]
Sierra Chart Engineering - Posts: 104368
Here is the source code for it. We can tell it was not written by us.


SCSFExport scsf_WoodieCCITrend2(SCStudyInterfaceRef sc)
{
  SCSubgraphRef CCI = sc.Subgraph[0];
  SCSubgraphRef TrendDown = sc.Subgraph[1];
  SCSubgraphRef TrendNeutral = sc.Subgraph[2];
  SCSubgraphRef TrendUp = sc.Subgraph[3];
  SCSubgraphRef HiLevel = sc.Subgraph[4];
  SCSubgraphRef LowLevel = sc.Subgraph[5];
  SCSubgraphRef Consecutive = sc.Subgraph[6];
  SCSubgraphRef LastTrend = sc.Subgraph[7];
  SCSubgraphRef WorksheetOutput = sc.Subgraph[8];
  SCSubgraphRef ZLR = sc.Subgraph[9];

  SCInputRef NumberOfBars = sc.Input[0];
  SCInputRef NeutralBars = sc.Input[1];
  SCInputRef CCILength = sc.Input[2];
  SCInputRef Level = sc.Input[3];
  SCInputRef CCIInputData = sc.Input[4];
  SCInputRef Version = sc.Input[5];

if(sc.SetDefaults)
{
sc.GraphName="Woodies CCI Trend";

sc.AutoLoop = 1;

TrendDown.Name = "TrendDown";
TrendDown.DrawStyle = DRAWSTYLE_BAR;
TrendDown.PrimaryColor = RGB(255,0,0);
    TrendDown.DrawZeros = false;

    TrendNeutral.Name = "TrendNeutral";
TrendNeutral.PrimaryColor = RGB(255,255,0);
TrendNeutral.DrawStyle = DRAWSTYLE_BAR;
    TrendNeutral.DrawZeros = false;

TrendUp.Name = "TrendUp";
    TrendUp.DrawStyle = DRAWSTYLE_BAR;
TrendUp.PrimaryColor = RGB(0,0,255);
    TrendUp.DrawZeros = false;

    HiLevel.Name = "Hi Level";
    HiLevel.DrawStyle = DRAWSTYLE_LINE;
HiLevel.PrimaryColor = RGB(0,255,0);
    HiLevel.DrawZeros = false;

    LowLevel.Name = "Low Level";
    LowLevel.DrawStyle = DRAWSTYLE_LINE;
LowLevel.PrimaryColor = RGB(0,255,0);
LowLevel.DrawZeros = false;

CCI.Name = "CCI";
CCI.DrawStyle = DRAWSTYLE_BAR;
    CCI.PrimaryColor = RGB(98,98,98);
    CCI.DrawZeros = false;

    Consecutive.DrawStyle = DRAWSTYLE_IGNORE;
    Consecutive.DrawZeros = false;

    LastTrend.DrawStyle = DRAWSTYLE_IGNORE;
    LastTrend.DrawZeros = false;

    WorksheetOutput.Name = "Spreadsheet Ouput";
    WorksheetOutput.DrawStyle = DRAWSTYLE_IGNORE;
    WorksheetOutput.PrimaryColor = RGB(0,127,255);
    WorksheetOutput.DrawZeros = false;

    ZLR.Name = "ZLR Output";
    ZLR.DrawStyle = DRAWSTYLE_POINT;
    ZLR.PrimaryColor = RGB(255,0,0);
    ZLR.SecondaryColor = RGB(0,255,0);
    ZLR.SecondaryColorUsed = 1;
    ZLR.LineWidth = 3;
    ZLR.DrawZeros = false;

   CCILength.Name = "CCI Length";
CCILength.SetInt(14);
CCILength.SetIntLimits(1,MAX_STUDY_LENGTH);

NumberOfBars.Name = "Number of Bars";
NumberOfBars.SetInt(6);
NumberOfBars.SetIntLimits(1,MAX_STUDY_LENGTH);
    
    NeutralBars.Name = "Number of Neutral Bars";
NeutralBars.SetInt(5);
NeutralBars.SetIntLimits(1,MAX_STUDY_LENGTH);

Level.Name = "Level";
Level.SetInt(100);
Level.SetIntLimits(1,MAX_STUDY_LENGTH);

    CCIInputData.Name = "Input Data";
    CCIInputData.SetInputDataIndex(SC_HLC);
    
    Version.SetInt(1);
    
return;
}


  
  
  //Current number of consecutive conditions CCI > 0 (or CCI < 0 if variable less zero)
  float& consec = Consecutive[sc.Index];
  const float& PrevConsec = Consecutive[sc.Index-1];
  
  float& currTrend= LastTrend[sc.Index]; // -1 - TrendDown; 1 - TrendUp
  float& lastTrend= LastTrend[sc.Index-1];

  const float& currCCI = CCI[sc.Index];
  int OccurGreatEdge=0;
  int OccurLessEdge=0;

  HiLevel[sc.Index] = (float)Level.GetInt();
  LowLevel[sc.Index] = (float)-Level.GetInt();

  sc.DataStartIndex= CCILength.GetInt()-1;

  sc.CCI(sc.BaseData[CCIInputData.GetInputDataIndex()], CCI, CCILength.GetInt(), 0.015f);
  
  if(sc.Index == 0)
  {  
    if(CCI[sc.Index] > 0)
      consec = 1;
    else if(CCI[sc.Index] < 0)
      consec = -1;
    else
      consec = 0;
  }
  else
  {
    if(currCCI > 0)
    {
      if(PrevConsec < 0)
        consec = 1;
      else
        consec = PrevConsec + 1;
    }
    else if(currCCI < 0)
    {
      if(PrevConsec > 0)
        consec = -1;
      else
        consec = PrevConsec - 1;
    }
  }
  
  for(int i = sc.Index; i>sc.Index-NumberOfBars.GetInt(); i--)
  {
    if(CCI[i] > Level.GetInt())
      OccurGreatEdge++;
    else if(CCI[i] < -Level.GetInt())
      OccurLessEdge++;
  }

  bool trendUp = (currCCI > 0) && ((lastTrend == 1) || ((consec >= NumberOfBars.GetInt()) && (OccurGreatEdge > 0)));
  bool trendDown = (currCCI < 0) && ((lastTrend == -1) || ((consec <= -NumberOfBars.GetInt() ) && (OccurLessEdge > 0)));

  //Zero out subgraphs that color the main subgraph. This needs to be done in case one of these conditions is no longer met when a bar is forming.
  TrendUp[sc.Index] = 0;
  TrendDown[sc.Index] = 0;
  TrendNeutral[sc.Index] = 0;
  WorksheetOutput[sc.Index] = 0;

  if(trendUp)
  {
    TrendUp[sc.Index] = currCCI;//trend up
    currTrend = 1;
    WorksheetOutput[sc.Index] = 3;
  }
  else if(trendDown)
  {
    TrendDown[sc.Index] = currCCI;//trend down
    currTrend = -1;
    WorksheetOutput[sc.Index] = 1;
  }
  else
  {  
    currTrend = lastTrend;  
    if( (consec >= NeutralBars.GetInt() && !trendUp) || ( -consec >= NeutralBars.GetInt() && !trendDown) )
      TrendNeutral[sc.Index] = currCCI;//trend neutral
    WorksheetOutput[sc.Index] = 2;
  }

  //Calculate the ZLR
  SCFloatArrayRef ZLRHooks = ZLR.Arrays[0]; // First extra array of ZLR subgraph

  if ((CCI[sc.Index-1] > CCI[sc.Index-2] && CCI[sc.Index] < CCI[sc.Index-1])
    || (ZLRHooks[sc.Index-1] < 0 && CCI[sc.Index] <= CCI[sc.Index-1])
    )
  {
    ZLRHooks[sc.Index] = -1;
    if (ZLRHooks [sc.Index] <0 && CCI [sc.Index] <0)
    {
      ZLR[sc.Index] = -200;
      ZLR.DataColor[sc.Index] = ZLR.PrimaryColor;
    }
    else
      ZLR [sc.Index] = 0;

  }
  else if ((CCI[sc.Index-1] < CCI[sc.Index-2] && CCI[sc.Index] > CCI[sc.Index-1])
    || (ZLRHooks[sc.Index-1] > 0 && CCI[sc.Index] >= CCI[sc.Index-1])
    )
  {
    ZLRHooks[sc.Index] = 1;
    if (ZLRHooks [sc.Index] >0 && CCI [sc.Index] >0)
    {
      ZLR[sc.Index] = 200;
      ZLR.DataColor[sc.Index] = ZLR.SecondaryColor;
    }
    else
      ZLR [sc.Index] = 0;

  }
  else
  {
    ZLR[sc.Index] = 0;
    ZLRHooks[sc.Index] = 0;
    
  }
}[/i][/i]

Sierra Chart Support - Engineering Level

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

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing

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

Login

Login Page - Create Account