Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=2
- strategy("Kalman Smoother м1",overlay=true,default_qty_type=strategy.percent_of_equity ,default_qty_value=100)
- ///// Backtest Start Date /////
- // startDate = input(title="Start Date", type=input.integer, defval=3, minval=1, maxval=31)
- // startMonth = input(title="Start Month", type=input.integer, defval=3, minval=1, maxval=12)
- // startYear = input(title="Start Year", type=input.integer, defval=2019, minval=1800, maxval=2100)
- // Input
- fastMAlen = input(21, minval=1, title="MACD fast moving average")
- slowMAlen=input(100,minval=1, title="MACD slow moving average")
- signalMACDlen = input(21,minval=1, title="MACD signal line moving average")
- StochLength = input(100, minval=1, title="Stochastic Length")
- switch=input(true, title="Enable MACD Bar Color?")
- //HISTORICAL VOLATILITY
- histovol_placeholder = input(true, title="==== Historical Vol ====")
- lengthHV = input(20, minval=1)
- hvValue = input(20, title="When HV is below")
- // annual = 252
- // per = timeframe.isintraday or timeframe.isdaily and timeframe.multiplier == 1 ? 1 : 7
- hv = 100*stdev(log(close / close[1]), lengthHV) * sqrt(252/7)
- len = input(7, minval=1, title="Length")
- src = input(close, title="Source")
- smma = 0.0
- smma := na(smma[1]) ? sma(src, len) : (smma[1] * (len - 1) + src) / len
- // plot(sma(close,9), color=white)
- plot(ema(close,21), color=yellow)
- // slow its lower
- Gain = input(5,type=float)
- // signal
- Gain2 = input(50,type=float)
- //
- // src = input(close)
- dk = src - nz(kf[1],src)
- smooth = nz(kf[1],src)+dk*sqrt((Gain/10000)*2)
- velo = nz(velo[1],0) + ((Gain/10000)*dk)
- kf = smooth+velo
- //
- plot(kf,color=red,transp=0)
- //
- src2 = input(close)
- dk2 = src2 - nz(kf2[1],src2)
- smooth2 = nz(kf2[1],src)+dk2*sqrt((Gain2/10000)*2)
- velo2 = nz(velo2[1],0) + ((Gain2/10000)*dk2)
- kf2 = smooth2+velo2
- plot(kf2,color=purple,transp=0)
- // plot(kf2,color=purple,transp=0)
- // MACD Calculation
- MACD = ema(kf, fastMAlen) - ema(kf, slowMAlen)
- signalMACD = ema(MACD, signalMACDlen)
- delta = MACD - signalMACD
- fastMA = ema(kf,fastMAlen)
- slowMA = ema(kf,slowMAlen)
- // ————— Williams %R —————
- _nWIL_Len = input(defval=14, title=" ▪ Length", minval=1)
- wil_up = highest(_nWIL_Len)
- wil_lo = lowest(_nWIL_Len)
- will = 100 - (100 * (close - wil_up) / (wil_up - wil_lo) * -1)
- // plot(will,color=yellow,transp=0)
- // longCondition = crossover(ema(close,6),kf)
- dev = 2.5* stdev(hlc3, 10)
- longCondition = crossover(ema(close,6)+2*syminfo.mintick,kf)
- shortCondition = crossover(kf,ema(close,6)-2*syminfo.mintick)
- // and rsi(close,14)[1]<rsi(close,14)[0]
- // if (longCondition and rsi(close,14)[1]<rsi(close,14)[0] and atr(14)[1]<atr(14)[0])
- stop_level_l = strategy.position_avg_price * (1 - 0.001)
- stop_level_s = strategy.position_avg_price * (1 + 0.001)
- plot(kf2+dev , title="dev", color=green, linewidth=1)
- plot(kf2 -dev , title="dev", color=yellow, linewidth=1)
- afterStartDate = (time >= timestamp(syminfo.timezone, 2019, 02, 30, 0, 0))
- if (longCondition and afterStartDate )
- // strategy.entry("My Long Entry Id", strategy.long,stop=stop_level_l)
- strategy.entry("My Long Entry Id", strategy.long)
- // shortCondition = crossunder(sma(close, 14), sma(close, 28))
- // shortCondition = crossunder(ema(close,6),kf)
- // shortCondition = crossover(kf,sma(close,9))
- // shortCondition = crossover(ema(close,9),sma(close,21))
- // and rsi(close,14)[1]>rsi(close,14)[0]
- // if (shortCondition and rsi(close,14)[1]>rsi(close,14)[0] and atr(14)[1]<atr(14)[0])
- // if (crossover(kf2,ema(close,21)) and afterStartDate )
- // strategy.entry("My Short Entry Id", strategy.short,stop=stop_level_s )
- // strategy.entry("My Short Entry Id", strategy.short)
- // strategy.close_all()
- if (shortCondition and afterStartDate )
- // strategy.entry("My Short Entry Id", strategy.short,stop=stop_level_s )
- // strategy.entry("My Short Entry Id", strategy.short)
- strategy.close_all()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement