Skip to content

Commit

Permalink
Added RSI a a check
Browse files Browse the repository at this point in the history
  • Loading branch information
oosswwaalldd committed Oct 14, 2021
1 parent e4ea331 commit 203a893
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// © Ossy1717

//@version=4
strategy("(Strategy) RSI + Stoch Divergences %SL/TP", overlay = true, max_bars_back = 1000, max_lines_count = 400, max_labels_count = 400, initial_capital = 1000, default_qty_value = 1000, default_qty_type = strategy.cash)
strategy("(Strategy) RSI Divergences %SL/TP", overlay = true, max_bars_back = 1000, max_lines_count = 400, max_labels_count = 400, initial_capital = 1000, default_qty_value = 1000, default_qty_type = strategy.cash)

// Inputs
onlyAPlus = input(defval = false, title = "Backtest Only A+ Setups?", tooltip="A+ is when all the divergerce occurs in the oversold/overbought area")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
// © Ossy1717

//@version=4
strategy("(Strategy) RSI + Stoch Divergences Trailing Stop", overlay = true, max_bars_back = 1000, max_lines_count = 400, max_labels_count = 400, initial_capital = 1000, default_qty_value = 1000, default_qty_type = strategy.cash)
strategy("(Strategy) RSI Divergences Trailing Stop", overlay = true, max_bars_back = 1000, max_lines_count = 400, max_labels_count = 400, initial_capital = 1000, default_qty_value = 1000, default_qty_type = strategy.cash)

// Inputs
onlyAPlus = input(defval = "All Setups", title = "Show Only A+ Setups", options = ["All Setups", "Only A+"], tooltip="Show only setups where RSI & Stoch are out of bands")
onlyAPlus = input(defval = false, title = "Backtest Only A+ Setups?", tooltip="A+ is when all the divergerce occurs in the oversold/overbought area")
tradeDirection = input(defval = "All", title = "Backtest Only Long, Only Shorts or All Setups?", options = ["All", "Longs", "Shorts"])
showTrailingStopLine = input(defval = "Yes", title = "Show Trailing Stop Line", options = ["Yes", "No"])
trailingStopPerc = input(defval = 2, title = "Stop Loss %", minval = 1, maxval = 100) / 100
trailingStopPerc = input(defval = 2, title = "Stop Loss %", minval = 0.5, step = 0.5, maxval = 100) / 100
checkRsiIndicator = input(defval = "Yes", title = "Check RSI Div Indicator", options = ["Yes", "No"])
lenFast = input(5, minval=1, title="Length Fast RSI")
lenSlow = input(14, minval=1, title="Length Slow RSI")
prd = input(defval = 5, title = "Pivot Period", minval = 1, maxval = 50)
source = input(defval = "Close", title = "Source for Pivot Points", options = ["Close", "High/Low"])
searchdiv = input(defval = "Regular", title = "Divergence Type", options = ["Regular", "Hidden", "Regular/Hidden"])
Expand Down Expand Up @@ -76,6 +80,23 @@ maFast = vwma(close, 12), maSlow = vwma(close, 26), vwmacd = maFast - maSlow //
Cmfm = ((close-low) - (high-close)) / (high - low), Cmfv = Cmfm * volume, cmf = sma(Cmfv, 21) / sma(volume,21) // Chaikin money flow
Mfi = mfi(close, 14) // Moneyt Flow Index

// RSI DIV Indicator
upFast = rma(max(change(close), 0), lenFast)
downFast = rma(-min(change(close), 0), lenFast)
rsiFast = downFast == 0 ? 100 : upFast == 0 ? 0 : 100 - (100 / (1 + upFast / downFast))
upSlow = rma(max(change(close), 0), lenSlow)
downSlow = rma(-min(change(close), 0), lenSlow)
rsiSlow = downSlow == 0 ? 100 : upSlow == 0 ? 0 : 100 - (100 / (1 + upSlow / downSlow))
//plotfast = plot(rsiFast, color=blue)
//plotslow = plot(rsiSlow, color=orange)
divergence = rsiFast - rsiSlow
isDivBullish = divergence > 0
isDivBearish = divergence < 0
// plotdiv = plot(divergence, color = divergence > 0 ? color.lime: color.red, linewidth = 2)
//band1 = hline(70,color=green)
//band0 = hline(30,color=red)
// band = hline(0)

