// 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 // 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=3 strategy(title = "Combined Strategy", default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type=strategy.commission.percent, commission_value = .0020, pyramiding = 0, slippage = 3, overlay = true) //----------// // MOMENTUM // //----------// ema8 = ema(close, 8) ema13 = ema(close, 13) ema21 = ema(close, 21) ema34 = ema(close, 34) ema55 = ema(close, 55) plot(ema8, color=color.red, title="8", linewidth=1) plot(ema13, color=color.orange, title="13", linewidth=1) plot(ema21, color=color.yellow, title="21", linewidth=1) plot(ema34, color=color.aqua, title="34", linewidth=1) plot(ema55, color=color.lime, title="55", linewidth=1) longEmaCondition = ema8 > ema13 and ema13 > ema21 and ema21 > ema34 and ema34 > ema55 exitLongEmaCondition = ema13 < ema55 shortEmaCondition = ema8 < ema13 and ema13 < ema21 and ema21 < ema34 and ema34 < ema55 exitShortEmaCondition = ema13 > ema55 // ---------- // // OSCILLATORS // // ----------- // rsi = rsi(close, 14) longRsiCondition = rsi < 70 and rsi > 40 exitLongRsiCondition = rsi > 70 shortRsiCondition = rsi > 30 and rsi < 60 exitShortRsiCondition = rsi < 30 // Stochastic length = 14, smoothK = 3, smoothD = 3 kFast = stoch(close, high, low, 14) dSlow = sma(kFast, smoothD) longStochasticCondition = kFast < 80 exitLongStochasticCondition = kFast > 95 shortStochasticCondition = kFast > 20 exitShortStochasticCondition = kFast < 5 //----------// // STRATEGY // //----------// longCondition = longEmaCondition and longRsiCondition and longStochasticCondition and strategy.position_size == 0 exitLongCondition = (exitLongEmaCondition or exitLongRsiCondition or exitLongStochasticCondition) and strategy.position_size != 0 shortCondition = shortEmaCondition and shortRsiCondition and shortStochasticCondition and strategy.position_size == 0 exitShortCondition = (exitShortEmaCondition or exitShortRsiCondition or exitShortStochasticCondition) and strategy.position_size != 0 //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(longCondition and strategy.position_size==0) strategy.entry("BUY",strategy.long,comment=le) if(exitLongCondition and st and strategy.position_size!=0) strategy.close("BUY",comment=lx) if(shortCondition and strategy.position_size==0) strategy.entry("SELL",strategy.short,comment=se) if(exitShortCondition and st and strategy.position_size!=0) strategy.close("SELL",comment=sx) 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)