Skip to content

Instantly share code, notes, and snippets.

@jtlimson
Created May 1, 2022 08:03
Show Gist options
  • Save jtlimson/ca452e3d3bb78a0b66f23d7b3b6678fe to your computer and use it in GitHub Desktop.
Save jtlimson/ca452e3d3bb78a0b66f23d7b3b6678fe to your computer and use it in GitHub Desktop.
tradingview bot trade strategy.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © contentPie
//@version=4
strategy("My script", overlay=true, initial_capital = 100000, default_qty_value = 100, default_qty_type = strategy.percent_of_equity, commission_value=0.025)
fastEMA = ema(close, 24)
fastSMA = sma(close, 24);
slowEMA = ema(close, 200)
atr = atr(14)
goLongCondition1 = fastEMA > fastSMA
goLongCondition2 = fastEMA > slowEMA
exitCondition1 = fastEMA < fastSMA
exitCondition2 = close < slowEMA
inTrade = strategy.position_size > 0
notInTrade = strategy.position_size <= 0
timePeriod = time >= timestamp(syminfo.timezone, 2020,12,15,0,0)
if (timePeriod and goLongCondition1 and goLongCondition2 and notInTrade)
strategy.entry("long", strategy.long, when=notInTrade)
stopLoss = close - atr * 3
strategy.exit("exit", "long", stop=stopLoss)
if (exitCondition1 and exitCondition2 and inTrade)
strategy.close(id="long")
plot(fastEMA, color=color.blue)
plot(slowEMA, color=color.yellow)
bgcolor(notInTrade ? color.red : color.green)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment