
この策略は,速動平均,遅動平均,交差量加重平均を計算して,それらの間の交差信号を識別して,価格の動きを捉えます. 速いMAがVWAPと遅いMAを上から下を通るとき,買い信号を生じ,速いMAがVWAPと遅いMAを上から下を通るとき,売り信号を生じ.
この戦略は,移動平均と取引量重加平均価格の優位性を組み合わせている.移動平均は,トレンド方向を判断するために,市場騒音を効果的にフィルターすることができる.取引量重加平均は,大資本の意図をより正確に反映することができる.急速なMAは,短期トレンドを捕捉し,遅いMAは,偽の信号をフィルターすることができる.
この戦略は,移動平均と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)