Untitled
unknown
plain_text
10 months ago
2.2 kB
8
Indexable
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using System;
using System.Collections.Generic;
using System.Linq;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.EasternStandardTime, AccessRights = AccessRights.None)]
public class MomentKey : Indicator
{
[Parameter("Hours List (comma-separated, format: HH:mm)", DefaultValue = "7:10,8:30,9:20,10:10,11:25")]
public string HoursList { get; set; }
[Parameter("Line Thickness", DefaultValue = 1)]
public int LineThickness { get; set; }
private List<(int hour, int minute)> targetTimes;
protected override void Initialize()
{
// Parse the list of hour:minute pairs
targetTimes = HoursList.Split(',')
.Select(time => time.Trim().Split(':'))
.Where(parts => parts.Length == 2 && int.TryParse(parts[0], out _) && int.TryParse(parts[1], out _))
.Select(parts => (hour: int.Parse(parts[0]), minute: int.Parse(parts[1])))
.ToList();
}
public override void Calculate(int index)
{
var currentBarTime = MarketSeries.OpenTime[index];
// Check if the current bar matches any specified hour and minute
if (targetTimes.Any(t => t.hour == currentBarTime.Hour && t.minute == currentBarTime.Minute))
{
string timeText = $"{currentBarTime.Hour:00}:{currentBarTime.Minute:00} {currentBarTime.DayOfWeek}";
// Draw a vertical dashed line
Chart.DrawVerticalLine(
$"MomentKey_{index}",
currentBarTime,
Color.DarkRed,
LineThickness,
LineStyle.DotsVeryRare
);
// Add a text label on the line
Chart.DrawText(
$"HourLabel_{index}",
timeText,
currentBarTime,
MarketSeries.Low[index] - Symbol.PipSize * 50,
Color.DarkRed
);
}
}
}
}Editor is loading...
Leave a Comment