
이 전략은 가격과 이동 평균의 교차에 기초하여 구매 및 판매 신호를 생성한다. 그것은 여러 종류의 이동 평균과 가짜 돌파구를 필터링하기 위해 공평한 변수를 제공한다. 이 전략은 가격 추세의 전환점을 포착하여 추세를 추적하는 것을 목표로 한다.
이 전략은 가격 종착 가격에 기초하여 N 길이의 이동 평균을 계산한다. 전형적인 이동 평균 유형에는 간단한 이동 평균 ((SMA), 지수 이동 평균 ((EMA), 가중 이동 평균 ((WMA) 등이 있다. 그런 다음 5%와 같은 변수 수준을 설정하고 상단 이동 평균의 1.05배와 하단 이동 평균의 0.95배를 계산한다. 가격 종착 가격이 상단 경로를 통과하면 구매 신호가 발생하며, 가격 종착 가격이 하단 경로를 통과하면 판매 신호가 발생한다.
이 전략은 전체적으로 좀 더 전형적인 트렌드 추적 전략이다. 가격과 이동 평균의 관계를 사용하여 트렌드를 판단하고, 약간의 유연성을 제공한다. 파라미터 최적화와 적절한 신호 필터링을 통해, 이는 효과가 좋은 양적 전략이 될 수 있다. 그러나 가공의 위험을 제어하고 과도한 손실을 피하는 데 주의가 필요하다.
/*backtest
start: 2023-12-26 00:00:00
end: 2024-01-25 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RafaelPiccolo
//@version=4
strategy("Price X MA Cross", overlay=true)
typ = input("HMA", "MA Type", options=["SMA", "EMA", "WMA", "HMA", "VWMA", "RMA", "TEMA"])
len = input(100, minval=1, title="Length")
src = input(close, "Source", type=input.source)
tol = input(0, minval=0, title="Tolerance (%)", type=input.float)
shortOnly = input(false, "Short only")
tema(src, len)=>
ema1 = ema(src, len)
ema2 = ema(ema1, len)
ema3 = ema(ema2, len)
return = 3 * (ema1 - ema2) + ema3
getMAPoint(type, len, src)=>
return = type == "SMA" ? sma(src, len) : type == "EMA" ? ema(src, len) : type == "WMA" ? wma(src, len) : type == "HMA" ? hma(src, len) : type == "VWMA" ? vwma(src, len) : type == "RMA" ? rma(src, len) : tema(src, len)
ma = getMAPoint(typ, len, src)
upperTol = ma * (1 + tol/100)
lowerTol = ma * (1 - tol/100)
longCondition = crossover(close, upperTol)
shortCondition = crossunder(close, lowerTol)
if (shortCondition)
strategy.entry("Short", strategy.short)
if (longCondition)
if (shortOnly)
strategy.close("Short")
else
strategy.entry("Long", strategy.long)
plot(ma, "Moving Average", close > ma ? color.green : color.red, linewidth = 2)
t1 = plot(tol > 0 ? upperTol : na, transp = 70)
t2 = plot(tol > 0 ? lowerTol : na, transp = 70)
fill(t1, t2, color = tol > 0 ? color.blue : na)