Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © dravitch
- //@version=4
- strategy("RSI Golden Cross Strategy", overlay=true, pyramiding=1, commission_type=strategy.commission.percent, commission_value=0.02, initial_capital=1000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)
- // Inputs
- rsi_length = input(14)
- rsi_oversold = input(20)
- rsi_overbought = input(90)
- fast_ma = input(50)
- slow_ma = input(200)
- // Variables
- var float rsi = na
- var bool bullish_cross = false
- var bool bearish_cross = false
- // Calculate indicators
- rsi := rsi(close, rsi_length)
- fast_sma = sma(close, fast_ma)
- slow_sma = sma(close, slow_ma)
- bullish_cross := crossover(fast_sma, slow_sma)
- bearish_cross := crossunder(fast_sma, slow_sma)
- // Trading strategy
- if (strategy.equity > 0)
- if (rsi < rsi_oversold) or bullish_cross
- strategy.entry("long", strategy.long)
- if bearish_cross
- strategy.close("long")
- if bearish_cross or rsi > rsi_overbought
- strategy.close("long")
- // Plots
- //plot(rsi, color=color.blue, title="RSI", linewidth=2)
- p1 = plot(fast_sma, color=color.purple, title="Fast SMA", linewidth=2)
- p2 = plot(slow_sma, color=color.blue, title="Slow SMA", linewidth=2)
- fill(p1, p2, (rsi < rsi_oversold and bullish_cross) or bearish_cross ? na : color.new(color.green, 70))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement