Support Board
Date/Time: Sun, 24 Nov 2024 07:00:07 +0000
Post From: ACSIL Custom Study HELP!
[2024-10-30 09:18:17] |
User357489 - Posts: 72 |
Hey SC Engineering/ wider community Im trying to make a custom study that draws an extending rectangles around the high-low range of the candles where the following color bar based on alert conditions are met; so a buy" rectangle would be when id25.sg1=true, (id25 being my CBBOAC) and likewise for a "sell" rectangle id26.sg1=true. please see attached a screenshot where ive manually drawn on the rectangles around the range of the candles in which my alert conditions are met. to clarify, i have colored rectangles green where a candle has not closed below the low of this rectangle, indicating its still an "active" area, and blue, where price has either traded below and closed below the low, OR a new alert has occurred, painting a more updated area, thus rendering the previous idle so to speak. Likewise red for active sell area and orange for idle. at present i have the following code; which builds successfully however doesnt do as intended. i'm still a coding novice so help and corrections very much welcome and appreciated, Thanks :) #include "sierrachart.h"
SCDLLName("Highlight Buy/Sell Candle Range") SCSFExport scsf_HighlightBuySellCandleRange(SCStudyInterfaceRef sc) { // Define Subgraphs for Buy and Sell Rectangle High and Low SCSubgraphRef Subgraph_BuyRectangleHigh = sc.Subgraph[0]; SCSubgraphRef Subgraph_BuyRectangleLow = sc.Subgraph[1]; SCSubgraphRef Subgraph_SellRectangleHigh = sc.Subgraph[2]; SCSubgraphRef Subgraph_SellRectangleLow = sc.Subgraph[3]; // Inputs for customizing the rectangle's appearance and behavior SCInputRef Input_ExtendUntilIntersection = sc.Input[0]; SCInputRef Input_BuyRectangleColor = sc.Input[1]; SCInputRef Input_SellRectangleColor = sc.Input[2]; SCInputRef Input_TransparentDrawStyle = sc.Input[3]; SCInputRef Input_TransparencyLevel = sc.Input[4]; // Persistent variables to track rectangle state int& BuyRectangleLineNumber = sc.GetPersistentInt(1); int& SellRectangleLineNumber = sc.GetPersistentInt(2); if (sc.SetDefaults) { // Study settings sc.GraphName = "Highlight Buy/Sell Candle Range"; sc.AutoLoop = 0; // Manual looping through bars // Subgraph properties Subgraph_BuyRectangleHigh.Name = "Buy Rectangle High"; Subgraph_BuyRectangleHigh.DrawStyle = DRAWSTYLE_IGNORE; Subgraph_BuyRectangleLow.Name = "Buy Rectangle Low"; Subgraph_BuyRectangleLow.DrawStyle = DRAWSTYLE_IGNORE; Subgraph_SellRectangleHigh.Name = "Sell Rectangle High"; Subgraph_SellRectangleHigh.DrawStyle = DRAWSTYLE_IGNORE; Subgraph_SellRectangleLow.Name = "Sell Rectangle Low"; Subgraph_SellRectangleLow.DrawStyle = DRAWSTYLE_IGNORE; // Input properties Input_ExtendUntilIntersection.Name = "Extend Until Intersection"; Input_ExtendUntilIntersection.SetYesNo(1); // Default to extend indefinitely Input_BuyRectangleColor.Name = "Buy Rectangle Color"; Input_BuyRectangleColor.SetColor(RGB(0, 255, 0)); // Default green for buy Input_SellRectangleColor.Name = "Sell Rectangle Color"; Input_SellRectangleColor.SetColor(RGB(255, 0, 0)); // Default red for sell Input_TransparentDrawStyle.Name = "Transparent Draw Style"; Input_TransparentDrawStyle.SetYesNo(0); // Default: not transparent Input_TransparencyLevel.Name = "Transparency Level"; Input_TransparencyLevel.SetInt(50); // Default transparency level 50% Input_TransparencyLevel.SetIntLimits(0, 100); // Limits: 0% to 100% return; } // Get subgraph data from the Buy and Sell conditions studies (ID25 for Buy, ID26 for Sell) SCFloatArray ID25_SG1, ID26_SG1; sc.GetStudyArrayUsingID(25, 1, ID25_SG1); // Buy condition sc.GetStudyArrayUsingID(26, 1, ID26_SG1); // Sell condition // Buy Condition: When ID25.SG1 equals 1 if (ID25_SG1[sc.Index] == 1) { float RectangleHigh = sc.High[sc.Index]; float RectangleLow = sc.Low[sc.Index]; Subgraph_BuyRectangleHigh[sc.Index] = RectangleHigh; Subgraph_BuyRectangleLow[sc.Index] = RectangleLow; s_UseTool BuyRectangle; BuyRectangle.Clear(); BuyRectangle.ChartNumber = sc.ChartNumber; BuyRectangle.DrawingType = DRAWING_RECTANGLEHIGHLIGHT; BuyRectangle.AddMethod = UTAM_ADD_OR_ADJUST; BuyRectangle.BeginIndex = sc.Index; BuyRectangle.EndIndex = Input_ExtendUntilIntersection.GetYesNo() ? sc.ArraySize - 1 : sc.Index; BuyRectangle.BeginValue = RectangleHigh; BuyRectangle.EndValue = RectangleLow; BuyRectangle.Color = Input_BuyRectangleColor.GetColor(); BuyRectangle.LineWidth = 1; BuyRectangle.AddAsUserDrawnDrawing = 0; BuyRectangle.ExtendRight = Input_ExtendUntilIntersection.GetYesNo() ? 1 : 0; BuyRectangle.TransparentLabelBackground = Input_TransparentDrawStyle.GetYesNo(); BuyRectangle.TransparencyLevel = Input_TransparencyLevel.GetInt(); BuyRectangleLineNumber = sc.UseTool(BuyRectangle); } // Sell Condition: When ID26.SG1 equals 1 if (ID26_SG1[sc.Index] == 1) { float RectangleHigh = sc.High[sc.Index]; float RectangleLow = sc.Low[sc.Index]; Subgraph_SellRectangleHigh[sc.Index] = RectangleHigh; Subgraph_SellRectangleLow[sc.Index] = RectangleLow; s_UseTool SellRectangle; SellRectangle.Clear(); SellRectangle.ChartNumber = sc.ChartNumber; SellRectangle.DrawingType = DRAWING_RECTANGLEHIGHLIGHT; SellRectangle.AddMethod = UTAM_ADD_OR_ADJUST; SellRectangle.BeginIndex = sc.Index; SellRectangle.EndIndex = Input_ExtendUntilIntersection.GetYesNo() ? sc.ArraySize - 1 : sc.Index; SellRectangle.BeginValue = RectangleHigh; SellRectangle.EndValue = RectangleLow; SellRectangle.Color = Input_SellRectangleColor.GetColor(); SellRectangle.LineWidth = 1; SellRectangle.AddAsUserDrawnDrawing = 0; SellRectangle.ExtendRight = Input_ExtendUntilIntersection.GetYesNo() ? 1 : 0; SellRectangle.TransparentLabelBackground = Input_TransparentDrawStyle.GetYesNo(); SellRectangle.TransparencyLevel = Input_TransparencyLevel.GetInt(); SellRectangleLineNumber = sc.UseTool(SellRectangle); } // Check for intersection if "Extend Until Intersection" is enabled if (Input_ExtendUntilIntersection.GetYesNo() == 0) { // Buy Rectangle Intersection Check if (BuyRectangleLineNumber != 0 && (sc.Close[sc.Index] <= Subgraph_BuyRectangleLow[sc.Index])) { sc.DeleteACSChartDrawing(sc.ChartNumber, DRAWING_RECTANGLEHIGHLIGHT, BuyRectangleLineNumber); BuyRectangleLineNumber = 0; } // Sell Rectangle Intersection Check if (SellRectangleLineNumber != 0 && (sc.Close[sc.Index] >= Subgraph_SellRectangleHigh[sc.Index])) { sc.DeleteACSChartDrawing(sc.ChartNumber, DRAWING_RECTANGLEHIGHLIGHT, SellRectangleLineNumber); SellRectangleLineNumber = 0; } } } PS i feel i may have massively overcomplicated things, (if anyone wonders, id8 refers to Numbers Bars Calculated Values study- which is part of the alert conditons) EDIT: or is it possible to display the OHLC of candles where color bar on alert condition formulas are true? this would also be acceptable Date Time Of Last Edit: 2024-10-30 10:20:11
|
Screenshot 2024-10-30 091347.png / V - Attached On 2024-10-30 09:14:23 UTC - Size: 81.46 KB - 34 views |