
이 전략은 21일 지수 이동 평균에 대한 금 가격의 편차 정도를 계산하여 표준 차와 결합하여 시장의 과매매 상황을 판단합니다. 편차 정도가 특정 표준 차에 도달하면 트렌드 추적 전략을 취하며 손실 제도를 설정하여 위험을 제어합니다.
이 전략은 가격 동력과 표준 격차를 기반으로 시장의 과매매를 판단하는 트렌드 추적 전략으로 다음과 같은 장점이 있습니다.
이 전략에는 몇 가지 위험도 있습니다.
해결책:
이 전략은 다음과 같은 부분에서 최적화될 수 있습니다.
이 전략은 전체적으로 기본 합리적인 트렌드 추적 전략이다. 이동 평균을 사용하여 주요 트렌드 방향을 판단하고, 가격 편차의 표준화된 처리를 통해 시장의 과매매 상황을 명확하게 판단하여 거래 신호를 생성할 수 있다. 합리적인 중지 방법을 설정하는 것은 전략이 수익을 보장하는 동시에 위험을 제어 할 수 있도록 한다. 파라미터를 추가적으로 최적화하고 더 많은 조건 판단을 추가함으로써 전략이 더 안정적이고 신뢰할 수 있으며, 매우 강력한 응용 가치가 있다.
/*backtest
start: 2024-01-20 00:00:00
end: 2024-02-19 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("GC Momentum Strategy with Stoploss and Limits", overlay=true)
// Input for the length of the EMA
ema_length = input.int(21, title="EMA Length", minval=1)
// Exponential function parameters
steepness = 2
// Calculate the EMA
ema = ta.ema(close, ema_length)
// Calculate the deviation of the close price from the EMA
deviation = close - ema
// Calculate the standard deviation of the deviation
std_dev = ta.stdev(deviation, ema_length)
// Calculate the Z-score
z_score = deviation / std_dev
// Long entry condition if Z-score crosses +0.5 and is below 3 standard deviations
long_condition = ta.crossover(z_score, 0.5)
// Short entry condition if Z-score crosses -0.5 and is above -3 standard deviations
short_condition = ta.crossunder(z_score, -0.5)
// Exit long position if Z-score converges below 0.5 from top
exit_long_condition = ta.crossunder(z_score, 0.5)
// Exit short position if Z-score converges above -0.5 from below
exit_short_condition = ta.crossover(z_score, -0.5)
// Stop loss condition if Z-score crosses above 3 or below -3
stop_loss_long = ta.crossover(z_score, 3)
stop_loss_short = ta.crossunder(z_score, -3)
// Enter and exit positions based on conditions
if (long_condition)
strategy.entry("Long", strategy.long)
if (short_condition)
strategy.entry("Short", strategy.short)
if (exit_long_condition)
strategy.close("Long")
if (exit_short_condition)
strategy.close("Short")
if (stop_loss_long)
strategy.close("Long")
if (stop_loss_short)
strategy.close("Short")
// Plot the Z-score on the chart
plot(z_score, title="Z-score", color=color.blue, linewidth=2)
// Optional: Plot zero lines for reference
hline(0.5, "Upper Threshold", color=color.red)
hline(-0.5, "Lower Threshold", color=color.green)