Created
November 21, 2023 15:03
-
-
Save iCodeForBananas/fa1b7faa84a324ac7e139c47e5fbe955 to your computer and use it in GitHub Desktop.
MACD w/ Stop EMA [iCodeForBananas]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@version=5 | |
strategy("MACD w/ Stop EMA [iCodeForBananas]", overlay=true, initial_capital = 5000, default_qty_value = 10, pyramiding = 0, default_qty_type= strategy.percent_of_equity, slippage=1, process_orders_on_close=true) | |
fastlen = input(4, 'Fast length', group = 'Entry') | |
slowlen = input(10, 'Slow length', group = 'Entry') | |
siglen = input(4, 'Signal length', group = 'Entry') | |
trailStopMALength = input(200, 'Trail stop EMA length', group = 'Exit') | |
trailStopQtyPercent = input(100, 'Stop quantity %', group = 'Exit') | |
[macdLine, signalLine, histLine] = ta.macd(close, fastlen, slowlen, siglen) | |
trailStopMA = ta.ema(close, trailStopMALength) | |
longEntryCondition = ta.crossover(macdLine, signalLine) | |
longExitCondition = ta.crossunder(close, trailStopMA) | |
if (longEntryCondition) | |
strategy.entry("LE", strategy.long) | |
if (longExitCondition) | |
strategy.close('LE', 'LX', qty_percent = trailStopQtyPercent) | |
plot(trailStopMA, linewidth = 1, color = color.red) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment