Created
November 6, 2023 20:03
-
-
Save iCodeForBananas/d71d6b79f6cf43f5636fcd5d1c1ab313 to your computer and use it in GitHub Desktop.
Broken highs/lows in trend
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("New Strategy", overlay=true, initial_capital = 5000, default_qty_value = 25, pyramiding = 4, default_qty_type= strategy.percent_of_equity) | |
FromMonth=input.int(defval=1,title="FromMonth",minval=1,maxval=12, group = 'Time filters') | |
FromDay=input.int(defval=1,title="FromDay",minval=1,maxval=31, group = 'Time filters') | |
FromYear=input.int(defval=2000,title="FromYear",minval=1990, group = 'Time filters') | |
ToMonth=input.int(defval=1,title="ToMonth",minval=1,maxval=12, group = 'Time filters') | |
ToDay=input.int(defval=1,title="ToDay",minval=1,maxval=31, group = 'Time filters') | |
ToYear=input.int(defval=9999,title="ToYear",minval=2017, group = 'Time filters') | |
start=timestamp(FromYear,FromMonth,FromDay,00,00) | |
finish=timestamp(ToYear,ToMonth,ToDay,23,59) | |
window()=>time>=start and time<=finish?true:false | |
afterStartDate = time >= start and time<=finish?true:false | |
closeTradesEOD = input.bool(false, 'Close trades end of day', group = 'Time filters') | |
fastMALength = input(15 , 'Fast MA length', group = 'Trend strength') | |
fastEMAEnabled = input.bool(false, 'Fast EMA enabled (default is SMA)', group = 'Trend strength') | |
slowMALength = input(20, 'Slow MA length', group = 'Trend strength') | |
slowEMAEnabled = input.bool(false, 'Slow EMA enabled (default is SMA)', group = 'Trend strength') | |
longsEnabled = input.bool(true, 'Enable longs', group = 'Trade settings') | |
shortsEnabled = input.bool(true, 'Enable shorts', group = 'Trade settings') | |
fastMA = fastEMAEnabled ? ta.ema(close, fastMALength) : ta.sma(close, fastMALength) | |
slowMA = slowEMAEnabled ? ta.ema(close, slowMALength) : ta.sma(close, slowMALength) | |
isGreenCandle = close > open | |
isRedCandle = close < open | |
isBrokenHigh = close > open[1] | |
isPriorCandleRed = close[1] < open[1] | |
isPriorPriorCandleRed = close [2] < open[2] | |
isPriorCandleGreen = close[1] > open[1] | |
isBrokenLow = close < open[1] | |
longOpenCondition = isGreenCandle and isPriorCandleRed and isBrokenHigh and afterStartDate and fastMA > slowMA and close > fastMA and longsEnabled | |
longCloseCondition = ta.crossunder(close, fastMA) | |
shortOpenCondition = isRedCandle and isPriorCandleGreen and isBrokenLow and afterStartDate and fastMA < slowMA and close < fastMA and shortsEnabled | |
shortCloseCondition = ta.crossover(close, fastMA) | |
if (longOpenCondition) | |
strategy.entry("Long Entry", strategy.long) | |
if (longCloseCondition) | |
strategy.close('Long Entry', 'Long Exit') | |
if (shortOpenCondition) | |
strategy.entry("Short Entry", strategy.long) | |
if (shortCloseCondition) | |
strategy.close('Short Entry', 'Short Exit') | |
if (closeTradesEOD and hour >= 14 and minute >= 30) | |
strategy.close_all("EOD") | |
plot(fastMA) | |
plot(slowMA, linewidth = 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment