//@version=4 strategy(title="RSI W Pattern strategy", pyramiding=2, shorttitle="RSI W Pattern", overlay = false, default_qty_type=strategy.fixed, default_qty_value=10000, initial_capital=100, currency=currency.USD ) len = input(title="RSI Period", minval=1, defval=5) buyRsiEntry = input(title="look for W pattern bottom edges well below RSI level (BUY) ", minval=10, defval=65, maxval=70) //numberOfBars = input(title="Number of Bars in W pattern ", minval=4, defval=4, maxval=6) emaL = input(title="Long Term EMA", minval=1, defval=50, maxval=200) emaS = input(title="Short Term EMA", minval=1, defval=20, maxval=200) stopLoss = input(title="Stop Loss %", minval=.01, defval=2, maxval=5, step=.01) //rsiWp1=false myRsi = rsi(close,len) //longEmaVal=ema(close,emaL) //shortEmaVal=ema(close,emaS) entryEma=ema(close,5) // This is used as filter for BUY isEma20AboveEma50=ema(close,emaS)>ema(close,emaL) ? true : false //W Pattern rsiWp1 = myRsi>myRsi[1] and myRsi>=30 and myRsi[1]myRsi[3] and myRsi[3]=30) patternText=" W " barcolor(longCondition?color.yellow:na) //initial entry strategy.entry("RSI_W_LE", comment="Buy" , long=true, when=longCondition ) //legging in to existing strategy.entry("RSI_W_LE",comment="Buy", long=true, when=strategy.position_size>0 and crossover(myRsi,10 )) //calculate stoploss value stopLossValue=strategy.position_avg_price - (strategy.position_avg_price*stopLoss/100) rsiPlotColor=longCondition ?color.yellow:color.purple plot(myRsi, title="RSI", linewidth=2, color=color.purple) // plot(myRsi, title="RSI", linewidth=2, color=rsiWp1?color.yellow:color.purple) //plot(myRsi[1], title="RSI", linewidth=2, color=rsiWp1==true?color.yellow:color.purple) //plot(myRsi[2], title="RSI", linewidth=2, color=rsiWp1?color.yellow:color.purple) //plot(myRsi[3], title="RSI", linewidth=2, color=rsiWp1?color.yellow:color.purple) //plot(myRsi[4], title="RSI", linewidth=2, color=rsiWp1?color.yellow:color.purple) hline(40, title="Middle Line", color=color.blue, linestyle=hline.style_dashed) obLevel = hline(75, title="Overbought", color=color.red, linestyle=hline.style_dashed) osLevel = hline(30, title="Oversold", color=color.purple, linestyle=hline.style_dashed) fill(obLevel, osLevel, title="Background", color=#9915FF, transp=90) plotshape( longCondition ? myRsi[1] : na, offset=-1, title="W Pattern", text=patternText, style=shape.labelup, location=location.absolute, color=color.purple, textcolor=color.yellow, transp=0 ) bgcolor(strategy.position_size>0?color.green:na, transp=40, title='In Long Position') //take profit or close when RSI reaches 75 takeProfit=crossover(myRsi,75) //close when RSi reaches profit level strategy.close("RSI_W_LE", comment="exit", qty=strategy.position_size,when=crossover(myRsi,75) and close>strategy.position_avg_price ) //close everything when stoploss hit longCloseCondition=close<(strategy.position_avg_price - (strategy.position_avg_price*stopLoss/100) ) //or crossunder(myRsi,30) strategy.close("RSI_W_LE", comment="Exit", qty=strategy.position_size,when=longCloseCondition)