0bps

Strategy vault / Other

HIGH LOW SAR

Pine Script strategy by Zer3192.

Author
Zer3192
Complexity
Intermediate · 112 lines
Parameters
7
Backtest bar
4h · intraday
Tested on
BTC/USDT · spot

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

Parameters

NameDefaultWhat it controls
v_input_1falsetrend
v_input_2_close0src5: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4
v_input_30.02start
v_input_40.02increment
v_input_50.2maximum
v_input_650lookBack
v_input_72.2Multiplier

Source Pine Script

/*backtest
start: 2021-05-08 00:00:00
end: 2022-05-07 23:59:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RafaelZioni

//@version=4
study("HIGH LOW SAR ", overlay=true)

len = 100

p1 =close

p2 = close[100] 
sma = sma(p1, len)
sma1 = sma(p2, len)
avg = atr(len)
fibratio1 = 1.618
fibratio3 = 4.236
r1 = avg * fibratio1
r3 = avg * fibratio3
top3 = sma + r3
bott1 = sma - r1
top2 = sma1 + r3
bott2 = sma1 - r1
plot(top2, title="high", color=color.red, style=plot.style_linebr, linewidth=3, transp=40, trackprice=true, offset=-9999)
plot(bott2, title="low", color=color.blue, style=plot.style_linebr, linewidth=3, transp=40, trackprice=true, offset=-9999)

plot(top3, title="high1", color=color.red, style=plot.style_linebr, linewidth=3, transp=40, trackprice=true, offset=-9999)
plot(bott1, title="low1", color=color.blue, style=plot.style_linebr, linewidth=3, transp=40, trackprice=true, offset=-9999)
//
trend = input(false)
if barstate.islast and trend  == true
    line z = line.new(bar_index[1],top3[1], bar_index,top3,extend=extend.both,color=color.red,style=line.style_dashed,width=1)
    line f = line.new(bar_index[1],top2[1], bar_index,top2,extend=extend.both,color=color.blue,style=line.style_dashed,width=1)
    line w = line.new(bar_index[1],bott1[1], bar_index,bott1,extend=extend.both,color=color.green,style=line.style_dashed,width=1)
    line h= line.new(bar_index[1],bott2[1], bar_index,bott2,extend=extend.both,color=color.green,style=line.style_dashed,width=1)
    line.delete(z[1])
    line.delete(f[1])
    line.delete(w[1])
    line.delete(h[1])
//
src5 = input(close)
    

len5 = 100

ma = ema(src5*volume, len5) / ema(volume, len5)



src1 = ma

p(src1, len5) =>
    n = 0.0
    s = 0.0
    for i = 0 to len5 - 1
        w = (len5 - i) * len5
        n := n + w
        s := s + src5[i] * w
    s / n

hm = 2.0 * p(src1, floor(len5 / 2)) - p(src1, len5)
vhma = p(hm, floor(sqrt(len5)))
lineColor = vhma > vhma[1] ? color.lime : color.red
plot(vhma, title="VHMA", color=lineColor ,linewidth=3)
hColor = true,vis = true
hu = hColor ? (vhma > vhma[2] ? #00ff00 : #ff0000) : #ff9800

vl = vhma[0]
ll = vhma[1]
m1 = plot(vl, color=hu, linewidth=1, transp=60)
m2 = plot(vis ? ll : na,  color=hu, linewidth=2, transp=80)

fill(m1, m2,  color=hu, transp=70)
//
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(50)
//
multi = input(2.2, title="Multiplier", minval=0.001, maxval=10) 

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

low1 = crossover(s1[1], s2)  and s1<bott1 
high1 = crossunder(s1[1], b) and s1>top2 and vhma < vhma[2]

plotshape(low1, title="L", text="L", color=color.green, style=shape.labelup, location=location.belowbar, size=size.small, textcolor=color.white, transp=0)  //plot for buy icon
plotshape(high1, title="H", text="H", color=color.red, style=shape.labeldown, location=location.abovebar, size=size.small, textcolor=color.white, transp=0)  //plot for sell icon
//
/////////////// Alerts /////////////// 
alertcondition(low1, title='low', message='SAR LOW')
alertcondition(high1, title='high', message='SAR HIGH')
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-05-29. 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/HIGH-LOW-SAR.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