该策略利用随机指标(Stochastic Oscillator)的交叉信号来触发买卖操作。当随机指标中的%K线从下向上穿过%D线,并且%K值低于20时,开仓做多;当%K线从上向下穿过%D线,并且%K值高于80时,开仓做空。同时,策略设置了止盈(Take Profit)和止损(Stop Loss)距离来管理仓位,避免亏损扩大。此外,该策略还设置了逻辑条件来平仓,当随机指标出现与开仓信号相反的交叉信号时,即使没有达到止盈止损价格,也会平掉相应的多头或空头仓位。
基于随机指标交叉的双向止盈止损策略是一个简单易懂的量化交易策略,通过随机指标的交叉信号来触发买卖操作,并设置止盈止损和逻辑条件平仓来管理风险。该策略的优势在于逻辑清晰,适合初学者学习和使用;但同时也存在一些风险,如随机指标在震荡市场中可能发出较多误差信号,固定的仓位管理方式可能无法适应不同的市场状况等。为了进一步提升策略的表现,可以考虑引入其他指标、优化仓位管理、参数优化以及加入过滤条件等方面进行改进。总的来说,该策略可以作为一个基础的量化交易策略模板,通过不断的优化和改进,有望在实际交易中取得良好的效果。
/*backtest start: 2024-02-29 00:00:00 end: 2024-03-07 00:00:00 period: 10m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("How to force strategies fire exit alerts not reversals", initial_capital = 1000, slippage=1, commission_type = strategy.commission.cash_per_contract, commission_value = 0.0001, overlay=true) // disclaimer: this content is purely educational, especially please don't pay attention to backtest results on any timeframe/ticker // Entries logic: based on Stochastic crossover k = ta.sma(ta.stoch(close, high, low, 14), 3) d = ta.sma(k, 3) crossover = ta.crossover(k,d) crossunder = ta.crossunder(k,d) if (crossover and k < 20) strategy.entry("Buy", strategy.long, alert_message="buy") if (crossunder and k > 80) strategy.entry("Sell", strategy.short, alert_message="sell") // StopLoss / TakeProfit exits: SL = input.int(600, title="StopLoss Distance from entry price (in Ticks)") TP = input.int(1200, title="TakeProfit Distance from entry price (in Ticks)") strategy.exit("xl", from_entry="Buy", loss=SL, profit=TP, alert_message="closebuy") strategy.exit("xs", from_entry="Sell", loss=SL, profit=TP, alert_message="closesell") // logical conditions exits: if (crossunder and k <= 80) strategy.close("Buy", alert_message="closebuy") if (crossover and k >= 20) strategy.close("Sell", alert_message="closesell")