// Calcs
co = crossover(k, d)
cu = crossunder(k, d)
Expand Down Expand Up @@ -388,15 +409,15 @@ for x = 0 to 10
if y == 0
isRsiOversold = rsi[startpoint] <= rsiOversold
isRsiComingFromOversold = rsi[barAmount] <= rsiOversold
if isRsiComingFromOversold
if ((onlyAPlus and isRsiComingFromOversold and isRsiOversold) or (not onlyAPlus and isRsiComingFromOversold) and (checkRsiIndicator == 'No' or (checkRsiIndicator == 'Yes' and isDivBullish)))
pos_reg_div_detected := true
signalTooltip = isRsiOversold ? "A+: Div In Oversold Zone" : "A: RSI NOT Oversold"
signalColor = isRsiOversold ? color.green : color.blue
label.new(x = x2 + 1, y = y2, yloc = yloc.belowbar, text="Long", textcolor=color.white, color = signalColor, style = label.style_label_up, size = size.small, tooltip=signalTooltip)
if y == 1
isRsiOverbought = rsi[startpoint] >= rsiOverbought
isRsiComingFromOverbought = rsi[barAmount] >= rsiOverbought
if isRsiComingFromOverbought
if (onlyAPlus and isRsiComingFromOverbought and isRsiOverbought) or (not onlyAPlus and isRsiComingFromOverbought)
neg_reg_div_detected := true
signalTooltip = isRsiOverbought ? "A+: Div In Overbought Zone" : "A: RSI NOT In Overbought Zone"
signalColor = isRsiOverbought ? color.red : color.orange
Expand Down Expand Up @@ -445,8 +466,8 @@ if showindis != "Don't Show" or shownum
// Conditions
timePeriod = time >= fromDate
notInTrade = strategy.position_size == 0
goLong = pos_reg_div_detected and notInTrade and timePeriod
goShort = neg_reg_div_detected and notInTrade and timePeriod
goLong = pos_reg_div_detected and notInTrade and timePeriod and (tradeDirection == "All" or tradeDirection == "Longs")
goShort = neg_reg_div_detected and notInTrade and timePeriod and (tradeDirection == "All" or tradeDirection == "Shorts")

// Determine trail stop loss prices
longStopPrice = 0.0, shortStopPrice = 0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// © Ossy1717

//@version=4
study("(Study) RSI + Stoch Divergences", overlay = true, max_bars_back = 1000, max_lines_count = 400, max_labels_count = 400)
study("(Study) RSI Divergences", overlay = true, max_bars_back = 1000, max_lines_count = 400, max_labels_count = 400)

// Inputs
onlyAPlus = input(defval = "All Setups", title = "Show Only A+ Setups", options = ["All Setups", "Only A+"], tooltip="Show only setups where RSI & Stoch are out of bands")
onlyAPlus = input(defval = false, title = "Show Only A+ Setups?", tooltip="A+ is when all the divergerce occurs in the oversold/overbought area")
showTrailingStopLine = input(defval = "Yes", title = "Show Trailing Stop Line", options = ["Yes", "No"])
trailingStopPerc = input(defval = 2, title = "Stop Loss %", minval = 1, maxval = 100) / 100
prd = input(defval = 5, title = "Pivot Period", minval = 1, maxval = 50)
Expand Down Expand Up @@ -388,15 +388,15 @@ for x = 0 to 10
if y == 0
isRsiOversold = rsi[startpoint] <= rsiOversold
isRsiComingFromOversold = rsi[barAmount] <= rsiOversold
if isRsiComingFromOversold
if (onlyAPlus and isRsiComingFromOversold and isRsiOversold) or (not onlyAPlus and isRsiComingFromOversold)
pos_reg_div_detected := true
signalTooltip = isRsiOversold ? "A+: Div In Oversold Zone" : "A: RSI NOT Oversold"
signalColor = isRsiOversold ? color.green : color.blue
label.new(x = x2 + 1, y = y2, yloc = yloc.belowbar, text="Long", textcolor=color.white, color = signalColor, style = label.style_label_up, size = size.small, tooltip=signalTooltip)
if y == 1
isRsiOverbought = rsi[startpoint] >= rsiOverbought
isRsiComingFromOverbought = rsi[barAmount] >= rsiOverbought
if isRsiComingFromOverbought
if (onlyAPlus and isRsiComingFromOverbought and isRsiOverbought) or (not onlyAPlus and isRsiComingFromOverbought)
neg_reg_div_detected := true
signalTooltip = isRsiOverbought ? "A+: Div In Overbought Zone" : "A: RSI NOT In Overbought Zone"
signalColor = isRsiOverbought ? color.red : color.orange
Expand Down

0 comments on commit 203a893

Please sign in to comment.