Untitled
unknown
plain_text
5 months ago
2.1 kB
4
Indexable
using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using System.Linq; namespace cAlgo { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class MomentKey : Indicator { [Parameter("Hours List (comma-separated)", DefaultValue = "7,8,9,10,11")] public string HoursList { get; set; } [Parameter("Line Color", DefaultValue = "Red")] public string LineColor { get; set; } [Parameter("Line Thickness", DefaultValue = 1)] public int LineThickness { get; set; } protected override void Initialize() { // Nothing to initialize } public override void Calculate(int index) { // Parse the list of hours var hours = HoursList.Split(',') .Select(hour => int.TryParse(hour.Trim(), out var parsedHour) ? parsedHour : (int?)null) .Where(hour => hour.HasValue) .Select(hour => hour.Value) .ToList(); var currentBarTime = MarketSeries.OpenTime[index]; // Check if the current bar is at one of the specified hours if (hours.Contains(currentBarTime.Hour) && currentBarTime.Minute == 0) { string hourText = $"{currentBarTime.Hour:00}:00"; // Draw a vertical dashed line var verticalLine = Chart.DrawVerticalLine( $"MomentKey_{index}", currentBarTime, Color.DarkRed, LineThickness, LineStyle.DotsVeryRare ); // Add a text label on the line Chart.DrawText( $"HourLabel_{index}", hourText, currentBarTime, Chart.TopY, Color.DarkRed ); } } } }
Editor is loading...
Leave a Comment