Support Board
Date/Time: Sun, 24 Nov 2024 05:34:00 +0000
Post From: Stacked imbalance at a divergent delta bar
[2024-06-27 05:00:13] |
User488241 - Posts: 34 |
Hello, I understand this is outside of official support. If anyone who has coding experience could chime in. I am trying to write a custom study that tracks stacked imbalance at a bar that also have negative delta but price closing higher that its open. Thank you! #include "sierrachart.h" SCSFExport scsf_StackedImbalancesWithVAP(SCStudyInterfaceRef sc) { if (sc.SetDefaults) { sc.GraphName = "Stacked Imbalances with VAP"; sc.StudyDescription = "Detects stacked imbalances using volume at price data."; sc.AutoLoop = 1; // Set to 1 for auto looping // Input parameters sc.Input[0].Name = "Minimum Imbalance Percentage"; sc.Input[0].SetFloat(400.0f); // Default value sc.Input[1].Name = "Minimum Delta"; sc.Input[1].SetFloat(-100.0f); // Default value return; } // Define variables float minImbalancePercentage = sc.Input[0].GetFloat(); float minDelta = sc.Input[1].GetFloat(); float bidVolume = 0.0f; float askVolume = 0.0f; float delta = 0.0f; unsigned int totalVolume = 0; // Calculate bid and ask volumes using Volume At Price data int VAPSizeAtBarIndex = sc.VolumeAtPriceForBars->GetSizeAtBarIndex(sc.Index); for (int VAPIndex = 0; VAPIndex < VAPSizeAtBarIndex; VAPIndex++) { const s_VolumeAtPriceV2 *p_VolumeAtPrice = NULL; if (!sc.VolumeAtPriceForBars->GetVAPElementAtIndex(sc.Index, VAPIndex, &p_VolumeAtPrice)) break; float price = p_VolumeAtPrice->PriceInTicks * sc.TickSize; if (price < sc.Close[sc.Index]) bidVolume += p_VolumeAtPrice->Volume; else askVolume += p_VolumeAtPrice->Volume; totalVolume += p_VolumeAtPrice->Volume; } // Calculate delta delta = bidVolume - askVolume; // Check conditions if (bidVolume > 0 && askVolume > 0 && (askVolume / bidVolume) >= (minImbalancePercentage / 100.0f)) { if (delta < minDelta && sc.Close[sc.Index] > sc.Open[sc.Index]) { sc.AddMessageToLog("Stacked imbalances detected with negative delta and higher close.", 1); // Implement your action here, e.g., plot a marker or take some action } } } |