Support Board
Date/Time: Fri, 07 Feb 2025 07:49:36 +0000
[Programming Help] - [SOLVED] sc.VolumeAtPriceForBars is not working.. WORKING CODE ADDED
View Count: 1480
[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 |
[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? |
[2020-04-20 11:54:21] |
User907968 - Posts: 826 |
You already can recover the price, s_VolumeAtPriceV2 has member 'PriceInTicks', look in VAPContainer.h struct s_VolumeAtPriceV2
{ //--- Members ------------------------------------------------------------ int PriceInTicks; unsigned int Volume; unsigned int BidVolume; unsigned int AskVolume; unsigned int NumberOfTrades; }; |
[2020-04-20 12:13:16] |
GiovanniD - Posts: 41 |
well, I'll take a look at VAPContainer.h can you check if the code I wrote works by giving the volume? I downloaded the latest version of Sierrachart and it doesn't work .. |
[2020-04-20 14:20:10] |
Giovanni II - Posts: 25 |
Solved, there is a bug in the code.. Thanks |
[2020-04-21 07:43:00] |
Giovanni II - Posts: 25 |
The complete and working code with in addition the calculation of the price: #include "sierrachart.h"
SCDLLName("Info Volume Bar2") SCSFExport scsf_Info_Volume_Bar2(SCStudyGraphRef sc) { SCSubgraphRef Volume_Bar = sc.Subgraph[0]; if (sc.SetDefaults) { sc.GraphName = "Info Volume Bar2"; sc.AutoLoop = 1; sc.MaintainVolumeAtPriceData = 1; Volume_Bar.Name = "Info Volume Bar2"; Volume_Bar.DrawStyle = DRAWSTYLE_BAR; Volume_Bar.PrimaryColor = RGB(0,255,0); Volume_Bar.LineWidth = 2; return; } // Section 2 - Data processing if ((int)sc.VolumeAtPriceForBars->GetNumberOfBars() < sc.ArraySize) return; SCString Buffer; int prezzi_candela; double T_size; int& V_prec = sc.GetPersistentInt(1); int& V_posiz = sc.GetPersistentInt(2); T_size = sc.TickSize; const s_VolumeAtPriceV2 *p_VolumeAtPrice=NULL;//qui viene inserito il volume di un prezzo della candela corrente prezzi_candela = sc.VolumeAtPriceForBars->GetSizeAtBarIndex(sc.Index);//numero di prezzi con volume alla candela corrente int volume_al_prezzo[prezzi_candela][2]; V_prec = 0; V_posiz = 0; 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] = 0;//volume volume_al_prezzo[VAPIndex][1] = 0;//prezzo } else { volume_al_prezzo[VAPIndex][0] = p_VolumeAtPrice->Volume; volume_al_prezzo[VAPIndex][1] = p_VolumeAtPrice->PriceInTicks; } if(volume_al_prezzo[VAPIndex][0] > V_prec) { V_prec = volume_al_prezzo[VAPIndex][0]; V_posiz = VAPIndex; } } Buffer.Format("V_prec: %d, V_posiz: %d", V_prec, V_posiz); sc.AddMessageToLog(Buffer,0); Buffer.Format("Candela: %d, Prezzo: %f, Volume: %d", sc.Index, volume_al_prezzo[V_posiz][1]*T_size, volume_al_prezzo[V_posiz][0]); sc.AddMessageToLog(Buffer,0); } |
[2020-04-24 09:52:53] |
User766588 - Posts: 20 |
HELP VOL PROF H1 TIME FRAME. Sei italiano? Could you help me please in my sierra chart 3 versione i need to manage vol profile on H1 timeframe. With comulative vol last 30 days in right margin + pivot point only last day Every day vah-val-POC-min and max day, prev close price H1 Candle with VP based on each h1 candle As you see in annexed chart for example .Is it possible with SC 3? Could you show me an image of a complete VP setting and imputs + subgrpah in order to copy it . Thank for you cooperation umberto p |
![]() |
[2020-04-24 09:58:18] |
Giovanni II - Posts: 25 |
Si, sono italiano. Spiega bene in italiano cosa ti serve. Ciao |
[2020-04-24 10:00:20] |
Giovanni II - Posts: 25 |
Ok, ho visto ora la foto, dovrebbe essere possibile. Devo solo vedere come impostare. Ti faccio sapere nel pomeriggio/sera.
|
[2020-04-24 11:58:58] |
User766588 - Posts: 20 |
GRAZIE IO HO SC3 version !!!
|
[2020-04-26 09:43:43] |
Giovanni II - Posts: 25 |
ciao, non mi é stato possibile vedere in questi giorni, oggi vedo il vbp e ti dico
|
[2020-04-26 09:58:07] |
Giovanni II - Posts: 25 |
Se non mi sono perso qualcosa per strada, tu cerchi questo, giusto?
|
[2020-04-26 14:48:15] |
User766588 - Posts: 20 |
esattamente grazie |
[2020-04-26 16:42:22] |
Giovanni II - Posts: 25 |
Copia il file allegato in /SierraChart/Data/ lancia il programma e da File->Open ChartBook seleziona il book esporta2 Si aprirá una finestra su Micro Sp500 con il grafico impostato come in foto, da qui vedi bene quali parametri ho usato e li replichi nei tuoi ChartBook Ciao |
![]() |
[2020-04-27 12:24:06] |
User766588 - Posts: 20 |
Per ora molte grazie, provo subito. grazie |
[2020-04-27 16:26:40] |
User766588 - Posts: 20 |
FUNZIONA PERFETTO GRAZIE
|
[2020-04-30 09:28:50] |
User766588 - Posts: 20 |
Scusami Giovanni se approfitto quando avrai tempo e voglia senza nessuna fretta potresti predispormi un nuovo CharbooK/workspace per utilizzare i miei n 2 monitors, da solo proprio non riesco. Nel monitor di SX E-mini ES, con allineato al margine DX il suo book + SOTTO AL grafico n 3 diverse finestre sempre ES timeframe 1,5,day. Nel monitor n 2 a DX invece mi servirebbe E-MINI NQ con stessa set up: grafico e book allineato a DX + sotto n 3 schede sempre NQ 1,5,day.Mi saresti di grande aiuto.Nel post dove mi avevi mandato il tuo file alleghero un screenshot di come dovrebbe essere.. Grazie mille. umberto p |
Attachment Deleted. ![]() |
[2020-04-30 09:34:45] |
User766588 - Posts: 20 |
Lo salvo in sierra/chart/data poi? a presto |
[2020-05-18 11:09:46] |
User766588 - Posts: 20 |
Scusa Giovanni, dato che non so settare la piattaforma, potresti farmi consulenza a pagamento x un settaggio come serve a me.Per questo e per eventuali nuove mie necessità?Fammi sapere se eventualmente sei disponibile .grazie.umberto
|
[2020-05-20 10:22:15] |
Giovanni II - Posts: 25 |
Ciao, scusami per il ritardo, dovevo al piú presto terminare un programma sui volumi, puoi veder in foto allegata. Per quanto riguarda il tuo problema, se si stratta di configurare le finestre come mi hai chiesto su, non ci sono problemi, ti spiego come fare. Al limite ci sentiamo telefonicamente che si fa prima. |
[2020-05-24 10:49:05] |
Giovanni II - Posts: 25 |
Ok, non scrivere qui in chiaro i tuoi contatti, x tua riservatezza. Modifica il testo è cancella i tuoi dati. Li avevo comunque ricevuti in privato e venerdì ti ho inviato una mail, controlla e fammi sapere. Buona giornata |
To post a message in this thread, you need to log in with your Sierra Chart account: