Skip to content

Instantly share code, notes, and snippets.

@doorbash
Last active December 19, 2020 02:21
Show Gist options
  • Save doorbash/ee5c68dabbf1bef743b2939d8040735f to your computer and use it in GitHub Desktop.
Save doorbash/ee5c68dabbf1bef743b2939d8040735f to your computer and use it in GitHub Desktop.
//@version=2
// author: Milad Doorbash
strategy("Bitfinex Greed Level + RSI Strategy")
sym = input(title="Symbol", defval="BTCUSD", type=string)
greedChange = input(0.4, title="Greed Change")
greedLength = input(100, title="Greed SMA Length")
rsiHigh = input(70, title="RSI High")
rsiLow = input(30, title="RSI Low")
longs = security("BITFINEX:"+ sym +"LONGS", period, close)
shorts = security("BITFINEX:"+ sym +"SHORTS", period, close)
gr = longs * 100 / (longs + shorts)
greed = sma(gr, greedLength)
len = input(14, minval=1, title="RSI Length")
src = input(close, "Source")
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
c = gr > (greed + greedChange) ? #00ff00 :
gr < (greed - greedChange) ? #ff0000 : #000000
cb = rsi < rsiLow and gr > (greed + greedChange) ? #00ff00 :
rsi > rsiHigh and gr < (greed - greedChange) ? #ff0000 : na
bgcolor(cb, transp=75)
plot(gr, title='Bitfinex Greed Level', style=line, linewidth=2, color=c)
plot(greed, title='Bitfinex Greed Level (SMA)', style=line, linewidth=1, color=#0000ff)
if crossover(rsi, rsiLow) and gr > (greed + greedChange)
strategy.order("buy", strategy.long, comment="Buy")
if crossunder(rsi, rsiHigh) and gr < (greed - greedChange)
strategy.order("sell", strategy.short, comment="Sell")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment