0bps

Strategy vault / Other

Parabolic SAR Buy And Sell

backtest

Author
ChaoZhang
Complexity
Starter · 42 lines
Parameters
5
Backtest bar
15m · intraday
Tested on
BTC/USDT · futures

backtest

IMG

Parameters

NameDefaultWhat it controls
v_input_10.00252Start
v_input_20.00133Increment
v_input_30.22Maximum
v_input_420Point Width
v_input_5trueHighlight Start Points ?

Source Pine Script

/*backtest
start: 2022-04-24 00:00:00
end: 2022-05-23 23:59:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
// Copyright (c) 2019-present, Alex Orekhov (everget)
// re-edit @guikroth
study("Parabolic SAR", shorttitle="PSAR Buy and Sell Alerts", overlay=true)

start = input(title="Start", type=float, step=0.00005, defval=0.00252)
increment = input(title="Increment", type=float, step=0.00005, defval=0.00133)
maximum = input(title="Maximum", type=float, step=0.01, defval=0.220)
width = input(title="Point Width", minval=1, defval=20)
highlightStartPoints = input(title="Highlight Start Points ?", defval=true)

psar = sar(start, increment, maximum)
dir = psar < close ? 1 : -1

psarColor = psar < close ? #3388bb : #fdcc02


plotshape(dir == 1 and dir[1] == -1 and highlightStartPoints ? psar : na, title="Buy", style=shape.labelup, location=location.absolute, size=size.normal, text="Buy", transp=0, textcolor = white, color=green, transp=0)
plotshape(dir == -1 and dir[1] == 1 and highlightStartPoints ? psar : na, title="Sell", style=shape.labeldown, location=location.absolute, size=size.normal, text="Sell", transp=0, textcolor = white, color=red, transp=0)

barcolor(dir == 1 ? green: red)
Buy = psar < close ? 1 : na
Sell = psar < close ? na : -1

changeCond = dir != dir[1]
alertcondition(dir == 1 and dir[1] == -1 and highlightStartPoints ? psar : na, title="Buy", message="buy!")
alertcondition(dir == 1 and dir[1] == -1 and highlightStartPoints ? psar : na, title="Buy", message="buy!")
alertcondition(dir == 1 and dir[1] == -1 and highlightStartPoints ? psar : na, title="Buy", message="buy!")
alertcondition(dir == -1 and dir[1] == 1 and highlightStartPoints ? psar : na, title="Sell", message="sell!")

if dir == 1 and dir[1] == -1 and highlightStartPoints
    strategy.entry("Enter Long", strategy.long)
else if dir == -1 and dir[1] == 1 and highlightStartPoints
    strategy.entry("Enter Short", strategy.short)

Published by ChaoZhang on the FMZ strategy square · last modified 2022-05-25. 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-Buy-And-Sell.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