DavideCane

MD strategy v2

25
Matteo e Davide
Bollinger
Macd
RSi
Stochastic
开源脚本

本着真正的TradingView精神,该脚本的作者将其开源发布,以便交易者可以理解和验证它。为作者喝彩!您可以免费使用它,但在出版物中重复使用此代码受网站规则的约束。 您可以收藏它以在图表上使用。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?
//@version=2
strategy("MD strategy", overlay=true)
lengthrsi = input( 14 )
overSold = input( 30 )
overBought = input( 70 )
price = close
source = close
lengthbb = input(20, minval=1)
mult = input(2.0, minval=0.001, maxval=50)
direction = input(0, title = "Strategy Direction", type=integer, minval=-1, maxval=1)
fastLength = input(12)
slowlength = input(26)
MACDLength = input(9)
consecutiveBarsUp = input(3)
consecutiveBarsDown = input(3)
lengthch = input(type=integer, minval=1, maxval=1000, defval=5)
upBound = highest(high, lengthch)
downBound = lowest(low, lengthch)
lengthst = input(14, minval=1)
OverBoughtst = input(80)
OverSoldst = input(20)
smoothK = 3
smoothD = 3

k = sma(stoch(close, high, low, lengthst), smoothK)
d = sma(k, smoothD)



ups = price > price[1] ? nz(ups[1]) + 1 : 0
dns = price < price[1] ? nz(dns[1]) + 1 : 0
MACD = ema(close, fastLength) - ema(close, slowlength)
aMACD = ema(MACD, MACDLength)
delta = MACD - aMACD

strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))

basis = sma(source, lengthbb)
dev = mult * stdev(source, lengthbb)

upper = basis + dev
lower = basis - dev

vrsi = rsi(price, lengthrsi)

if (not na(vrsi))
    if (crossover(vrsi, overSold))
        strategy.entry("RsiLE", strategy.long, comment="RsiLE")
    if (crossunder(vrsi, overBought))
        strategy.entry("RsiSE", strategy.short, comment="RsiSE")

if (crossover(source, lower))
    strategy.entry("BBandLE", strategy.long, stop=lower, oca_name="BollingerBands", oca_type=strategy.oca.cancel, comment="BBandLE")
else
    strategy.cancel(id="BBandLE")

if (crossunder(source, upper))
    strategy.entry("BBandSE", strategy.short, stop=upper, oca_name="BollingerBands", oca_type=strategy.oca.cancel, comment="BBandSE")
else
    strategy.cancel(id="BBandSE")
    
    
if (not na(k) and not na(d))
    if (crossover(k,d) and k < OverSoldst)
        strategy.entry("StochLE", strategy.long, comment="StochLE")
    if (crossunder(k,d) and k > OverBoughtst)
        strategy.entry("StochSE", strategy.short, comment="StochSE")   
        
if (crossover(delta, 0))
    strategy.entry("MacdLE", strategy.long, comment="MacdLE")

if (crossunder(delta, 0))
    strategy.entry("MacdSE", strategy.short, comment="MacdSE")