// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © yashp1334 //@version=4 //@version=4 strategy("Log x", overlay=false) //have to use security function to calculate logarithm properly O = security(syminfo.tickerid, timeframe.period, log(open)) H = security(syminfo.tickerid, timeframe.period, log(high)) L = security(syminfo.tickerid, timeframe.period, log(low)) C = security(syminfo.tickerid, timeframe.period, log(close)) plotcandle(O, H, L, C, color=open < close ? color.green : color.red, wickcolor=color.black) // Getting inputs z_length = input(title="z Length", type=input.integer, defval=50) src = input(title="Source", type=input.source, defval=close) sma_source = input(title="Simple MA", type=input.bool, defval=false) // Calculating sma_1 = sma(src, z_length) ema_1 = ema(src, z_length) z_ma = sma_source ? sma_1 : ema_1 x = log(z_ma) plot(x, title="x", color=C >= x ? color.blue : color.red, linewidth=3) lookBack =input(100) multi = input(2, title="Multiplier", minval=0.001, maxval=2) mean = ema(x, lookBack) stddev = multi * stdev(x, lookBack) b = mean + stddev A = mean - stddev buySignal = crossover(x, A) sellSignal = crossunder(x, b) meanp = plot(mean, title="Mean Price", color=color.gray) //INTRADAY s=input(title="INTRA DAY TRADE SESSION",type=input.session,defval="0915-1450") st=time(timeframe.period,s) e=input(title="END SESSION",type=input.session,defval="1515-1520") et=time(timeframe.period,e) quant=input(title="Trade Quantity",defval=1) //adding stoploss and target option ut=input(defval=false,title="USE TARGET") us=input(defval=false,title="USE STOPLOSS") tar=input(defval=10.0,title="TARGET IN RS") stop=input(defval=7.0,title="STOP LOSS IN RS") tar:=tar/syminfo.mintick stop:=stop/syminfo.mintick //setting automated alerts required by apibridge lxse="TYPE: LX" + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) + " :TYPE:SE " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) sxle="TYPE: SX" + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) + " :TYPE:LE " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) le="TYPE:LE " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) lx="TYPE:LX " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) se="TYPE:SE " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) sx="TYPE:SX " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) if(buySignal and st and strategy.position_size==0) strategy.entry("BUY",strategy.long,comment=le) if(sellSignal and st and strategy.position_size==0) strategy.entry("SELL",strategy.short,comment=se) if(buySignal and st and strategy.position_size!=0) strategy.entry("BUY",strategy.long,comment=sxle) if(sellSignal and st and strategy.position_size!=0) strategy.entry("SELL",strategy.short,comment=lxse) if(ut==true and us==false) strategy.exit(id="LX",from_entry="BUY",profit=tar,comment=lx) strategy.exit(id="SX",from_entry="SELL",profit=tar,comment=sx) if(us==true and ut==false) strategy.exit(id="LX",from_entry="BUY",loss=stop,comment=lx) strategy.exit(id="SX",from_entry="SELL",loss=stop,comment=sx) if(ut==true and us==true) strategy.exit(id="LX",from_entry="BUY",profit=tar,loss=stop,comment=lx) strategy.exit(id="SX",from_entry="SELL",profit=tar,loss=stop,comment=sx) strategy.close(id="BUY",when=et,comment=lx) strategy.close(id="SELL",when=et,comment=sx) bsign = plot(b, title="Upper Deviation Line", color=color.green, linewidth=2) ssign = plot(A, title="Lower Deviation Line", color=color.red, linewidth=2) fill(bsign, meanp, title="Upper Deviation fill", color=color.green) fill(meanp, ssign, title="Lower Deviation fill", color=color.red)