Login Page - Create Account

Support Board


Date/Time: Fri, 07 Feb 2025 07:46:42 +0000



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

[2020-04-19 15:42:55]
Giovanni II - Posts: 25
Hi,
I wrote this simple program in order to have at each price level of the current candle the respective volume.

#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.GraphRegion = 0;
    sc.ValueFormat = 0;
    sc.DrawZeros = 1;
    sc.AutoLoop = 1;
    sc.MaintainVolumeAtPriceData = 1;
    sc.HideDLLAndFunctionNames = 1;    
    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);
}  
}

I tested it this Sunday, in replay, but it doesn't work: it always gives me zero value for the volume. I don't think there are any mistakes ..

Chart: Replay 1.00X: MESM20_FUT_CME [C][M] 10 Min #7 | Study: Info Volume Bar | Candela: 2845, Posizione: 30, Prezzo: 2837.500000, Volume: 0 | 2020-04-19 17:27:15.714
Chart: Replay 1.00X: MESM20_FUT_CME [C][M] 10 Min #7 | Study: Info Volume Bar | Candela: 2845, Posizione: 31, Prezzo: 2837.750000, Volume: 0 | 2020-04-19 17:27:15.714
Chart: Replay 1.00X: MESM20_FUT_CME [C][M] 10 Min #7 | Study: Info Volume Bar | Candela: 2845, Posizione: 32, Prezzo: 2838.000000, Volume: 0 | 2020-04-19 17:27:15.714
Chart: Replay 1.00X: MESM20_FUT_CME [C][M] 10 Min #7 | Study: Info Volume Bar | Candela: 2845, Posizione: 33, Prezzo: 2838.250000, Volume: 0 | 2020-04-19 17:27:15.714
Chart: Replay 1.00X: MESM20_FUT_CME [C][M] 10 Min #7 | Study: Info Volume Bar | Candela: 2845, Posizione: 34, Prezzo: 2838.500000, Volume: 0 | 2020-04-19 17:27:15.714
Chart: Replay 1.00X: MESM20_FUT_CME [C][M] 10 Min #7 | Study: Info Volume Bar | Candela: 2845, Posizione: 35, Prezzo: 2838.750000, Volume: 0 | 2020-04-19 17:27:15.714
Chart: Replay 1.00X: MESM20_FUT_CME [C][M] 10 Min #7 | Study: Info Volume Bar | Candela: 2845, Posizione: 36, Prezzo: 2839.000000, Volume: 0 | 2020-04-19 17:27:15.714
Chart: Replay 1.00X: MESM20_FUT_CME [C][M] 10 Min #7 | Study: Info Volume Bar | Candela: 2845, Posizione: 37, Prezzo: 2839.250000, Volume: 0 | 2020-04-19 17:27:15.714
Chart: Replay 1.00X: MESM20_FUT_CME [C][M] 10 Min #7 | Study: Info Volume Bar | Candela: 2845, Posizione: 38, Prezzo: 2839.500000, Volume: 0 | 2020-04-19 17:27:15.714
Chart: Replay 1.00X: MESM20_FUT_CME [C][M] 10 Min #7 | Study: Info Volume Bar | Candela: 2845, Posizione: 39, Prezzo: 2839.750000, Volume: 0 | 2020-04-19 17:27:15.714
Chart: Replay 1.00X: MESM20_FUT_CME [C][M] 10 Min #7 | Study: Info Volume Bar | Candela: 2846, Posizione: 0, Prezzo: 2838.250000, Volume: 0 | 2020-04-19 17:27:15.714
Chart: Paused 1.00X: MESM20_FUT_CME [C][M] 10 Min #7 | Study: Info Volume Bar | Candela: 2846, Posizione: 0, Prezzo: 2838.250000, Volume: 0 | 2020-04-19 17:27:15.715

However, a doubt came to me.. since sc.VolumeAtPriceForBars-> GetSizeAtBarIndex (sc.Index);
returns the volume for each price level of the candle but without considering the price, simply following an increasing order, from the lowest price to the highest, if in the candle there is a price gap I believe that it is no longer possible to associate the right value of the volume to the right price, so the logic of my program in this case, if a gap occurs, is wrong ..

Let me know..
Thank's