0bps

Strategy vault / Other

SAR high and low

Pine Script strategy by Zer3192.

Author
Zer3192
Complexity
Starter · 49 lines
Parameters
5
Backtest bar
4h · intraday
Tested on
BTC/USDT · futures

The original spec has no written description. Read the source below.

Parameters

NameDefaultWhat it controls
v_input_10.02start
v_input_20.02increment
v_input_30.2maximum
v_input_440lookBack
v_input_52Multiplier

Source Pine Script

/*backtest
start: 2021-05-08 00:00:00
end: 2022-05-07 23:59:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
study("SAR -high and low",overlay = true)
// INPUTS //
//
start = input(0.02) 
increment = input(0.02)  
maximum = input(0.2)
s1 = sar(start, increment, maximum)
pc = close < s1 ? color.red : color.green
plot(s1, style=plot.style_cross, color=pc)
//


lookBack = input(40)
//
multi = input(2, title="Multiplier", minval=0.001, maxval=2) 

mean = ema(s1 ,lookBack)  
stddev = multi * stdev(s1, lookBack)  
b = mean + stddev
s2 = mean - stddev

low1 = crossover(s1, s2)  
high1 = crossunder(s1, b) 

meanp = plot(mean, title="Mean", color=color.gray)  
bsign = plot(b, title="Upper Deviation Line", color=color.green, linewidth=2)  
ssign = plot(s2, title="Lower Deviation Line", color=color.red, linewidth=2)  

fill(bsign, meanp, title="Upper Deviation fill", color=color.green)  
fill(meanp, ssign, title="Lower Deviation fill", color=color.red)  



plotshape(low1, title="low", text="low", color=color.green, style=shape.labelup, location=location.belowbar, size=size.small, textcolor=color.white, transp=0)  //plot for buy icon
plotshape(high1, title="high", text="high", color=color.red, style=shape.labeldown, location=location.abovebar, size=size.small, textcolor=color.white, transp=0)  //plot for sell icon
if low1
   strategy.entry("buy", strategy.long)
else if high1
    strategy.entry("sell", strategy.short)

Published by Zer3192 on the FMZ strategy square · last modified 2022-06-04. 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/SAR-high-and-low.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