Created
April 11, 2022 09:45
-
-
Save pathnirvana/769e3b5e575f3009ed38724cd68bfd43 to your computer and use it in GitHub Desktop.
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/ | |
// © janaka | |
//@version=5 | |
strategy("My script", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10) | |
shortSMA = ta.sma(close, 11) | |
longSMA = ta.sma(close, 30) | |
trendSMA = ta.sma(close, 200) | |
rsi = ta.rsi(close, 14) | |
atr = ta.atr(14) | |
longCondition = ta.crossover(shortSMA, longSMA) and trendSMA < close | |
shortCondition = ta.crossunder(shortSMA, longSMA) and trendSMA > close | |
if (longCondition) | |
stopLoss = low - atr * 1 | |
takeProfit = high + atr * 2 | |
strategy.entry("long", strategy.long, when = rsi > 50) | |
strategy.exit("exit", "long", stop=stopLoss, limit=takeProfit) | |
if (shortCondition) | |
stopLoss = high + atr * 1 | |
takeProfit = low - atr * 2 | |
strategy.entry("short", strategy.short, when = rsi < 50) | |
strategy.exit("exit", "short", stop=stopLoss, limit=takeProfit) | |
plot(shortSMA) | |
plot(longSMA, color=color.navy) | |
plot(trendSMA, color=color.green) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment