
동적 평균을 뚫는 전략은 동적 지표와 결합된 동적 지표의 동적 경로 신호를 이용한 주식 거래 전략이다. 이 전략은 인덱스 이동 평균 (EMA), 간단한 이동 평균 (SMA), 이동 평균 분산 지수 (MACD) 및 수정된 상대적으로 강한 지수 (StockRSI) 과 같은 다중 기술 지표를 종합적으로 사용하여, 장기적인 추세가 상승한 것을 확인한 전제 하에 구매 신호를 형성한다. 단기적인 동적 지표가 역전 신호를 표시할 때, 전략은 중지 손실을 취한다.
이 전략의 주요 구성 요소는 다음과 같습니다.
EMA/SMA 평행선 교차: 9주기 EMA 패스트라인과 21주기 SMA 패스트라인을 설정하여 패스트라인이 패스트라인을 통과하면 구매 신호를 발생시킨다.
MACD 지표: MACD 지표는 MACD 라인, 신호 라인 및 MACD 기둥을 포함한다. 기둥이 긍정적이고 EMA/SMA에서 생성된 구매 신호와 동기화될 때, 추가 확인이 된다.
스톡RSI: StockRSI는 개량된 RSI 지표에 대한 것이다. 지표선이 OVERBOUGHT 선 ((80)) 보다 높거나 OVERSOLD 선 ((20) 보다 낮을 때 구매 신호가 발생한다.
브린 벨트: 브린 중간 궤도는 20일 SMA이며, 대역폭은 위의 두 표준마다 차이가 있다. 가격이 브린 영역 안에 있을 때만 거래 신호를 생성한다.
손해 및 정지: 지난 14 일 동안의 ATR을 기준으로 스톱로스 및 스톱 가격을 계산합니다.
이 전략은 위의 지표 중 적어도 2개의 지표가 동시에 구매 신호를 발산해야 하며, 주가가 부린 구역 안에 있고 장기적인 추세가 상승하기 때문에 최종 구매 신호가 발생한다. MACD 지표가 하향으로 역전될 때, StockRSI가 오버 바이 영역에 들어가면 판매 신호가 발생한다.
이 전략은 평평선 교차, 운동량 지표 및 변동률 지표의 장점을 결합하여 다음과 같은 주요 장점을 가지고 있습니다.
좋은 결과다중 지표는 모두 성숙한 지표이며, 전략적 결과는 대장과 단일 지표보다 우수하다.
최적화된 변수: EMA 주기, 부린 띠 통로와 같은 주요 파라미터가 최적화되어 시스템 안정성을 향상시킬 수 있다.
자동 중지/정지브린띠와 ATR은 실시간으로 스톱로드를 조정하여 리스크 관리를 돕는다.
실행의 난이도가 낮습니다.코드는 간결하고, 지표는 쉽게 얻을 수 있으며, 실제 조작의 어려움은 크지 않다.
이 전략은 좋은 성과를 거뒀지만, 다음과 같은 주요한 위험 요소가 있습니다.
지표는 잘못된 신호를 내보냅니다.: 시장이 비정상적으로 변동하거나 지표가 실패하면 잘못된 신호가 발생할 수 있다. 이 시기는 장기적인 추세 판단과 함께 고려해야 한다.
변수가 잘못되었습니다.: 매개 변수 설정이 잘못되면 거래가 너무 자주 또는 반응이 민감하지 않을 수 있습니다. 다양한 품종과 시장 환경에 따라 조정해야합니다.
너무 작거나 너무 커서: 막는 손실이 너무 작으면 쉽게 잡힐 수 있고, 너무 크면 손실이 너무 크다. 막는 손실과 막는 손실이 균형을 잡아야 한다.
위와 같은 위험에는 다음과 같은 조치를 취할 수 있습니다.
인공 개입과 수정: 특이한 상황이 발생하면 신호를 수동으로 확인하고, 매개 변수를 수정하거나, 정책을 일시 중지할 수 있다.
최적화 변수 설정: 유전 알고리즘과 같은 더 과학적이고 객관적인 방법을 사용하여 매개 변수를 최적화하십시오.
변동률 조정으로 인한 손실: 변동률에 따라 자동으로 스톱 로드 폭을 조정할 수 있습니다.
이 전략은 다음과 같은 부분에서 더 개선될 수 있습니다.
손해 방지 장치의 안정성을 높이는 것: 추적 스톱 또는 지수 이동 평균을 추가하여 스톱을 수행할 수 있다.
거래량 필터링: 거래량 지표를 추가하여 무효 돌파구를 피하십시오.
동적 조정 변수: 시장 환경에 따라 자동으로 평균선 주기, 통로 너비 등을 최적화할 수 있다.
기계 학습 알고리즘을 도입합니다.: RNN, LSTM 등의 알고리즘을 사용하여 매개 변수를 구현하는 동적 최적화.
동력 돌파평선 전략 종합 적용 기술 지표의 장점, 장단 달리기 협조의 경우, 좋은 수익을 얻었다. 이 전략은 손해 제어가 위치하고, 실행의 어려움은 크지 않다. 다음 단계는 손해 제도를 더욱 개선하고, 더 지능화된 방법을 사용하여 파라미터 최적화 및 신호 필터링을 수행하여, 더 안정적인 초과 수익을 얻으려고 노력한다.
/*backtest
start: 2022-11-20 00:00:00
end: 2023-11-26 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Improved Custom Strategy", shorttitle="ICS", overlay=true)
// Volatility
volatility = ta.atr(14)
// EMA/MA Crossover
fast_length = 9
slow_length = 21
fast_ma = ta.ema(close, fast_length)
slow_ma = ta.sma(close, slow_length)
crossover_signal = ta.crossover(fast_ma, slow_ma)
// MACD
[macdLine, signalLine, macdHistogram] = ta.macd(close, 12, 26, 9)
macd_signal = crossover_signal and (macdHistogram > 0)
// Bollinger Bands
source = close
basis = ta.sma(source, 20)
upper = basis + 2 * ta.stdev(source, 20)
lower = basis - 2 * ta.stdev(source, 20)
// Fractal-based Support and Resistance levels
isFractalHigh = high[2] < high[1] and high[1] > high[0]
isFractalLow = low[2] > low[1] and low[1] < low[0]
resistance = ta.valuewhen(isFractalHigh, high[1], 0)
support = ta.valuewhen(isFractalLow, low[1], 0)
// StockRSI
length = 14
K = 100 * (close - ta.lowest(close, length)) / (ta.highest(close, length) - ta.lowest(close, length))
D = ta.sma(K, 3)
overbought = 80
oversold = 20
stockrsi_signal = ((K < D) and (K < oversold)) or ((K > D) and (K > overbought))
// Buy and sell conditions
mandatory_buy_conditions = (crossover_signal ? 1 : 0) + (macd_signal ? 1 : 0) + (stockrsi_signal ? 1 : 0)
// Long-term Trend Check
long_term_ma = ta.sma(close, 200)
long_term_bullish = close > long_term_ma
long_term_bearish = close < long_term_ma
// Plot the long-term MA for visual clarity
plot(long_term_ma, color=color.gray, title="200-Day MA", linewidth=1)
// Simplified Buy and Sell conditions
buy_condition = long_term_bullish and (mandatory_buy_conditions >= 2) and (close > lower) and (close < upper)
sell_condition = (macdHistogram < 0) and (K > D) and (K > overbought)
// Potential SL and TP based on volatility
potential_SL = close - volatility
potential_TP = close + 2 * volatility
plot(potential_SL, title="SL Level", color=color.red, linewidth=1, style=plot.style_linebr)
plot(potential_TP, title="TP Level", color=color.green, linewidth=1, style=plot.style_linebr)
// ... (rest of your code above)
// State variable to track if we're in a position, a counter for trades, and a delayed counter for plotting
var bool inPosition = false
var tradeCounter = 0
var tradeCounterDelayed = 0 // Declaration of the variable
// Buy logic: Check if tradeCounter is 0 and the buy condition is met
if tradeCounter == 0 and buy_condition
strategy.entry("BUY", strategy.long, stop=potential_SL, limit=potential_TP)
inPosition := true
tradeCounter := tradeCounter + 1
// Sell logic: Check if tradeCounter is 1, the sell condition is met, and we are in a position
if tradeCounter == 1 and inPosition and sell_condition
strategy.close("BUY")
inPosition := false
tradeCounter := tradeCounter - 1
// Update the delayed trade counter:
tradeCounterDelayed := tradeCounter
// Plotting
bgcolor(buy_condition ? color.new(color.green, 90) : sell_condition ? color.new(color.red, 90) : na)
plotshape(series=buy_condition and tradeCounterDelayed == 0, style=shape.labelup, location=location.belowbar, color=color.green, text="BUY", size=size.small)
plotshape(series=sell_condition and tradeCounterDelayed == 1, style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", size=size.small)
// ... (rest of your code if any)