Support Board
Date/Time: Sat, 05 Jul 2025 16:50:02 +0000
Post From: [SOLVED] sc.VolumeAtPriceForBars is not working.. WORKING CODE ADDED
[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); } |