Support Board
Date/Time: Tue, 06 May 2025 05:16:47 +0000
Post From: Sierra unable to Plot correctly.
[2025-01-16 11:08:59] |
User669552 - Posts: 26 |
I use a range chart with 8 price levels(7 tick). The objective is to plot a red candle if the POC is in the Upper halve of red candle and plot the the green candle if the POC is in in the lower half. Despite be a very simple study sierra chart plotting incorrectly and missing some. I believe these could be other factor other than the code. Here is the simple code. #include "sierrachart.h" // Define the name of the DLL for this custom study SCDLLName("ApexVolumeAtPriceStudy"); SCSFExport scsf_ApexVolumeAtPriceStudy(SCStudyInterfaceRef sc) { // Default settings if (sc.SetDefaults) { sc.GraphName = "Apex Volume at Price Study"; sc.StudyDescription = "Detects conditions for Green and Red Candles based on POC."; sc.AutoLoop = 0; // We will handle the loops manually sc.MaintainVolumeAtPriceData = 1; // Ensure volume at price data is maintained return; } // Get the Endidx value (Index of the bar we are analyzing) int Endidx = sc.ArraySize - 2; // We are analyzing the second-to-last bar (the last loaded bar) // Initialize variables const s_VolumeAtPriceV2* p_VAP = nullptr; int NumPriceLevels = sc.VolumeAtPriceForBars->GetSizeAtBarIndex(Endidx - 1); // Number of price levels for the bar int VolumeAtEachLevel[NumPriceLevels]; // Retrieve volume data for each price level of the bar at Endidx-1 for (int i = 0; i < NumPriceLevels; i++) { if (!sc.VolumeAtPriceForBars->GetVAPElementAtIndex(Endidx - 1, i, &p_VAP)) { break; // If there's an error, stop the loop } VolumeAtEachLevel = p_VAP->Volume; // Store the volume for this price level } // Find the POC by identifying the price level with the highest volume within the entire range (0 to 7) int POCIndex = -1; float MaxVolume = 0.0f; // Change to float // Loop through all price levels (0 to 7) to find the POC for (int i = 0; i < NumPriceLevels; i++) { if (VolumeAtEachLevel > MaxVolume) { MaxVolume = VolumeAtEachLevel; POCIndex = i; // The price level with the highest volume is the POC } } // Check if the bar is a Green Candle (Bullish) if (sc.Close[Endidx] > sc.Open[Endidx]) { // Green Candle Condition: POC must be within index 0 to 3 (lower half of the candle) if (POCIndex >= 0 && POCIndex <= 3) { // Green Candle Condition Met - POC is within 0 to 3 s_UseTool Draw; Draw.DrawingType = DRAWING_MARKER; Draw.MarkerType = MARKER_SQUARE; Draw.Color = RGB(0, 255, 0); // Green color Draw.MarkerSize = 15; Draw.BeginValue = sc.Low[Endidx] - (sc.TickSize * 2); // Offset below the bar Draw.BeginIndex = Endidx; sc.UseTool(Draw); } } // Check if the bar is a Red Candle (Bearish) if (sc.Close[Endidx] < sc.Open[Endidx]) { // Red Candle Condition: POC must be within index 4 to 7 (upper half of the candle) if (POCIndex >= 4 && POCIndex <= 7) { // Red Candle Condition Met - POC is within 4 to 7 s_UseTool Draw; Draw.DrawingType = DRAWING_MARKER; Draw.MarkerType = MARKER_SQUARE; Draw.Color = RGB(255, 0, 0); // Red color Draw.MarkerSize = 15; Draw.BeginValue = sc.High[Endidx] + (sc.TickSize * 2); // Offset above the bar Draw.BeginIndex = Endidx; sc.UseTool(Draw); } } } |