Squeeze Momentum on Reversal Strategy

DeepEntropy · strategy · 50 行 · 点赞 900 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//
// @author Odyssee
// @version=2
//
strategy(shorttitle = "Squeeze MOM", title="Squeeze Momentum on Reversal Strategy", overlay=false)
 
length = input(20, title="BB Length")
mult = input(2.0,title="BB MultFactor")
lengthKC=input(20, title="KC Length")
multKC = input(1.5, title="KC MultFactor")
strength = input(0.0018, title="Reversal Strength")
 
useTrueRange = input(true, title="Use TrueRange (KC)", type=bool)
 
// Calculate BB
source = close
basis = sma(source, length)
dev = multKC * stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev
 
// Calculate KC
ma = sma(source, lengthKC)
range = useTrueRange ? tr : (high - low)
rangema = sma(range, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC
 
sqzOn  = (lowerBB > lowerKC) and (upperBB < upperKC)
sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
noSqz  = (sqzOn == false) and (sqzOff == false)
 
highest = highest(high, lengthKC)
lowest = lowest(low, lengthKC)
lastsma = sma(close,lengthKC)
 
valin = linreg(source  -  avg(avg(highest, lowest), lastsma), lengthKC,0)
 
bcolor = iff( valin > 0, iff( valin > nz(valin[1]), lime, green), iff( valin < nz(valin[1]), red, maroon))
scolor = noSqz ? blue : sqzOn ? black : gray 
plot(valin, color=bcolor, style=histogram, linewidth=4)
plot(0, color=scolor, style=cross, linewidth=2)
 
shortcondition = valin > strength and valin < nz(valin[1]) // line become green
longcondition = valin < (strength*-1) and valin > nz(valin[1]) // line become maroon
 
if(longcondition)
    strategy.entry("BUY", strategy.long)
if(shortcondition)
    strategy.entry("SELL", strategy.short)

← 返回列表