DavideCane

MD strategy v2

25
Matteo e Davide
Bollinger
Macd
RSi
Stochastic
오픈 소스 스크립트

이 스크립트의 오써는 참된 트레이딩뷰의 스피릿으로 이 스크립트를 오픈소스로 퍼블리쉬하여 트레이더들로 하여금 이해 및 검증할 수 있도록 하였습니다. 오써를 응원합니다! 스크립트를 무료로 쓸 수 있지만, 다른 퍼블리케이션에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

면책사항

이 정보와 게시물은 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")