0bps

Strategy vault / Mean reversion

Parabolic SAR Reversal Strategy

This strategy trades based on Parabolic SAR indicator which identifies potential reversal points in trends. Entry signals are generated when SAR flips above or below price.

Author
ChaoZhang
Complexity
Intermediate · 64 lines
Parameters
9
Backtest bar
3h · intraday
Tested on
BTC/USDT · futures

Overview

This strategy trades based on Parabolic SAR indicator which identifies potential reversal points in trends. Entry signals are generated when SAR flips above or below price.

Principles

Parabolic SAR is a trend following indicator that mainly identifies trend reversals.

When SAR is below price, it represents uptrend. SAR flipping above price gives short signal.

When SAR is above price, it represents downtrend. SAR flipping below price gives long signal.

The strategy simply trades the SAR flip as signal direction, with SAR as stop loss.

Advantages

  1. SAR accurately locates potential reversal points.

  2. Trend following mechanism reduces false signals.

  3. SAR acts as trailing stop, avoiding being trapped.

  4. No other indicators or filters required.

  5. Easy parameter optimization, defaults often work.

Risks and Mitigations

  1. SAR may whipsaw in ranging markets. Trend filter can be added.

  2. SAR too close to price risks being hit. Wider stops needed.

  3. Volume is ignored, risk of divergence. Volume indicators can help.

  4. Drawdowns may be significant. Appropriate position sizing is key.

  5. Reversals do not always succeed. Confirmation may be needed.

Enhancement Opportunities

  1. Test if SAR parameters can be improved.

  2. Add indicators like MACD to confirm reversal probability.

  3. Build dynamic trailing stop mechanism.

  4. Optimize entry position sizing to capitalize on SAR signals.

  5. Research adding reversal confirmation logic.

Summary

The strategy trades potential reversal points identified by SAR, taking trades when SAR flips price. Benefits include trailing stops to avoid traps. But SAR timing may be inaccurate and needs refinement. Overall the SAR reversal concept is worth learning.

Parameters

NameDefaultWhat it controls
v_input_10.02start
v_input_20.02increment
v_input_30.2maximum
v_input_4trueFrom Day
v_input_5trueFrom Month
v_input_62018From Year
v_input_7trueTo Day
v_input_8trueTo Month
v_input_92019To Year

Source Pine Script

/*backtest
start: 2023-08-18 00:00:00
end: 2023-09-17 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy("Parabolic SAR Strategy", overlay=true)

// 
// author: Kozlod
// date: 2018-09-03
// https://www.tradingview.com/u/Kozlod/
// 

start = input(0.02)
increment = input(0.02)
maximum = input(0.2)

////////////////////////////////////////////////////////////////////////////////
// BACKTESTING RANGE
 
// From Date Inputs
fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
fromYear = input(defval = 2018, title = "From Year", minval = 1970)
 
// To Date Inputs
toDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
toMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
toYear = input(defval = 2019, title = "To Year", minval = 1970)
 
// Calculate start/end date and time condition
startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)
finishDate = timestamp(toYear, toMonth, toDay, 00, 00)
time_cond = true
 
////////////////////////////////////////////////////////////////////////////////

psar = sar(start, increment, maximum)

// Signals
psar_long  = high[1] < psar[2] and high > psar[1] 
psar_short = low[1]  > psar[2] and low  < psar[1] 

// Plot PSAR
plotshape(psar, location = location.absolute, style = shape.cross, size = size.tiny, color = low < psar[1] and not psar_long ? green : red)


if (psar >= high and time_cond)
    strategy.entry("ParLE", strategy.long, stop=psar, comment="ParLE")
else
    strategy.cancel("ParLE")

if (psar <= low and time_cond)
    strategy.entry("ParSE", strategy.short, stop=psar, comment="ParSE")
else
    strategy.cancel("ParSE")

if (not time_cond)
    strategy.close_all()

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-18. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Parabolic-SAR-Reversal-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open