This strategy utilizes the crossover signals of the Stochastic Oscillator to trigger buy and sell operations. When the %K line crosses above the %D line and the %K value is below 20, it opens a long position; when the %K line crosses below the %D line and the %K value is above 80, it opens a short position. Additionally, the strategy sets take profit and stop loss distances to manage positions and prevent the expansion of losses. Moreover, the strategy also sets logical conditions to close positions. When the Stochastic Oscillator shows a crossover signal opposite to the opening signal, it will close the corresponding long or short position even if the take profit or stop loss price has not been reached.
The bidirectional stop-loss take-profit strategy based on Stochastic crossover is a simple and easy-to-understand quantitative trading strategy. It triggers buy and sell operations through the crossover signals of the Stochastic Oscillator and sets take profit/stop loss and logical conditions for closing positions to manage risks. The advantage of this strategy is that the logic is clear and suitable for beginners to learn and use; however, it also has some risks, such as the Stochastic Oscillator may generate many false signals in a choppy market, and fixed position management methods may not adapt to different market conditions. To further improve the performance of the strategy, we can consider introducing other indicators, optimizing position management, parameter optimization, and adding filtering conditions. In general, this strategy can serve as a basic quantitative trading strategy template, and through continuous optimization and improvement, it is expected to achieve good results in actual trading.
/*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")template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6