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;
}
Michael Manus
could you try and replace :
atr.Update(bar.EndTime, bar.Close);withatr.Update(bar);and post if it worksChris Holley
This worked! Thanks for the help, Michael
Chris Holley
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!