Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- strategy(title='my MACD strategy_1', overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
- fastLen = input(title='Fast Length', defval=7)
- slowLen = input(title='Slow Length', defval=14)
- sigLen = input(title='Signal Length', defval=4)
- useDateFilter = input.bool(true, title="Filter Date Range of Backtest", group="Backtest Time Period")
- backtestStartDate = input.time(timestamp("1 nov 2023"), title="Start Date", group="Backtest Time Period", tooltip="This start date is in the time zone of the exchange where the chart's instrument trades. It doesn't use the time zone of the chart or of your computer.")
- backtestEndDate = input.time(timestamp("10 May 2024"), title="End Date", group="Backtest Time Period", tooltip="This end date is in the time zone of the exchange where the chart's instrument trades. It doesn't use the time zone of the chart or of your computer.")
- inTradeWindow = not useDateFilter or (time >= backtestStartDate and time < backtestEndDate)
- [macdLine, signalLine, _] = ta.macd(close, fastLen, slowLen, sigLen)
- plot(series=macdLine, color=color.new(color.blue, 0), linewidth=2)
- plot(series=signalLine, color=color.new(color.orange, 0), linewidth=2)
- if ta.crossover(macdLine, signalLine) and inTradeWindow
- strategy.entry(id='Entry Long', direction=strategy.long)
- if ta.crossunder(macdLine, signalLine) and inTradeWindow
- strategy.entry(id='Entry Short', direction=strategy.short)
- if not inTradeWindow
- strategy.cancel_all()
- strategy.close_all()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement