Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- strategy("Sine Wave Trading", overlay=true)
- // Input parameters
- fast_period = input.int(5, "Fast Period", minval=1)
- slow_period = input.int(34, "Slow Period", minval=1)
- displace = input.int(0, "Displace", minval=-500, maxval=500)
- // Compute sine wave
- sine = ta.sine(close, fast_period, slow_period, displace)
- // Plot sine wave and buy/sell signals
- plot(sine, color=color.blue, linewidth=2)
- buy_signal = crossover(close, sine)
- sell_signal = crossunder(close, sine)
- plotshape(buy_signal, style=shape.triangleup, location=location.belowbar, color=color.green)
- plotshape(sell_signal, style=shape.triangledown, location=location.abovebar, color=color.red)
- // Compute account balance and trade size
- balance = strategy.netprofit + strategy.equity
- position_size = balance / close
- // Check if asset is at dip or top on all timeframes
- is_dip_1min = ta.lowest(close, 20) == close
- is_top_1min = ta.highest(close, 20) == close
- is_dip_5min = ta.lowest(close, 100) == close
- is_top_5min = ta.highest(close, 100) == close
- is_dip_1h = ta.lowest(close, 600) == close
- is_top_1h = ta.highest(close, 600) == close
- // Entry and exit logic
- if buy_signal and is_dip_1min and is_dip_5min and is_dip_1h
- strategy.entry("long", strategy.long, qty=position_size)
- strategy.exit("exit", "long", profit=ta.highest(sine, 60), loss=ta.lowest(sine, 60))
- if sell_signal and is_top_1min and is_top_5min and is_top_1h
- strategy.entry("short", strategy.short, qty=position_size)
- strategy.exit("exit", "short", profit=ta.lowest(sine, 60), loss=ta.highest(sine, 60))
Advertisement
Add Comment
Please, Sign In to add comment