Login Page - Create Account

Support Board


Date/Time: Sat, 07 Jun 2025 19:57:15 +0000



Looking for Volatility Profit Indicator CPP File

View Count: 486

[2023-02-17 03:26:10]
TriStar Trading - Posts: 156
Does anyone know where I could find the CPP file for the user contributed study Volatility Profit Indicator? Thanks!
[2023-02-17 14:35:55]
User90125 - Posts: 715
Go here to find it:

https://www.sierrachart.com/AdditionalFiles/UserContributedACS_SourceCode/UserContributedStudies.cpp

Or just use the code posted below:

/***********************************************************************/

/*
Volatility Profit Indicator (VPI)
Author: jsyd
Date: 05/04/2011
*/

SCSFExport scsf_VPI(SCStudyGraphRef sc)
{
  SCSubgraphRef uBandSubgraph = sc.Subgraph[0];
  SCSubgraphRef mBandSubgraph = sc.Subgraph[1];
  SCSubgraphRef lBandSubgraph = sc.Subgraph[2];
  SCSubgraphRef atrSubgraph = sc.Subgraph[3];
  SCSubgraphRef uMaSubgraph = sc.Subgraph[4];
  SCSubgraphRef lMaSubgraph = sc.Subgraph[5];
  
  SCInputRef maTypeInput = sc.Input[0];
  SCInputRef ulPeriodInput = sc.Input[1];
  SCInputRef mPeriodInput = sc.Input[2];
  SCInputRef atrPeriodInput = sc.Input[3];
  SCInputRef atrMultiInput = sc.Input[4];
  
  if(sc.SetDefaults)
  {
    sc.GraphName="Volatility Profit Indicator";
    sc.StudyDescription="OverBought/OverSold based on ATR";
    
    uBandSubgraph.Name = "Upper Band";
    uBandSubgraph.DrawStyle = DRAWSTYLE_LINE;
    uBandSubgraph.PrimaryColor = RGB(255, 128, 0);
    uBandSubgraph.LineWidth = 2;
    
    mBandSubgraph.Name = "Middle Band (Moving Average)";
    mBandSubgraph.DrawStyle = DRAWSTYLE_LINE;
    mBandSubgraph.PrimaryColor = RGB(255, 255, 255);
    mBandSubgraph.LineWidth = 1;
    
    lBandSubgraph.Name = "Lower Band";
    lBandSubgraph.DrawStyle = DRAWSTYLE_LINE;
    lBandSubgraph.PrimaryColor = RGB(255, 128, 0);
    lBandSubgraph.LineWidth = 2;
    
    atrSubgraph.Name = "ATR";
    atrSubgraph.DrawStyle = DRAWSTYLE_HIDDEN;
    
    uMaSubgraph.Name = "Upper MA";
    uMaSubgraph.DrawStyle = DRAWSTYLE_HIDDEN;
    
    lMaSubgraph.Name = "Lower MA";
    lMaSubgraph.DrawStyle = DRAWSTYLE_HIDDEN;
    
    // Inputs
    maTypeInput.Name = "Moving Average Type";
    maTypeInput.SetMovAvgType(MOVAVGTYPE_EXPONENTIAL);  
    
    ulPeriodInput.Name = "Upper/Lower Band Period";
    ulPeriodInput.SetInt(13);
    ulPeriodInput.SetIntLimits(1, 10000);  
    
    mPeriodInput.Name = "Middle Band Period";
    mPeriodInput.SetInt(20);
    mPeriodInput.SetIntLimits(1, 10000);    
    
    atrPeriodInput.Name = "ATR Period";
    atrPeriodInput.SetInt(20);
    atrPeriodInput.SetIntLimits(1, 10000);  
    
    atrMultiInput.Name = "ATR Multiplier";
    atrMultiInput.SetFloat(2);
    
    sc.DrawZeros = false;
sc.AutoLoop = 1;
    sc.FreeDLL = 0;
    sc.GraphRegion = 0;
    sc.ScaleRangeType=SCALE_SAMEASREGION;

    return;
  }
  
  int cur = sc.Index;
  /*
  VPI High Band = MA(HI, type, x) + y * ATR(z)
  VPI Low Band = MA(LO, type, x) - y * ATR(z)
  where...
    type = MA Type (default to Exponential)
    x = MA Period (default to 13)
    y = True Range Multiplier (default to 2)
    z = True Range Period (default to 20)
  */
  /*===========================================================
  ATR
  ===========================================================*/
  sc.ATR(sc.BaseDataIn, atrSubgraph, atrPeriodInput.GetInt(), MOVAVGTYPE_SIMPLE);
  
  sc.MovingAverage(sc.BaseDataIn[SC_HIGH], uMaSubgraph, maTypeInput.GetMovAvgType() , cur, ulPeriodInput.GetInt());
  sc.MovingAverage(sc.BaseDataIn[SC_LAST], mBandSubgraph, maTypeInput.GetMovAvgType() , cur, mPeriodInput.GetInt());
  sc.MovingAverage(sc.BaseDataIn[SC_LOW], lMaSubgraph, maTypeInput.GetMovAvgType() , cur, ulPeriodInput.GetInt());
  
  uBandSubgraph[cur] = uMaSubgraph[cur] + (atrMultiInput.GetFloat() * atrSubgraph[cur]);
  lBandSubgraph[cur] = lMaSubgraph[cur] - (atrMultiInput.GetFloat() * atrSubgraph[cur]);
}


/***********************************************************************/

Hope this helps :)
[2023-02-17 18:18:44]
TriStar Trading - Posts: 156
Hey thanks tons! Mike

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

Login

Login Page - Create Account