// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © saurabhlohiya //@version=4 strategy("PEERTRADING WITH MOVING AVEREAGE",overlay=true) ma_type=input(defval="EMA", title="MA Type: ", options=["SMA", "EMA"]) ma_len1 = input(defval=6, title="Length FOR MA CROSSOVER OF CURRENT SCRIPT", minval=1) s1=input(title="ENTER SYMBOL1",defval="TCS") u1=input(title="USE SYMBOL2 ",defval=false) s2=input(title="ENTER SYMBOL2",defval="TECHM") r=input(title="Resolution",type=input.resolution,defval="15") c1=security(s1,resolution=r,expression=close) c2=security(s2,resolution=r,expression=close) ma_len3 = input(defval=6, title="MA - Length FOR TREND OF REFFERENCE SCRIPT", minval=1) u4=input(defval=false,title="TRADE ONLY INTRADAY") et=input(defval="0915-1510",title="INTRADAY TRADE SESSION",type=input.session) st=input(defval="1515-1530",title="INTRADAY EXIT BETWEEN",type=input.session) u2=input(title="USE TARGET",defval=false) t=input(title="TARGET IN RS",defval=10.0) t:=t/syminfo.mintick u3=input(title="USE STOPLOSS",defval=false) s=input(title="STOPLOSS IN RS",defval=10.0) s:=s/syminfo.mintick variant(type, src, len) => type=="EMA" ? ema(src,len):sma(src,len) // === Moving Average calculation ma_series1 = variant(ma_type,close,ma_len1) ma_series3 = variant(ma_type,c1,ma_len3) ma_series4 = variant(ma_type,c2,ma_len3) p2lcond=false p2scond=false if(u1==false) p2lcond:=true p2lcond:=true p1d=0 p2d=0 if(c1>ma_series3) p1d:=1 if(c1ma_series4) p2lcond:=true if(c20) strategy.entry('sell',strategy.short,comment=lxse) if(u4==false) if(long and strategy.position_size==0) strategy.entry('buy',strategy.long,comment=le) if(short and strategy.position_size==0) strategy.entry('sell',strategy.short,comment=se) if(long and strategy.position_size<0) strategy.entry('buy',strategy.long,comment=sxle) if(short and strategy.position_size>0) strategy.entry('sell',strategy.short,comment=lxse) //stoploss and target if(u2==true and u3==false) strategy.exit(id="LX",from_entry='buy',profit=t,comment=lx) strategy.exit(id='SX',from_entry='sell',profit=t,comment=sx) if(u3==true and u2==false) strategy.exit(id='LX',from_entry='buy',loss=s,comment=lx) strategy.exit(id='SX',from_entry='sell',loss=s,comment=sx) if(u2==true and u3==true) strategy.exit(id='LX',from_entry='buy',profit=t,loss=s,comment=lx) strategy.exit(id='SX',from_entry='sell',profit=t,loss=s,comment=sx) if(time(timeframe.period,st) and u4==true) strategy.close("buy",comment=lx) strategy.close("sell",comment=sx)