Contents
Indicator Reference
Parabolic Stop And Reverse
Create Manual Indicators
You can manually create a ParabolicStopAndReverse
indicator, so it doesn’t automatically update. Manual indicators let you update their values with any data you choose. The following reference table describes the ParabolicStopAndReverse
constructor.
ParabolicStopAndReverse()1/2
ParabolicStopAndReverse QuantConnect.Indicators.ParabolicStopAndReverse (string
name,*decimal
afMax )
Create new Parabolic SAR.
ParabolicStopAndReverse()2/2
ParabolicStopAndReverse QuantConnect.Indicators.ParabolicStopAndReverse (
*decimal
afMax
)
Create new Parabolic SAR.
Update Manual Indicators
You can update the indicator automatically or manually.
Automatic Update
To register a manual indicator for automatic updates with the security data, call the RegisterIndicator
method.
private ParabolicStopAndReverse _psar; // In Initialize() _psar = new ParabolicStopAndReverse(name); _psar.Updated += IndicatorUpdateMethod; RegisterIndicator(symbol, _psar, Resolution.Daily); // In IndicatorUpdateMethod() if (_psar.IsReady) { var indicatorValue = _psar.Current.Value; }
# In Initialize() self.psar = ParabolicStopAndReverse(name) self.psar.Updated += self.IndicatorUpdateMethod self.RegisterIndicator(symbol, self.psar, Resolution.Daily) # In IndicatorUpdateMethod() if self.psar.IsReady: indicator_value = self.psar.Current.Value
To customize the data that automatically updates the indicator, see Custom Indicator Periods and Custom Indicator Values.
Manual Update
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 a TradeBar
, QuoteBar
, or an IndicatorDataPoint
. The indicator will only be ready after you prime it with enough data.
private ParabolicStopAndReverse _psar; private Symbol symbol; // In Initialize() _psar = new ParabolicStopAndReverse(); symbol = AddEquity("SPY").Symbol; // In OnData() if (data.QuoteBars.ContainsKey(_symbol)) { _psar.Update(data.QuoteBars[symbol]); } if (_psar.IsReady) { var indicatorValue = _psar.Current.Value; }
# In Initialize() self.psar = ParabolicStopAndReverse() self.symbol = self.AddEquity("SPY").Symbol # In OnData() if data.QuoteBars.ContainsKey(self.symbol): self.psar.Update(data.QuoteBars[self.symbol]) if self.psar.IsReady: indicator_value = self.psar.Current.Value
Create Automatic Indicators
The PSAR method creates an ParabolicStopAndReverse indicator, sets up a consolidator to update the indicator, and then returns the indicator so you can use it in your algorithm.
The following reference table describes the PSAR
method:
PSAR()1/1
ParabolicStopAndReverse QuantConnect.Algorithm.QCAlgorithm.PSAR (Symbol
symbol,*Decimal
afStart,*Decimal
afIncrement,*Decimal
afMax,*Nullable<Resolution>
resolution,*Func<IBaseData, IBaseDataBar>
selector )
Creates a new Parabolic SAR indicator
If you don't provide a resolution, it defauls to the security resolution. If you provide a resolution, it must be greater than or equal to the resolution of the security. For instance, if you subscribe to hourly data for a security, you should update its indicator with data that spans 1 hour or longer.
For more information about the selector argument, see Alternative Price Fields.
Get Indicator Values
To get the value of the indicator, use its Current.Value
attribute.
private ParabolicStopAndReverse _psar; // In Initialize() var symbol = AddEquity("SPY").Symbol; _psar = PSAR(symbol); // In OnData() if (_psar.IsReady) { var current = _psar.Current.Value; }
# In Initialize() symbol = self.AddEquity("SPY").Symbol self.psar = self.PSAR(symbol) # In OnData() if self.psar.IsReady: current = self.psar.Current.Value
Visualization
To plot indicator values, in the OnData
event handler, call the Plot
method.
private ParabolicStopAndReverse _psar; // In Initialize() var symbol = AddEquity("SPY").Symbol; _psar = PSAR(symbol); // In OnData() if (_psar.IsReady) { Plot("My Indicators", "parabolicstopandreverse", _psar.Current); }
# In Initialize() symbol = self.AddEquity("SPY").Symbol self.psar = self.PSAR(symbol) # In OnData() if self.psar.IsReady: self.Plot("My Indicators", "parabolicstopandreverse", self.psar.Current)
For more information about plotting indicators, see Plotting Indicators.