Skip to content

Instantly share code, notes, and snippets.

@itsfreddyrb
Last active August 4, 2018 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsfreddyrb/92a4911954c3196a97050f181863be45 to your computer and use it in GitHub Desktop.
Save itsfreddyrb/92a4911954c3196a97050f181863be45 to your computer and use it in GitHub Desktop.
Estrategia Tradingview
//@version=3
strategy("My Strategy", overlay=true, currency=currency.USD, default_qty_type=strategy.cash, default_qty_value=4000)
//src = close, len = input(35)
//ema = ema(src,len)
//plot(ema,color = blue, linewidth = 2, style = line)
short = ema(close, 20)
medium = ema(close, 50)
long = ema(close, 200)
//plot(short, color = purple, linewidth = 2)
plot(long, color= red, linewidth = 2)
//plot(long, color = blue, linewidth = 2)
useStop = input(defval = true, title = "Use Trailing Stop?")
slPoints = input(defval = 50, title = "Stop Loss Trail Points", minval = 1)
slOffset = input(defval = 25, title = "Stop Loss Trail Offset", minval = 1)
//plot(cross(short, long) ? short : na, style = cross, color = white, linewidth = 4)
//plot(cross(short, medium) ? short: na, style = cross, color = orange, linewidth = 4)
//plot(cross(medium, long) ? medium: na, style = cross, color = teal, linewidth = 4)
longCondition = crossover(close, ema(close, 200))
if (longCondition)
strategy.entry("buy", strategy.long, when = close > high[1])
//strategy.exit("exit", "buy", trail_points = 10, loss = 50)
strategy.exit("exit-by-SL", from_entry = "buy", trail_points = slPoints, trail_offset = slOffset, loss = 70)
//strategy.close("buy", when = open > close)
shortCondition = crossunder(close, ema(close, 200))
if (shortCondition)
strategy.entry("sell", strategy.short, when = close < low[1])
strategy.exit("exit-by-SL", from_entry = "sell" ,trail_points = slPoints, trail_offset = slOffset, loss = 70)
// strategy.entry("My Short Entry Id", strategy.short)
// strategy.close("buy", when = open < close)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment