Matteo e Davide
//@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) 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(close[lengthch])) strategy.entry("ChBrkLE", strategy.long, stop=upBound + syminfo.mintick, comment="ChBrkLE") strategy.entry("ChBrkSE", strategy.short, stop=downBound - syminfo.mintick, comment="ChBrkSE") //plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)