Created
May 26, 2021 00:10
-
-
Save sudoaza/a8dea1fa52e168d20b0a9b9c32a7300f to your computer and use it in GitHub Desktop.
Double RSI PineScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ | |
// © sudoaza | |
//@version=4 | |
strategy("Double RSI") | |
// Fix the backtest graph | |
order_size = round(1 / close[1]) | |
// Define RSI functions | |
_fast_rsi = rsi(close, 7) | |
_slow_rsi = rsi(close, 7) | |
// Calculate RSI series | |
fast_rsi = security(syminfo.tickerid, '3', _fast_rsi) | |
slow_rsi = security(syminfo.tickerid, '60', _slow_rsi) | |
// RSI Conditions | |
// Fast (short period) RSI is BUY | |
fast_ok = fast_rsi < 50 | |
// Slow (long period) RSI is RANGING | |
slow_ok = (slow_rsi < 70) and (slow_rsi > 20) | |
plot(slow_rsi, "Slow RSI", slow_ok ? color.blue : color.purple) | |
plot(fast_rsi, "Fast RSI", fast_ok ? color.yellow : color.orange) | |
// Price is going up | |
fast_close = security(syminfo.tickerid, '3', close) | |
rising = rising(fast_close, 2) | |
// All conditions met | |
buy = slow_ok and fast_ok and rising | |
plot(buy ? 100 : 0, "Buy", color=buy ? color.green : color.red) | |
// Prices vary this much | |
atr = atr(14) | |
atr_1hour = security(syminfo.tickerid, '3', atr) | |
if (buy) | |
take_profit = high + atr | |
stop_loss = max(low - atr * 2, low * 0.98) | |
// TODO there is an issue here, when the exit is not met for the previous buy | |
// it changes the exit to the new one. Maybe set a flag on entry/exit | |
strategy.entry("long", strategy.long, order_size) | |
strategy.exit("exit", "long", stop=stop_loss, limit=take_profit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment