Skip to content

Instantly share code, notes, and snippets.

@pathnirvana
Created April 11, 2022 09:45
Show Gist options
  • Save pathnirvana/769e3b5e575f3009ed38724cd68bfd43 to your computer and use it in GitHub Desktop.
Save pathnirvana/769e3b5e575f3009ed38724cd68bfd43 to your computer and use it in GitHub Desktop.
// 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