backtrader.indicators.psar module¶
PSAR Indicator Module - Parabolic SAR.
This module provides the Parabolic SAR (Stop and Reverse) indicator developed by J. Welles Wilder, Jr. for trend following and reversal signals.
- Classes:
ParabolicSAR: Parabolic SAR indicator (alias: PSAR).
示例
- class MyStrategy(bt.Strategy):
- def __init__(self):
self.psar = bt.indicators.PSAR(self.data)
- def next(self):
# PSAR dots below price indicate uptrend if self.psar.psar[0] < self.data.low[0]:
self.buy()
# PSAR dots above price indicate downtrend elif self.psar.psar[0] > self.data.high[0]:
self.sell()
- class backtrader.indicators.psar.ParabolicSAR[源代码]¶
基类:
PeriodNParabolic SAR (Stop and Reverse) indicator.
Defined by J. Welles Wilder, Jr. in 1978 in his book New Concepts in Technical Trading Systems. SAR stands for Stop and Reverse, and the indicator is meant as a signal for entry (and reverse).
The indicator places dots above or below price bars to indicate the current trend direction. When the dots flip from above to below (or vice versa), it signals a potential trend reversal.
The initial trend direction is determined by comparing the close price of the second bar to the first bar. The SAR value accelerates toward the price as the trend extends, using the acceleration factor.
- See:
https://en.wikipedia.org/wiki/Parabolic_SAR http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:parabolic_sar
- psar¶
Line containing the calculated Parabolic SAR values.
- 参数:
period -- Bar number from which to start showing values (default: 2).
af -- Acceleration factor (default: 0.02).
afmax -- Maximum acceleration factor (default: 0.20).
- alias = ('PSAR',)¶
- plotinfo = <backtrader.metabase.plotinfo_obj object>¶
- plotlines = <backtrader.metabase.plotlines_obj object>¶
- prenext()[源代码]¶
Handle calculations before minimum period is reached.
Initializes status tracking and calculates initial PSAR values.
- nextstart()[源代码]¶
Initialize PSAR calculation on first valid bar.
Determines initial trend direction and sets up status tracking.
- next()[源代码]¶
Calculate PSAR for the current bar.
Updates the stop-and-reverse point based on trend direction, extreme price, and acceleration factor.
- frompackages = ()¶
- once(start, end)¶
Implement once using next for batch calculation.
This is used when next is overridden but once is not. It loops through the range and calls next for each step.
- 参数:
start -- Starting index
end -- Ending index
- oncestart(start, end)¶
Implement oncestart using nextstart for batch calculation.
This is used when nextstart is overridden but oncestart is not.
- 参数:
start -- Starting index
end -- Ending index
- packages = ()¶
- preonce(start, end)¶
Implement preonce using prenext for batch calculation.
This is a generic implementation if prenext is overridden but preonce is not. It loops through the range and calls prenext for each step.
- 参数:
start -- Starting index
end -- Ending index
- backtrader.indicators.psar.PSAR¶
ParabolicSAR的别名