Support Board
Date/Time: Sun, 15 Jun 2025 17:12:59 +0000
Post From: ACSIL study
[2025-06-08 23:57:51] |
User936417 - Posts: 16 |
Here is the code: #include "sierrachart.h" SCDLLName("Line Tool Projections") #ifndef DRAWING_LINE #define DRAWING_LINE 8 #endif SCSFExport scsf_LineToolProjections(SCStudyInterfaceRef sc) { SCInputRef Level1 = sc.Input[0]; SCInputRef Level2 = sc.Input[1]; SCInputRef Level3 = sc.Input[2]; SCInputRef ShowLevelValues = sc.Input[3]; // Subgraphs for projected level outputs SCSubgraphRef Level1Up = sc.Subgraph[0]; SCSubgraphRef Level2Up = sc.Subgraph[1]; SCSubgraphRef Level3Up = sc.Subgraph[2]; SCSubgraphRef Level1Down = sc.Subgraph[3]; SCSubgraphRef Level2Down = sc.Subgraph[4]; SCSubgraphRef Level3Down = sc.Subgraph[5]; if (sc.SetDefaults) { sc.GraphName = "Line Tool Projections"; sc.AutoLoop = 0; Level1.Name = "Projection Level 1 (points)"; Level1.SetInt(9); Level2.Name = "Projection Level 2 (points)"; Level2.SetInt(13); Level3.Name = "Projection Level 3 (points)"; Level3.SetInt(19); ShowLevelValues.Name = "Show Level Value Labels"; ShowLevelValues.SetYesNo(1); // Subgraph settings Level1Up.Name = "Level 1 Up"; Level1Up.DrawStyle = DRAWSTYLE_LINE; Level1Up.PrimaryColor = RGB(0, 255, 0); Level2Up.Name = "Level 2 Up"; Level2Up.DrawStyle = DRAWSTYLE_LINE; Level2Up.PrimaryColor = RGB(0, 200, 0); Level3Up.Name = "Level 3 Up"; Level3Up.DrawStyle = DRAWSTYLE_LINE; Level3Up.PrimaryColor = RGB(0, 150, 0); Level1Down.Name = "Level 1 Down"; Level1Down.DrawStyle = DRAWSTYLE_LINE; Level1Down.PrimaryColor = RGB(255, 0, 0); Level2Down.Name = "Level 2 Down"; Level2Down.DrawStyle = DRAWSTYLE_LINE; Level2Down.PrimaryColor = RGB(200, 0, 0); Level3Down.Name = "Level 3 Down"; Level3Down.DrawStyle = DRAWSTYLE_LINE; Level3Down.PrimaryColor = RGB(150, 0, 0); return; } if (sc.UpdateStartIndex != sc.ArraySize - 1) return; const int ToolType = static_cast<int>(DRAWING_LINE); const int DrawingCount = sc.GetACSDrawingsCount(sc.ChartNumber, ToolType); if (DrawingCount == 0) { sc.AddMessageToLog("LineToolProjections: No line drawings found.", 0); return; } for (int i = DrawingCount - 1; i >= 0; --i) { s_UseTool Tool; if (!sc.GetACSDrawingByIndex(sc.ChartNumber, i, Tool, ToolType)) continue; if (Tool.DrawingType != static_cast<DrawingTypeEnum>(DRAWING_LINE)) continue; float High = max(Tool.BeginValue, Tool.EndValue); float Low = min(Tool.BeginValue, Tool.EndValue); float Level1Val = static_cast<float>(Level1.GetInt()); float Level2Val = static_cast<float>(Level2.GetInt()); float Level3Val = static_cast<float>(Level3.GetInt()); float Levels[6] = { High + Level1Val, High + Level2Val, High + Level3Val, Low - Level1Val, Low - Level2Val, Low - Level3Val }; // Plot subgraph values Level1Up[sc.Index] = Levels[0]; Level2Up[sc.Index] = Levels[1]; Level3Up[sc.Index] = Levels[2]; Level1Down[sc.Index] = Levels[3]; Level2Down[sc.Index] = Levels[4]; Level3Down[sc.Index] = Levels[5]; // Draw horizontal projected lines for (int j = 0; j < 6; ++j) { s_UseTool LineTool; LineTool.Clear(); LineTool.ChartNumber = sc.ChartNumber; LineTool.DrawingType = static_cast<DrawingTypeEnum>(DRAWING_LINE); LineTool.BeginValue = Levels[j]; LineTool.BeginDateTime = sc.BaseDateTimeIn[sc.ArraySize - 1].GetAsDouble(); LineTool.Color = RGB(0, 255, 0); LineTool.AddMethod = UTAM_ADD_ALWAYS; if (ShowLevelValues.GetYesNo()) { char Label[32]; snprintf(Label, sizeof(Label), "%.2f", Levels[j]); LineTool.Text = Label; } sc.UseTool(LineTool); } break; // Only process most recent line } } |