Skip to content

Instantly share code, notes, and snippets.

@saleh-old
Created June 9, 2020 07:59
Show Gist options
  • Save saleh-old/7569cad1b10dee874c494ee4a47d9120 to your computer and use it in GitHub Desktop.
Save saleh-old/7569cad1b10dee874c494ee4a47d9120 to your computer and use it in GitHub Desktop.
def go_long(self):
# entry: the high of the current candle
entry = self.high
stop = entry - ta.atr(self.candles)*3
qty = utils.risk_to_qty(self.capital, 5, entry, stop)
last_20_highs = self.candles[-20:, 3]
previous_high = np.max(last_20_highs)
self.buy = qty, entry
self.stop_loss = qty, stop
# (first) take-profit: the high of the last 20 candles
self.take_profit = qty/2, previous_high
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment