OnCalculate method returning different values in real time and historic
Created at 10 Jul 2024, 10:42
OnCalculate method returning different values in real time and historic
10 Jul 2024, 10:42
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
public class OnCalculateIssue : Indicator
{
protected override void Initialize()
{
}
public override void Calculate(int index)
{
if(index == 0) return;
double val = Math.Abs(Bars.ClosePrices[index] - Bars.ClosePrices[index-1]);
var txt = Chart.DrawText(index.ToString(), val.ToString("N2"), Bars.OpenTimes[index], Bars.LowPrices[index] - Symbol.PipValue*5, Color.Black);
txt.HorizontalAlignment = HorizontalAlignment.Center;
txt.VerticalAlignment = VerticalAlignment.Center;
}
}
}
PanagiotisCharalampous
11 Jul 2024, 06:34
Hi there,
This is by design. Calculate() method is executed once for each historical bar and then for each tick during real time operations.
Best regards,
Panagiotis
@PanagiotisCharalampous