
이 전략은 빠른 이동 평균, 느린 이동 평균 및 교차량 가중 평균을 계산하여 그 사이의 교차 신호를 식별하여 가격 움직임을 포착합니다. 빠른 MA가 위쪽에서 VWAP와 느린 MA를 통과하면 구매 신호가 발생하고 빠른 MA가 위쪽에서 VWAP와 느린 MA를 통과하면 판매 신호가 발생합니다.
이 전략은 이동 평균과 거래량 가중 평균 가격의 장점을 결합한다. 이동 평균은 시장 소음을 효과적으로 필터링하여 트렌드 방향을 판단한다. 거래량 가중 평균은 큰 자본의 의도를 더 정확하게 반영한다. 빠른 MA는 단기 트렌드를 포착하고, 느린 MA는 가짜 신호를 필터링한다. 빠른 MA 위에 느린 MA와 VWAP를 통과하면 단기 트렌드가 부시로 전환되어 구매 신호를 생성하고, 아래로 통과하면 상향으로 전환되어 판매 신호를 생성한다.
이 전략은 이동 평균과 VWAP의 장점을 통합하고, 쌍중 필터링을 통해 교차 신호를 인식하고, 유연한 스톱 스톱 메커니즘과 함께 위험을 효과적으로 제어할 수 있으며, 추천되는 트렌드 추적 전략이다.
/*backtest
start: 2023-11-19 00:00:00
end: 2023-12-19 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("Flexible MA VWAP Crossover Strategy with SL/TP", shorttitle="MA VWAP Crossover", overlay=true)
// Input parameters
fast_length = input(9, title="Fast MA Length", minval=1)
slow_length = input(21, title="Slow MA Length", minval=1)
vwap_length = input(14, title="VWAP Length", minval=1)
// Stop Loss and Take Profit inputs
stop_loss_percent = input(1.0, title="Stop Loss (%)", minval=0.1, maxval=5.0, step=0.1)
take_profit_percent = input(2.0, title="Take Profit (%)", minval=1.0, maxval=10.0, step=0.1)
// Calculate moving averages
fast_ma = sma(close, fast_length)
slow_ma = sma(close, slow_length)
vwap = sma(close * volume, vwap_length) / sma(volume, vwap_length)
// Buy and sell conditions
buy_condition = crossover(fast_ma, vwap) and crossover(fast_ma, slow_ma)
sell_condition = crossunder(fast_ma, vwap) and crossunder(fast_ma, slow_ma)
// Plot the moving averages
plot(fast_ma, title="Fast MA", color=color.blue)
plot(slow_ma, title="Slow MA", color=color.red)
plot(vwap, title="VWAP", color=color.purple)
// Plot buy and sell signals
plotshape(buy_condition, style=shape.triangleup, location=location.belowbar, color=color.green, title="Buy Signal")
plotshape(sell_condition, style=shape.triangledown, location=location.abovebar, color=color.red, title="Sell Signal")
// Define stop loss and take profit levels
var float stop_loss_price = na
var float take_profit_price = na
if (buy_condition)
stop_loss_price := close * (1 - stop_loss_percent / 100)
take_profit_price := close * (1 + take_profit_percent / 100)
// Strategy entry and exit with flexible SL/TP
strategy.entry("Buy", strategy.long, when = buy_condition)
if (sell_condition)
strategy.exit("SL/TP", from_entry = "Buy", stop = stop_loss_price, limit = take_profit_price)