Created
November 21, 2023 15:04
-
-
Save iCodeForBananas/8d566f61cd7bdc275048eb3d5faa5c94 to your computer and use it in GitHub Desktop.
Price Cross MA [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("Price Cross MA [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) | |
entryMALength = input(50, 'Trade entry EMA length', group = 'Entry') | |
trailStopMALength = input(150, 'Trail stop EMA length', group = 'Exit') | |
trailStopQtyPercent = input(100, 'Stop quantity %', group = 'Exit') | |
entryMA = ta.ema(close, entryMALength) | |
trailStopMA = ta.ema(close, trailStopMALength) | |
longEntryCondition = ta.crossover(close, entryMA) | |
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) | |
plot(entryMA, color = color.blue) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment