Login Page - Create Account

Support Board


Date/Time: Fri, 07 Feb 2025 07:54:45 +0000



Post From: [SOLVED] sc.VolumeAtPriceForBars is not working.. WORKING CODE ADDED

[2020-04-20 10:22:38]
Giovanni II - Posts: 25
Today I tested the code in real time and it doesn't work, keep returning volume 0..
I compared the code with your examples and it seems correct to me.

I simplified it to this code:
#include "sierrachart.h"

SCDLLName("Info Volume Bar")

SCSFExport scsf_Info_Volume_Bar(SCStudyGraphRef sc)
{
  SCSubgraphRef Volume_Bar = sc.Subgraph[0];

  if (sc.SetDefaults)
  {
    sc.GraphName = "Info Volume Bar";

    sc.AutoLoop = 1;
    sc.MaintainVolumeAtPriceData = 1;
    
    Volume_Bar.Name = "Volume";
    Volume_Bar.DrawStyle = DRAWSTYLE_BAR;
    Volume_Bar.PrimaryColor = RGB(0,255,0);
    Volume_Bar.LineWidth = 2;    

    return;
  }
  // Section 2 - Data processing
  SCString Buffer;  
  
  int prezzi_candela;
  double Alto, Basso, T_size;
  
  Alto = sc.High[sc.Index];
  Basso = sc.Low[sc.Index];
  T_size = sc.TickSize;
  
  prezzi_candela = (Alto - Basso)/T_size;
  
  double volume_al_prezzo[prezzi_candela];
const s_VolumeAtPriceV2 *p_VolumeAtPrice=NULL;//qui viene inserito il volume di un prezzo della candela corrente

  //int VAPSizeAtBarIndex = sc.VolumeAtPriceForBars->GetSizeAtBarIndex(sc.Index);//numero di prezzi con volume alla candela corrente

  double prezzo_corrente;
  for (int VAPIndex = 0; VAPIndex <= prezzi_candela; VAPIndex++)//processa tutti i prezzi della candela corrente con volume (0 = prezzo piú basso)
  {
    if (!sc.VolumeAtPriceForBars->GetVAPElementAtIndex(sc.Index, VAPIndex, &p_VolumeAtPrice))
    {
      volume_al_prezzo[VAPIndex] = 0;
    }
    else
    {
      volume_al_prezzo[VAPIndex] = p_VolumeAtPrice->Volume;
    }
    
    prezzo_corrente = Basso + (VAPIndex*T_size);
    Buffer.Format("Candela: %d, Posizione: %d, Prezzo: %f, Volume: %d", sc.Index, VAPIndex, prezzo_corrente, volume_al_prezzo[VAPIndex]);
    sc.AddMessageToLog(Buffer,0);
}  
}

however, I still have doubts about the effectiveness of this logic..
you did a good job with the sc.VolumeAtPriceForBars class
Why not do an excellent job by adding the "price" method so that we can also recover the price as well as the volume?