
この戦略は,MACD指数に基づいた改良版の取引戦略である.これは,MACD指数のトレンド追跡特性と動量取引の理念を組み合わせて,急速移動平均と遅い移動平均の間の差を分析することによって取引信号を生成する.この戦略は,戦略の安定性と収益性を高めるために,トレンド確認,信号の遅延確認,固定パーセントのストップ・ロスおよびストップ・ストップなどの最適化手段も導入している.
この戦略の核心は,MACD指数で,それは,高速移動平均 ((EMA) と遅い移動平均 ((EMA) の差から構成されている.高速EMAと遅いEMAが交差すると,買入または売却のシグナルが生じます.具体的には,MACD線が,下から上へ突破すると,買入のシグナルが生じます.MACD線が,上から下へ落ちると,信号線を破ると,売出のシグナルが生じます.
基本のMACD交差信号に加えて,この戦略は,トレンド確認機構を導入している.それは,単純移動平均 ((SMA)) と比較して,現在の市場が上昇傾向にあるか下降傾向にあるかを判断している.買い信号が上昇傾向に現れるか,または下降傾向に起こるセールス信号が現れるかによって,取引操作が実際に実行される.
さらに,この戦略は,信号確認の時間窓を延長する.つまり,現在のK線が買取または販売条件を満たし,前K線も同じ条件を満たす場合にのみ,対応する取引が実行される.これは,信号の信頼性をさらに向上させる.
最後に,この戦略は,固定パーセントのストップ・ロズとストップ・プー価格を設定している.取引が実行されると,開設価格に基づいてストップ・ロズとストップ・プー価格が計算され,これらの価格に達すると自動的に平仓する.これは,1回の取引のリスクと利益を制御するのに役立ちます.
この戦略は,MACD指標に基づく改良された取引戦略であり,トレンド確認,信号遅延確認,固定ストップなどによる戦略の安定性と収益の可能性を高めています. しかし,パラメータ最適化,トレンド識別,単一指標,データ再測などのリスクもあります. 将来,他の指標,ダイナミックストップ,ポジション管理,機械学習などの側面から戦略の最適化を考慮して,実際のアプリケーションの効果をさらに向上させることができます.
/*backtest
start: 2023-05-08 00:00:00
end: 2024-05-13 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sligetit
//@version=5
strategy("Improved MACD_VXI Strategy", overlay=true)
// Calculate MACD and Signal Line
fastLength = input.int(13, title="Fast Length")
slowLength = input.int(21, title="Slow Length")
signalLength = input.int(8, title="Signal Length")
fastMA = ta.ema(close, fastLength)
slowMA = ta.ema(close, slowLength)
macd = fastMA - slowMA
signal = ta.sma(macd, signalLength)
// Plot MACD and Signal Line
plot(macd, color=color.red, linewidth=1)
plot(signal, color=color.blue, linewidth=2)
// Calculate Cross Signals with Trend Confirmation
smaPeriod = input.int(50, title="SMA Period")
sma = ta.sma(close, smaPeriod)
trendUp = close > sma
trendDown = close < sma
crossOver = ta.crossover(signal, macd)
crossUnder = ta.crossunder(signal, macd)
buySignal = crossOver and trendUp
sellSignal = crossUnder and trendDown
// Execute Buy/Sell Operations
if buySignal
strategy.entry("Buy", strategy.long)
if sellSignal
strategy.entry("Sell", strategy.short)
// Extend Signal Confirmation Time Window
longSignal = crossOver[1] and trendUp[1]
shortSignal = crossUnder[1] and trendDown[1]
if longSignal
strategy.entry("Buy", strategy.long)
if shortSignal
strategy.entry("Sell", strategy.short)
// Set Fixed Percentage Stop Loss and Take Profit
stopLossPercent = input.float(1, title="Stop Loss (%)") / 100
takeProfitPercent = input.float(2, title="Take Profit (%)") / 100
stopLossPrice = strategy.position_avg_price * (1 - stopLossPercent)
takeProfitPrice = strategy.position_avg_price * (1 + takeProfitPercent)
strategy.exit("Stop Loss/Profit", "Buy", stop=stopLossPrice, limit=takeProfitPrice)
strategy.exit("Stop Loss/Profit", "Sell", stop=stopLossPrice, limit=takeProfitPrice)