Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study("MACD", overlay=true)
- // --------- Variables --------- //
- var fastemaperiod = 8.3896
- var slowemaperiod = 17.5185
- var signalemaperiod = 9.0503
- // Formula expressions
- var ex1 = (fastemaperiod-slowemaperiod)*2
- var ex1a = signalemaperiod+1.0
- var ex2 = 1.0-(2.0/ex1a)
- var ex3 = fastemaperiod+1.0
- var ex4 = slowemaperiod+1.0
- var ex5 = (2.0/ex1a)-1.0
- // --------- Functions --------- //
- floatema(pprice, pperiod) =>
- alpha = 2 / (pperiod + 1)
- ema = 0.0
- ema := alpha * pprice + (1 - alpha) * nz(ema[1])
- ema
- roundmultiplier() =>
- int start = 1
- for i = 0 to 100
- start := (start*10)
- if(int(nz(syminfo.mintick*start)) == 0)
- continue
- break
- start
- var multiplier = roundmultiplier()
- showpredictedprice(pprice, pcolor, pshowlabel) =>
- fastema = floatema(close, fastemaperiod)
- slowema = floatema(close, slowemaperiod)
- signalema = floatema((fastema - slowema), signalemaperiod)
- predictedprice = (-1.0)*((1.0/(ex1*ex2))*(ex3*(ex4*(ex5*(fastema[0]*(1.0-(2.0/ex3))-(slowema[0]*(1.0-(2.0/ex4))))+(signalema[0]*ex2)))))
- predictedprice := (round(predictedprice*multiplier)/multiplier)
- predictedtime = (time + (time - time[1]))
- labelstyle = pprice < predictedprice ? label.style_labeldown : label.style_labelup
- if(pshowlabel)
- _label = label.new(predictedtime, predictedprice, xloc=xloc.bar_time, text=tostring(predictedprice), textcolor=color.white, color=pcolor, style=labelstyle)
- label.delete(_label[1])
- _line = line.new(time, pprice, predictedtime, predictedprice, xloc=xloc.bar_time, color=pcolor, width=2)
- line.delete(_line[1])
- _line
- // --------- Calulations --------- //
- fastema = floatema(close, fastemaperiod)
- slowema = floatema(close, slowemaperiod)
- signalema = floatema((fastema - slowema), signalemaperiod)
- // Predictor calculation
- predictor = (-1.0)*((1.0/(ex1*ex2))*(ex3*(ex4*(ex5*(fastema[1]*(1.0-(2.0/ex3))-(slowema[1]*(1.0-(2.0/ex4))))+(signalema[1]*ex2)))))
- // Predict price for the next bar
- showpredictedprice(predictor, color.red, true)
- // --------- Plots --------- //
- plot(predictor, color=color.red, transp=0, linewidth=2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement