// 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 // 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 //Created by ChrisMoody //BarColor strategy for RSI-2 Paint Bars + 200SMA and 5 SMA strategy("_CM_RSI_2_HB_MA", overlay=false) src = close, //RSI Code up = rma(max(change(src), 0), 2) down = rma(-min(change(src), 0), 2) rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down)) rsi_up = rsi > 90 rsi_down = rsi < 10 //MovAvg's Code ma5 = sma(close,5) ma200= sma(close, 200) //Rules for Bar Colors isLongEntry() => close > ma200 and close < ma5 and rsi < 10 isLongExit() => close > ma200 and close[1] < ma5[1] and high > ma5 and ((close[1] > ma200[1] and close[1] < ma5[1] and rsi[1] < 10) or (close[2] > ma200[2] and close[2] < ma5[2] and rsi[2] < 10) or (close[3] > ma200[3] and close[3] < ma5[3] and rsi[3] < 10) or (close[4] > ma200[4] and close[4] < ma5[4] and rsi[4] < 10) ) isShortEntry() => close < ma200 and close > ma5 and rsi > 90 isShortExit() => close < ma200 and close[1] > ma5[1] and low < ma5 and ((close[1] < ma200[1] and close[1] > ma5[1] and rsi[1] > 90) or (close[2] < ma200[2] and close[2] > ma5[2] and rsi[2] > 90) or (close[3] < ma200[3] and close[3] > ma5[3] and rsi[3] > 90) or (close[4] < ma200[4] and close[4] > ma5[4] and rsi[4] > 90) ) //Rules For MA Colors col = ma5 >= ma200 ? color.lime : ma5 < ma200 ? color.red : na barcolor(isLongEntry() ? color.lime : na) barcolor(isLongExit() ? color.yellow : na) barcolor(isShortEntry() ? color.red : na) barcolor(isShortExit() ? color.yellow : na) plot(ma5, color=col, title="5 SMA", linewidth=3) plot(ma200, color=col, title="200 SMA", linewidth=3) //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(isLongEntry() and st and strategy.position_size==0) strategy.entry("BUY",strategy.long,comment=le) if(isLongExit() and st and strategy.position_size!=0) strategy.close("BUY",comment=lx) if(isShortEntry() and st and strategy.position_size==0) strategy.entry("SELL",strategy.short,comment=se) if(isShortExit() 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)