Advertisement
pasholnahuy

stochastic strat

May 30th, 2024
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. //@version=5
  2. strategy(title='my MACD strategy_1', overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
  3. fastLen = input(title='Fast Length', defval=7)
  4. slowLen = input(title='Slow Length', defval=14)
  5. sigLen = input(title='Signal Length', defval=4)
  6.  
  7. useDateFilter = input.bool(true, title="Filter Date Range of Backtest", group="Backtest Time Period")
  8. 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.")
  9. 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.")
  10.  
  11. inTradeWindow = not useDateFilter or (time >= backtestStartDate and time < backtestEndDate)
  12.  
  13. [macdLine, signalLine, _] = ta.macd(close, fastLen, slowLen, sigLen)
  14. plot(series=macdLine, color=color.new(color.blue, 0), linewidth=2)
  15. plot(series=signalLine, color=color.new(color.orange, 0), linewidth=2)
  16.  
  17. if ta.crossover(macdLine, signalLine) and inTradeWindow
  18.     strategy.entry(id='Entry Long', direction=strategy.long)
  19. if ta.crossunder(macdLine, signalLine) and inTradeWindow
  20.     strategy.entry(id='Entry Short', direction=strategy.short)
  21.  
  22. if not inTradeWindow
  23.     strategy.cancel_all()    
  24.     strategy.close_all()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement