//@version=4 strategy(title="PSAR x", overlay=true) start = input(0.02) increment = input(0.02) maximum = input(0.2) c=close psar = sar(start, increment, maximum) cp = psar len = input(100, minval=1),off= 0,dev= input(1.9, "Deviation") lreg = linreg(cp, len, off), lreg_x =linreg(cp, len, off+1) b = bar_index, s = lreg - lreg_x,intr = lreg - b*s dS = 0.0 for i=0 to len-1 dS:= dS + pow(cp[i]-(s*(b-i)+intr), 2) de = sqrt(dS/(len)) up = (-de*dev) + psar down= (de*dev) + psar up_t = 0.0 up_t := c[1] > up_t[1] ? max(up, up_t[1]) : up down_t = 0.0 down_t := c[1] < down_t[1] ? min(down, down_t[1]) : down trend = 0 trend := c > down_t[1] ? 1: c < up_t[1] ? -1 : nz(trend[1], 1) // r_line = trend ==1 ? up_t : down_t plot(r_line) buy=crossover( c, r_line) sell=crossunder(c, r_line) plotshape(buy, style=shape.triangleup, size=size.small, location=location.belowbar, color=color.lime) plotshape(sell, style=shape.triangledown, size=size.small, location=location.abovebar, color=color.red) /////// Alerts ///// alertcondition(buy,title="buy") alertcondition(sell,title="sell") //INTRADAY AlgoJi s_a=input(title="INTRA DAY TRADE SESSION",type=input.session,defval="0915-1450") st=time(timeframe.period,s_a) e=input(title="END SESSION",type=input.session,defval="1515-1520") et=time(timeframe.period,e) quant=input(title="Trade Quantity",defval=1) //AlgoJi 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(buy and st and strategy.position_size==0) strategy.entry("BUY",strategy.long,comment=le) if(sell and st and strategy.position_size==0) strategy.entry("SELL",strategy.short,comment=se) if(buy and st and strategy.position_size!=0) strategy.entry("BUY",strategy.long,comment=sxle) if(sell 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)