
이 전략은 무작위 진동 지표 (Stochastic Oscillator) 와 이동 평균 (Moving Average) 을 결합하여 시장의 과매매 및 과매매 상태를 판단하고 이동 평균의 추세 방향에 따라 거래 방향을 결정한다. 무작위 진동 지표가 과매 영역을 가로질러 올라가는 경우, 이동 평균이 상승 추세에있을 때, 전략은 다수 포지션을 열고; 무작위 진동 지표가 과매 영역을 가로질러 내려가는 경우, 이동 평균이 하향 추세에있을 때, 전략은 공백 포지션을 열고. 동시에, 전략은 손실을 통제하기 위해 스톱을 설정한다.
이 전략은 무작위적인 흔들림 지표와 이동 평균을 결합하여 시장의 과매매 과매매 상태를 포착하는 동시에 이동 평균의 추세 방향을 사용하여 거래 신호를 필터링하고 위험을 제어하기 위해 스톱을 설정합니다. 전략의 아이디어는 명확하고 이해하기 쉽고 구현됩니다. 그러나, 전략에는 지표 지연, 빈번한 거래와 같은 몇 가지 제한 사항이 있습니다.
/*backtest
start: 2024-04-22 00:00:00
end: 2024-04-29 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pablo_2uc
//@version=5
strategy("Estrategia Stoch + MA c/ SL", overlay=true)
// Parámetros del Estocástico
length = input.int(14, title="Longitud Estocástico")
smoothK = input.int(3, title="Suavizado K")
smoothD = input.int(3, title="Suavizado D")
oversold = input.int(20, title="Sobreventa")
overbought = input.int(80, title="Sobrecompra")
// Parámetros de la Media Móvil
maLength = input.int(9, title="Longitud MA")
maSource = input(close, title="Fuente MA")
// Capital inicial
capital = 500
// Tamaño de posición (10% del capital)
positionSize = 1
// Stop Loss (2% del precio de entrada)
stopLossPercent = input.int(2, title="Stop Loss (%)") / 100
// Cálculo del Estocástico
k = ta.sma(ta.stoch(close, high, low, length), smoothK)
d = ta.sma(k, smoothD)
// Cálculo de la Media Móvil
ma = ta.sma(maSource, maLength)
// Condiciones de entrada en largo y corto
longCondition = ta.crossunder(k, oversold) and ma > ma[1]
shortCondition = ta.crossover(k, overbought) and ma < ma[1]
// Condiciones de salida
exitLongCondition = ta.crossover(k, ma) and ma < ma[1]
exitShortCondition = ta.crossunder(k, ma) and ma > ma[1]
// Estrategia
if (longCondition)
strategy.entry("Long", strategy.long, qty=positionSize)
strategy.exit("Exit Long", "Long", stop=close * (1 - stopLossPercent))
if (shortCondition)
strategy.entry("Short", strategy.short, qty=positionSize)
strategy.exit("Exit Short", "Short", stop=close * (1 + stopLossPercent))
// Cierre de posiciones
if (exitLongCondition)
strategy.close("Long")
if (exitShortCondition)
strategy.close("Short")