Login Page - Create Account

Support Board


Date/Time: Thu, 25 Apr 2024 20:40:35 +0000



Hint needed to code study involving volume at price

View Count: 1296

[2015-07-24 17:36:20]
User911705 - Posts: 89
Hello, I've already made a couple inquiries to listed 3rd party Sierra developers and neither has even responded to an initial email:(

So, I'm going to try and figure out how to do this myself, but given the slim to nil documentation for sc.VolumeAtPriceForBars I don't have much to work from. I am a novice C++ programmer and have studied the related header file and the two sample pieces of code. This left my head swimming, LOL.

I want to create a study which will need to calculate the vpoc of the most recent 'n' bars, for every bar. I suspect I need to use some sort of array to hold all the prices from high to low of the most recent 'n' bars, but not sure if that's the only way to approach the problem. Might there be a way to do this with just using Sierra ACSIL commands, or am I going to need to create my own new data structure (hopefully that's the correct terminology).

Any hints or suggestions to point me in the correct direction would be most appreciated.
[2015-07-25 10:34:16]
Sierra Chart Engineering - Posts: 104368
I suspect I need to use some sort of array to hold all the prices from high to low of the most recent 'n' bars,
Yes, you will need this. This is how Sierra Chart does this. Probably will want to use something like an STL vector and perform a full recalculation of this at every chart update or at least at every new bar.
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
Date Time Of Last Edit: 2015-07-25 10:34:59
[2015-07-29 21:53:39]
norvik_ - Posts: 106
#include "C:\SierraChart\ACS_Source\sierrachart.h"

SCDLLName("PointOfControlPriceOfBar")

const int free_dll = 1;

SCSFExport scsf_VolumeAtPrice(SCStudyInterfaceRef sc)
{

  SCSubgraphRef POCPrice = sc.Subgraph[0];
  SCSubgraphRef temp_POCPrice = sc.Subgraph[1];
  SCSubgraphRef POCVolume = sc.Subgraph[2];
  
  SCInputRef maLength = sc.Input[0];
   SCInputRef UseMA = sc.Input[2];
   SCInputRef Type = sc.Input[3];
   SCInputRef FastSmoothConstant = sc.Input[4];
   SCInputRef SlowSmoothConstant = sc.Input[5];
  
  if (sc.SetDefaults)
{

    
         sc.AutoLoop = 1; // true
         sc.GraphRegion = 0;
         sc.FreeDLL = free_dll;

sc.StudyDescription = "This study indicate Price Of POC Of Bar.";

sc.AutoLoop = 1;

FastSmoothConstant.Name = "FastSmoothConstant";
       FastSmoothConstant.SetFloat(2.0);
      
       SlowSmoothConstant.Name = "SlowSmoothConstant";
       SlowSmoothConstant.SetFloat(7.0);
      
       maLength.Name = "MovAvg Length";
       maLength.SetInt(3);
       maLength.SetIntLimits(1,100);
      
       Type.Name = "Type";
       Type.SetMovAvgType(MOVAVGTYPE_SIMPLE_SKIP_ZEROS);


sc.MaintainVolumeAtPriceData = 1; // true

UseMA.Name = "Using Simple MA Or Adaptive ";
          UseMA.SetCustomInputStrings("Not Use;Use Simple MA;Use MA Adaptive");
          UseMA.SetCustomInputIndex(0);
          UseMA.SetIntLimits(0,2);
      

POCPrice.Name = "POC Volume";
        POCPrice.DrawStyle = DRAWSTYLE_LINE;      
POCPrice.LineWidth = 2;
POCPrice.PrimaryColor = RGB(0,255,255);
return;
}

     
       if ((int)sc.VolumeAtPriceForBars->GetNumberOfBars() < sc.ArraySize)
     return;
       unsigned int VolumeAtPriceLevel = 0;
     unsigned int pVolume   = 0;
       
       float Price = 0.0;
       float pocPrice = 0.0;
     
s_VolumeAtPriceV2 *p_VolumeAtPriceAtIndex;
int Count = sc.VolumeAtPriceForBars-> GetSizeAtBarIndex(sc.Index);
for (int ElementIndex = 0;ElementIndex < Count; ElementIndex ++)
{
sc.VolumeAtPriceForBars->GetVAPElementAtIndex(sc.Index, ElementIndex, &p_VolumeAtPriceAtIndex);

if (p_VolumeAtPriceAtIndex)
       {
   VolumeAtPriceLevel = p_VolumeAtPriceAtIndex->Volume;
        Price = p_VolumeAtPriceAtIndex->PriceInTicks * sc.TickSize;
       }
   if (VolumeAtPriceLevel > pVolume)
       {
         pVolume = VolumeAtPriceLevel;
         pocPrice = Price;
       }
}
  
  
  temp_POCPrice[sc.Index] = pocPrice;
  
  switch(UseMA.IntValue)
   {
     case 0:POCPrice[sc.Index] = temp_POCPrice[sc.Index];break;
     case 1:sc.MovingAverage(temp_POCPrice, POCPrice , Type.GetMovAvgType(), maLength.GetInt());break;
    case 2:sc.AdaptiveMovAvg(temp_POCPrice, POCPrice, maLength.GetInt(),FastSmoothConstant.GetFloat(),SlowSmoothConstant.GetFloat());break;
   }  
  
  POCVolume[sc.Index] = pVolume;    

}

I code it several years ago, may be it help.
[2015-07-30 00:04:49]
User911705 - Posts: 89
Thank you Norvik, I appreciate your sharing this.

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

Login

Login Page - Create Account