Support Board
Date/Time: Tue, 26 Aug 2025 10:32:41 +0000
Post From: Build advance custom study indicator
[2025-07-21 17:04:38] |
User203340 - Posts: 15 |
Here is the code of the indicator #include "sierrachart.h" SCDLLName("Cum Delta Histogram") // ─── Input indices ─────────────────────────────────────────── const int IDX_MODE = 0; // 0 = Trades, 1 = BidAsk const int IDX_PLOTTYPE = 1; // 0 = Histogram, 1 = Line const int IDX_POSCOLOR = 2; const int IDX_NEGCOLOR = 3; const int IDX_ZEROCOLOR = 4; // ─── Study Function ────────────────────────────────────────── SCSFExport scsf_CumDeltaHistogram(SCStudyInterfaceRef sc) { if (sc.SetDefaults) { sc.GraphName = "Cumulative Delta Histogram"; sc.GraphRegion = 1; // own sub‑pane sc.AutoLoop = 1; /* Inputs */ sc.Input[IDX_MODE].Name = "Delta Source"; sc.Input[IDX_MODE].SetCustomInputStrings("Trades;BidAsk"); sc.Input[IDX_MODE].SetInt(1); // default BidAsk sc.Input[IDX_PLOTTYPE].Name = "Plot Style"; sc.Input[IDX_PLOTTYPE].SetCustomInputStrings("Histogram;Line"); sc.Input[IDX_PLOTTYPE].SetInt(0); // default Histogram sc.Input[IDX_POSCOLOR].Name = "Positive Color"; sc.Input[IDX_POSCOLOR].SetColor(RGB(0,200,0)); sc.Input[IDX_NEGCOLOR].Name = "Negative Color"; sc.Input[IDX_NEGCOLOR].SetColor(RGB(220,0,0)); sc.Input[IDX_ZEROCOLOR].Name = "Zero‑line Color"; sc.Input[IDX_ZEROCOLOR].SetColor(RGB(160,160,160)); /* Subgraphs */ sc.Subgraph[0].Name = "CumDelta"; sc.Subgraph[0].DrawStyle = DRAWSTYLE_BAR; sc.Subgraph[1].Name = "Zero"; sc.Subgraph[1].DrawStyle = DRAWSTYLE_LINE; sc.Subgraph[1].PrimaryColor= sc.Input[IDX_ZEROCOLOR].GetColor(); return; } /* Style switch: bar or line */ sc.Subgraph[0].DrawStyle = (sc.Input[IDX_PLOTTYPE].GetInt() == 0 ? DRAWSTYLE_BAR : DRAWSTYLE_LINE); /* Per‑bar delta */ double barDelta; if (sc.Input[IDX_MODE].GetInt() == 0) // Trades up/down tick barDelta = sc.Volume[sc.Index] * (sc.Close[sc.Index] > sc.Open[sc.Index] ? 1.0 : -1.0); else // Bid‑Ask aggressive volume barDelta = sc.AskVolume[sc.Index] - sc.BidVolume[sc.Index]; /* Cumulative sum */ double cum = (sc.Index == 0 ? barDelta : sc.Subgraph[0][sc.Index - 1] + barDelta); sc.Subgraph[0][sc.Index] = cum; /* Colour */ COLORREF posCol = sc.Input[IDX_POSCOLOR].GetColor(); COLORREF negCol = sc.Input[IDX_NEGCOLOR].GetColor(); sc.Subgraph[0].DataColor[sc.Index] = (cum >= 0 ? posCol : negCol); /* Zero line */ sc.Subgraph[1][sc.Index] = 0; } |