I'm trying to get the ATR value of an Instrument from an Addon.
So, i try to get ATR indicator without success.
An finally i tried to compute the ATR in a BarRequest but the returned value is false.
Can you maybe help me to find the good value ?
Here my sample:
barsRequest.Request(new Action<BarsRequest, ErrorCode, string>((bars, errorCode, errorMessage) =>
{
for (int i = 0; i < bars.Bars.Count; i++)
{
double high0 = bars.Bars.GetHigh(i);
double low0 = bars.Bars.GetLow(i);
if (i == 0)
{
_atr.Add(high0 - low0);
}
else
{
double close1 = bars.Bars.GetClose(i-1);
double trueRange = Math.Max(Math.Abs(low0 - close1), Math.Max(high0 - low0, Math.Abs(high0 - close1)));
double value = ((Math.Min(i + 1, Period) - 1 ) * _atr[_atr.Count-1] + trueRange) / Math.Min(i + 1, Period);
_atr.Add(value);
NinjaTrader.Code.Output.Process(string.Format("val ue: {0}", value), PrintTo.OutputTab1);
}
}
}));
Comment