Wrong Daily Data on Fridays
Created at 25 Apr 2021, 00:38
Wrong Daily Data on Fridays
25 Apr 2021, 00:38
I want to plot some price level on 15-min charts that is computed based on the high, low and closing price of the previous day. The code works correctly, but on Fridays the plot appears far away from the prices of the previous day. Do you have any idea, why this happens? I attach the code and a screenshot.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class LinesError : Indicator
{
[Output("S1", LineColor = "Yellow", PlotType = PlotType.Points, Thickness = 4)]
public IndicatorDataSeries S1 { get; set; }
double PP;
int LastDailyBarIndex;
Bars DailyBars;
protected override void Initialize()
{
DailyBars = MarketData.GetBars(TimeFrame.Daily);
}
public override void Calculate(int index)
{
LastDailyBarIndex = GetDayIndex(Bars.OpenTimes[index]) - 1;
PP = (DailyBars.HighPrices[LastDailyBarIndex] + DailyBars.LowPrices[LastDailyBarIndex] + DailyBars.ClosePrices[LastDailyBarIndex]) / 3;
S1[index] = (2 * PP) - DailyBars.HighPrices[LastDailyBarIndex];}
protected int GetDayIndex(DateTime currentTime)
{
int i = DailyBars.Count;
while (DailyBars.OpenTimes[i].DayOfYear != currentTime.DayOfYear)
{
i--;
}
return i;
}
}
}