Created
November 21, 2023 15:04
-
-
Save iCodeForBananas/83089b09f70da22eb46a1293067ab0f2 to your computer and use it in GitHub Desktop.
Broken High/Low Strategy [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("Broken High/Low Strategy [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) | |
trailStopMALength = input(200, 'Trail stop EMA length', group = 'Exit') | |
trailStopQtyPercent = input(100, 'Stop quantity %', group = 'Exit') | |
trailStopMA = ta.ema(close, trailStopMALength) | |
isGreenCandle = close > open | |
isRedCandle = close < open | |
isBrokenHigh = close > open[1] | |
isPriorCandleRed = close[1] < open[1] | |
isPriorPriorCandleRed = close[2] < open[2] | |
isPriorPriorCandleGreen = close[2] > open[2] | |
isPriorCandleGreen = close[1] > open[1] | |
isBrokenLow = close < open[1] | |
isPriorRedCandleBroken = isGreenCandle and isPriorCandleRed and isBrokenHigh | |
isPriorGreenCandleBroken = isRedCandle and isPriorCandleGreen and isBrokenLow | |
isPriorPriorRedCandleBroken = not isPriorRedCandleBroken and isGreenCandle and isPriorPriorCandleRed ? close > open[2] : false | |
isPriorPriorGreenCandleBroken = not isPriorGreenCandleBroken and isRedCandle and isPriorPriorCandleGreen ? close < open[2] : false | |
longOpenCondition = isPriorRedCandleBroken or isPriorPriorRedCandleBroken | |
longCloseCondition = ta.crossunder(close, trailStopMA) | |
if (longOpenCondition) | |
strategy.entry("Long Entry", strategy.long) | |
if (longCloseCondition) | |
strategy.close('Long Entry', 'Long Exit') | |
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