An Algorithmic Approach to The Parabolic SAR Trading Strategy

So, in this chapter, we’re going to take a closer look at how the Parabolic SAR strategy works. After seeing how it played out with Reliance in the previous chapter, it’s time to break down the basics. We’ll start by understanding the key settings that control how the Parabolic SAR behaves.

We’ll then move on to spotting market trends which is what this strategy is all about. We’ll learn how to tell if prices are likely going up or down, and how the strategy responds to these changes.

We’ll also talk about how to spot points where trends might flip, and how to make buying or selling decisions based on what the strategy tells us. This is key to making smart trades.

Plus, we’ll go over how the strategy speeds up or slows down based on price movements, and we’ll see how to plot these details on a chart to visualize what’s going on.

Lastly, we’ll wrap it up with a step-by-step walkthrough of how the strategy works, written in a programming-like way to clearly outline the logic.

So, there’s a lot to cover but it will give us a solid understanding of how the Parabolic SAR strategy works, setting us up to use it smartly in our future trades.

Initial Parameters:

The behavior of the Parabolic SAR is governed by three key parameters:

  • Start (0.02): This value represents the initial Acceleration Factor (AF), dictating the rate at which the SAR will approach the price initially.
  • Increment (0.02): The AF increases by this value whenever a new Extreme Point (EP) is made within the ongoing trend, thus accelerating the SAR’s approach towards the price.
  • Maximum (0.2): This value serves as the cap for the AF, ensuring it doesn’t exceed this value no matter how many new EPs are registered.

Trend Identification and Management:

Identifying the Trend:

The first step in the strategy is to identify the prevailing trend:

  • An upward trend is assumed if the closing price is higher than the previous close.
  • Conversely, a downward trend is assumed if the closing price is lower than the previous close.

Managing the Trend:

Once the trend is identified, the Parabolic SAR behaves accordingly:

  • In an upward trend, the SAR is placed below the price, steadily moving up towards it as the market continues to rise.
  • In a downward trend, the SAR is placed above the price, steadily moving down towards it as the market continues to fall.

Detecting Reversals:

Reversals are a key aspect of market behavior:

  • In an upward trend, if the price falls to or below the current SAR value, a trend reversal to downward is detected.
  • In a downward trend, if the price rises to or above the current SAR value, a trend reversal to upward is detected.

Trading Decisions:

Based on the trend information, trading decisions are made:

  • Short Entry: In an upward trend, a fall to the SAR value triggers a short entry, anticipating a downward movement.
  • Long Entry: Conversely, in a downward trend, a rise to the SAR value triggers a long entry, anticipating an upward movement.

Adjusting the Acceleration Factor:

The AF is crucial for adjusting the SAR’s sensitivity towards price movements:

  • With each new EP in the ongoing trend, the AF increases, hastening the SAR’s approach towards the price.
  • The AF is restrained by a maximum value of 0.2, ensuring a balanced approach.

Plotting the SAR:

The strategy employs plots to visualize the SAR values, providing a clear representation of the market’s trend and potential reversal points.

Pseudo Code Overview:

A well-defined pseudo code encapsulates the logic of the strategy, providing a step-by-step blueprint of the operations, from trend identification to trading decisions, all under the governance of the defined parameters.

				
					Initialize variables: start, increment, maximum, uptrend, EP, SAR, AF, nextBarSAR, firstTrendBar

For each bar in the price data:
    Determine the trend based on the closing prices of the current and previous bars.
    If it's the first bar of a new trend:
        Set initial SAR, EP, and AF values based on the price data.
    If in an uptrend:
        If SAR value drops below the lowest price of the current or previous bar:
            Detect a trend reversal to downward.
            Adjust SAR, EP, and AF values.
    If in a downward trend:
        If SAR value rises above the highest price of the current or previous bar:
            Detect a trend reversal to upward.
            Adjust SAR, EP, and AF values.
    If not the first bar of the new trend:
        Adjust AF value if a new high (in an upward trend) or a new low (in a downward trend) is made.
    Calculate the next bar's SAR value based on the current SAR, EP, and AF values.
    If a bar is confirmed:
        Enter or exit trades based on the trend and SAR value.
    Plot the current and next bar's SAR values.

				
			

Python Code:

				
					class ParabolicSARStrategy:
    def __init__(self, start=0.02, increment=0.02, maximum=0.2):
        self.start = start
        self.increment = increment
        self.maximum = maximum
        self.uptrend = None
        self.EP = None
        self.SAR = None
        self.AF = start
        self.nextBarSAR = None
        self.firstTrendBar = False

    def calculate(self, bars):
        for i in range(len(bars)):
            if i > 0:
                self.firstTrendBar = False
                self.SAR = self.nextBarSAR
                if i == 1:
                    prevSAR = prevEP = lowPrev = highPrev = closeCur = closePrev = None
                    lowPrev, highPrev = bars[i-1]['low'], bars[i-1]['high']
                    closeCur, closePrev = bars[i]['close'], bars[i-1]['close']
                    if closeCur > closePrev:
                        self.uptrend = True
                        self.EP = bars[i]['high']
                        prevSAR, prevEP = lowPrev, bars[i]['high']
                    else:
                        self.uptrend = False
                        self.EP = bars[i]['low']
                        prevSAR, prevEP = highPrev, bars[i]['low']
                    self.firstTrendBar = True
                    self.SAR = prevSAR + self.start * (prevEP - prevSAR)
                if self.uptrend:
                    if self.SAR > bars[i]['low']:
                        self.firstTrendBar = True
                        self.uptrend = False
                        self.SAR = max(self.EP, bars[i]['high'])
                        self.EP = bars[i]['low']
                        self.AF = self.start
                else:
                    if self.SAR < bars[i]['high']:
                        self.firstTrendBar = True
                        self.uptrend = True
                        self.SAR = min(self.EP, bars[i]['low'])
                        self.EP = bars[i]['high']
                        self.AF = self.start
                if not self.firstTrendBar:
                    if self.uptrend:
                        if bars[i]['high'] > self.EP:
                            self.EP = bars[i]['high']
                            self.AF = min(self.AF + self.increment, self.maximum)
                    else:
                        if bars[i]['low'] < self.EP:
                            self.EP = bars[i]['low']
                            self.AF = min(self.AF + self.increment, self.maximum)
                if self.uptrend:
                    self.SAR = min(self.SAR, bars[i-1]['low'])
                    if i > 1:
                        self.SAR = min(self.SAR, bars[i-2]['low'])
                else:
                    self.SAR = max(self.SAR, bars[i-1]['high'])
                    if i > 1:
                        self.SAR = max(self.SAR, bars[i-2]['high'])
                self.nextBarSAR = self.SAR + self.AF * (self.EP - self.SAR)

            # Additional logic for entering/exiting trades and plotting can be added here

# Usage:
# Assume bars is a list of dictionaries where each dictionary contains the open, high, low, and close prices for each bar.
# strategy = ParabolicSARStrategy()
# strategy.calculate(bars)

				
			

In this Python code, the ParabolicSARStrategy class is defined, which encapsulates the logic of the strategy. The calculate method processes a list of price bars, executing the logic of the strategy for each bar.

The Parabolic SAR strategy provides a structured approach for traders to navigate market trends, making informed entry and exit decisions. We will explore this strategy by applying it to various stocks and see their outcome. 

By understanding the operational mechanics and the governing parameters of the Parabolic SAR, traders are well-positioned to utilize this strategy for enhanced trading outcomes.

Similar to how the Entropy strategy relies on Bollinger Bands, it also incorporates the use of Parabolic SAR for making trading decisions. 

However, a common drawback persists; both these strategies operate under the assumption that the stock price distribution follows a normal distribution. 

Therefore, in scenarios where this assumption is disrupted, especially during fundamental news releases or any other significant market events, it’s advisable to refrain from employing the Entropy or Parabolic SAR strategies.

Post a comment

Leave a Comment

Your email address will not be published. Required fields are marked *

×Close