Support Board
Date/Time: Sun, 24 Nov 2024 05:59:04 +0000
[Programming Help] - Stacked imbalance at a divergent delta bar
View Count: 192
[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 } } } |
[2024-06-27 12:25:15] |
emmanuel - Posts: 57 |
What is the problem? Note: `sc.Close[sc.Index]` is actually the current/last price of the bar because the current bar (sc.Index) is technically not closed. In other words, it's the "close" at that moment in time, before the bar has actually close. |
To post a message in this thread, you need to log in with your Sierra Chart account: