
이 전략은 무작위 지표 (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")