- At midnight, a new "day" object is created.
- I want that day object to save the high/low of the day along with which candle it happened.
From my output, it seems that logic is getting messed up and I don't understand where from.
This script:
else if (State == State.Realtime)
{
foreach (var day in days.Where(day => day.date != Today))
{
Print($"{day.date} -> OHL_O: {day.MOP}, {day.High}, {day.Low}, Six Open: {day.open} -> High: {Time[day.HighBar]}, Low: {Time[day.LowBar]}");
}
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < 1) return;
Today = Time[0].Date;
if (Time[0].TimeOfDay == SixOpen)
{
SixOpeningPrice = Open[0];
}
if (Time[0].TimeOfDay == MidnightOpen)
{
days.Add(new day
{
date = Time[0].Date,
MOP = Open[0],
open = SixOpeningPrice,
High = High[0],
Low = Low[0]
});
Print("New Day Started: " + Time[0].Date);
}
foreach (var day in days.Where(day => day.date == Today))
{
if (High[0] >= day.High)
{
day.High = High[0];
day.HighBar = CurrentBar;
//Draw.Line(this, "High", CurrentBar, High[0], CurrentBar - 5, High[0], Brushes.Green);
}
if (Low[0] <= day.Low)
{
day.Low = Low[0];
day.LowBar = CurrentBar;
//Draw.Line(this, "Low", -5, Low[0], CurrentBar, Low[0], Brushes.Red);
}
}
}
private class day
{
public DateTime date { get; set; } = DateTime.MaxValue;
public double open { get; set; } = double.MinValue;
public double MOP { get; set; } = double.MinValue;
public double High { get; set; } = double.MinValue;
public int HighBar { get; set; } = -1;
public double Low { get; set; } = double.MaxValue;
public int LowBar { get; set; } = -1;
public bool TookPDH { get; set; } = false;
public int PDHRaid { get; set; } = -1;
public bool TookPDL { get; set; } = false;
public int PDLRaid { get; set; } = -1;
public bool Drawn { get; set; } = false;
}
Returns this:
6/12/2024 12:00:00 AM -> OHL_O: 5387, 5454.5, 5385, Six Open: 1.79769313486232E+308 -> High: 6/14/2024 3:30:00 AM, Low: 6/14/2024 3:30:00 PM
6/13/2024 12:00:00 AM -> OHL_O: 5440.75, 5452.75, 5408.5, Six Open: 5436.25 -> High: 6/13/2024 10:15:00 AM, Low: 6/13/2024 6:15:00 AM
6/14/2024 12:00:00 AM -> OHL_O: 5441.25, 5443, 5397.75, Six Open: 5436 -> High: 6/12/2024 4:30:00 PM, Low: 6/12/2024 11:45:00 AM
Disreguard the "Six Open:" property.
As you can see, it is giving the high/low values from the 12th on the 14th day object, and vice versa.

Comment