xmd79

Sine Wave Trading

Mar 19th, 2023
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. //@version=5
  2. strategy("Sine Wave Trading", overlay=true)
  3.  
  4. // Input parameters
  5. fast_period = input.int(5, "Fast Period", minval=1)
  6. slow_period = input.int(34, "Slow Period", minval=1)
  7. displace = input.int(0, "Displace", minval=-500, maxval=500)
  8.  
  9. // Compute sine wave
  10. sine = ta.sine(close, fast_period, slow_period, displace)
  11.  
  12. // Plot sine wave and buy/sell signals
  13. plot(sine, color=color.blue, linewidth=2)
  14. buy_signal = crossover(close, sine)
  15. sell_signal = crossunder(close, sine)
  16. plotshape(buy_signal, style=shape.triangleup, location=location.belowbar, color=color.green)
  17. plotshape(sell_signal, style=shape.triangledown, location=location.abovebar, color=color.red)
  18.  
  19. // Compute account balance and trade size
  20. balance = strategy.netprofit + strategy.equity
  21. position_size = balance / close
  22.  
  23. // Check if asset is at dip or top on all timeframes
  24. is_dip_1min = ta.lowest(close, 20) == close
  25. is_top_1min = ta.highest(close, 20) == close
  26. is_dip_5min = ta.lowest(close, 100) == close
  27. is_top_5min = ta.highest(close, 100) == close
  28. is_dip_1h = ta.lowest(close, 600) == close
  29. is_top_1h = ta.highest(close, 600) == close
  30.  
  31. // Entry and exit logic
  32. if buy_signal and is_dip_1min and is_dip_5min and is_dip_1h
  33. strategy.entry("long", strategy.long, qty=position_size)
  34. strategy.exit("exit", "long", profit=ta.highest(sine, 60), loss=ta.lowest(sine, 60))
  35.  
  36. if sell_signal and is_top_1min and is_top_5min and is_top_1h
  37. strategy.entry("short", strategy.short, qty=position_size)
  38. strategy.exit("exit", "short", profit=ta.lowest(sine, 60), loss=ta.highest(sine, 60))
  39.  
Advertisement
Add Comment
Please, Sign In to add comment