I am trying to get the ATR from symbols within a universe for position sizing. I have attached a snippet of the two different methods I have tried for this. I keep receiving the error : Runtime Error: AverageTrueRange does not support Update(DateTime, decimal) method overload. Use Update(IBaseDataBar) instead.
Any suggestions on how to do this? I can't attached a backtest because of the error, but I am referencing these in the onData block.
//First attempt at getting ATR from the universe
private class SelectionData
{
// variables you need for selection
public readonly RateOfChangePercent rocp;
public readonly AverageTrueRange atr;
// initialize your variables and indicators.
public SelectionData(int period)
{
rocp = new RateOfChangePercent(period);
atr = new AverageTrueRange(30);
}
// update your variables and indicators with the latest data.
// you may also want to use the History API here.
public bool Update(DateTime time, decimal value)
{
return rocp.Update(time, value) && atr.Update(time, value);
}
}
//Second attempt to retreive ATR from the universe
public decimal GetATR(Symbol symbol, int windowSize)
{
//validate that the security is in the universe
if (!Securities.ContainsKey(symbol))
return 0;
IEnumerable<TradeBar> bars = History<TradeBar>(symbol, TimeSpan.FromDays(7), Resolution.Daily);
AverageTrueRange atr;
atr = ATR(symbol, windowSize, MovingAverageType.Simple, Resolution.Daily);
foreach (var bar in bars) {
atr.Update(bar.EndTime, bar.Close);
}
decimal o = atr.Current;
return o;
}