Supported Indicators
Delay
Introduction
An indicator that delays its input for a certain period
To view the implementation of this indicator, see the LEAN GitHub repository.
Using Delay Indicator
Delay does not have an automatic indicator implementation available.
You can manually create a Delay
indicator, so it doesn't automatically update. Manual indicators let you update their values with any data you choose.
Updating your indicator manually enables you to control when the indicator is updated and what data you use to update it. To manually update the indicator, call the Update
method with time/number pair, or an IndicatorDataPoint
. The indicator will only be ready after you prime it with enough data.
public class DelayAlgorithm : QCAlgorithm { private Symbol _symbol; private Delay _delay; public override void Initialize() { _symbol = AddEquity("SPY", Resolution.Daily).Symbol; _delay = new Delay(SPY); } public override void OnData(Slice data) { if (data.Bars.TryGeValue(_symbol, out var bar)) { _delay.Update(bar.EndTime, bar.Close); } if (_delay.IsReady) { // The current value of _delay is represented by itself (_delay) // or _delay.Current.Value Plot("Delay", "delay", _delay); } } }
class DelayAlgorithm(QCAlgorithm): def Initialize(self) -> None: self.symbol = self.AddEquity("SPY", Resolution.Daily).Symbol self.delay = Delay(SPY) def OnData(self, slice: Slice) -> None: bar = slice.Bars.get(self.symbol) if bar: self.delay.Update(bar.EndTime, bar.Close) if self.delay.IsReady: # The current value of self.delay is represented by self.delay.Current.Value self.Plot("Delay", "delay", self.delay.Current.Value)
To register a manual indicator for automatic updates with the security data, call the RegisterIndicator
method.
public class DelayAlgorithm : QCAlgorithm { private Symbol _symbol; private Delay _delay; public override void Initialize() { _symbol = AddEquity("SPY", Resolution.Daily).Symbol; _delay = new Delay(SPY); RegisterIndicator(_symbol, _delay, Resolution.Daily); } public override void OnData(Slice data) { if (_delay.IsReady) { // The current value of _delay is represented by itself (_delay) // or _delay.Current.Value Plot("Delay", "delay", _delay); } } }
class DelayAlgorithm(QCAlgorithm): def Initialize(self) -> None: self.symbol = self.AddEquity("SPY", Resolution.Daily).Symbol self.delay = Delay(SPY) self.RegisterIndicator(self.symbol, self.delay, Resolution.Daily) def OnData(self, slice: Slice) -> None: if self.delay.IsReady: # The current value of self.delay is represented by self.delay.Current.Value self.Plot("Delay", "delay", self.delay.Current.Value)
The following reference table describes the Delay constructor:
Delay()1/2
Delay QuantConnect.Indicators.Delay (
int
period,
)
Initializes a new instance of the Delay class.
Delay()2/2
Delay QuantConnect.Indicators.Delay (string
name,int
period, )
Initializes a new instance of the Delay class.
Visualization
The following image shows plot values of selected properties of Delay
using the plotly library.
