
この戦略は,ランダムな指標 (((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")