クロスペアボリンガー帯クロスオーバー量的な戦略

作者: リン・ハーンチャオチャン, 日付: 2023-12-27 14:28:21
タグ:

img

概要

この戦略は,MACD指標の高速線とスローラインのクロスオーバーを比較することによって,買いと売りの信号を生成する.買い信号が生成されると,口座資本の一定の割合でポジションを開く.その後,特定のリトレースポイントで追加のポジションが追加される.ポジションの累積利益が設定された取利益点に達すると,すべてのポジションが閉鎖される.売り信号の論理は買い信号に似ている.

戦略の論理

この戦略の主な論理は,トレンドを決定するためにMACDの速いラインとスローラインのクロスオーバーを比較することである.MACDは移動平均の違いであり,短期間の移動平均と長期間の移動平均の違いを計算することによって,市場の傾向と勢いを判断する.速いラインとスローラインのクロスオーバーは黄金十字と死十字とみなされる.

速い線がスローラインを越えると,市場が上昇傾向にあることを示し,戦略はロングポジションを開く.速い線がスローラインを下回ると,ダウントレンドを示し,戦略はショートポジションを開く.

ポジションを開いた後,戦略は特定のリトラセインメントポイントで既存のロングまたはショートポジションに追加されます.これはマルティンゲール原理を通じて利益の可能性を増加させることができます.蓄積された利益が設定された収益ポイントに達すると,戦略はすべてのポジションを閉じます.

利点分析

この戦略には以下の利点があります.

  1. 市場傾向を決定するためにMACD指標を使用します.これは古典的で信頼できる技術分析指標です.

  2. 単一の取引のリスクを制御できる セットでポジションを開くアプローチを採用する.

  3. マルティンゲール原理によって利益の可能性を拡大することができます

  4. 損失を制限するために 利益を取るポイントを設定します

リスク分析

この戦略にはいくつかのリスクもあります:

  1. MACD指標は市場の動きを完璧に予測できないため,誤った信号が発生する可能性があります.

  2. 全ポジションの追加でリトラセシンが拡大するリスクがあります. 追加された各ポジションの割合を適切に調整できます.

  3. 利潤のポイントを小さく設定すると 利益の可能性が制限され 異なる製品に調整されます

  4. 口座制限を超えないように,製品ごとにポジションを開設するための合理的な資本の割合を設定する必要がある.

オプティマイゼーションの方向性

この戦略は,次の側面で最適化できます.

  1. MACDパラメータをテストして 特定の取引製品に適したパラメータを見つけます

  2. お金パーセントとリトラセインメントパーセントを最適化し,最適なパラメータ組み合わせを見つけます

  3. 最適レベルを決定するために,それぞれ長期と短期の利得ポイントをテストします.

  4. 口座の利回り能力を評価し,製品ごとに合理的な最大ポジション制限を設定する.

  5. ストップロスの論理を追加します.ストップロスは急激な市場変化が発生したときに損失を効果的に制御することができます.

概要

概要すると,これは典型的なトレンドフォロー戦略である.市場トレンド方向性を決定するためにMACD指標を使用し,トレンドをフォローするためにバッチでポジションを追加するアプローチをとり,累積利益が一定のレベルに達すると利益を得ます.このシンプルで実用的な戦略は,量的な取引初心者にとって実行しやすく,適しています.パラメータを最適化し,リスク制御ロジックを拡張することで,戦略はより堅牢になることができます.


/*backtest
start: 2023-11-26 00:00:00
end: 2023-12-26 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/
// © TradingSoft_tech

//@version=5
strategy("MAPM-V1", overlay=true, default_qty_value=10, max_bars_back=5000,default_qty_type = strategy.percent_of_equity, commission_value=0.1, initial_capital = 100, pyramiding=6, currency=currency.USD)

///////// Options
SignalFast = input.int(300, step=10)
SignalSlow = input.int(600, step=10)
StepAddPurchases = input.float(2.5, step=0.1)
VolumePurchases = input.int(6,step=1)
Buy = input(true)
Sell = input(true)
longProfitPerc = input.float(title="Long Take Profit (%)", minval=0.0, step=0.1, defval=1) * 0.01
shortProfitPerc = input.float(title="Short Take Profit (%)", minval=0.0, step=0.1, defval=1) * 0.01
Martingale = input.float(1.6, minval = 1, step = 0.1)
VolumeDepo = input.int(100, step=1)
PercentOfDepo = input.float(10, step=1)
Close = (close)
EnterVolume = VolumeDepo*PercentOfDepo*0.01/Close

///////// Calculation indicator
fastAverage = ta.ema(close, 8)
slowAverage = ta.ema(close, 49)
macd = fastAverage - slowAverage
macdSignalF = ta.ema(macd,SignalFast)
macdSignalS = ta.ema(macd,SignalSlow)

// Test Start
startYear = input(2005, "Test Start Year")
startMonth = input(1, "Test Start Month")
startDay = input(1, "Test Start Day")
startTest = timestamp(startYear,startMonth,startDay,0,0)

//Test End
endYear = input(2050, "Test End Year")
endMonth = input(12, "Test End Month")
endDay = input(30, "Test End Day")
endTest = timestamp(endYear,endMonth,endDay,23,59)

timeRange = time > startTest and time < endTest ? true : false

///////// Plot Data
//plot(macd, style = plot.style_histogram)
//plot(macdSignalF*10000, style = plot.style_line, color=color.red)
//plot(macdSignalS*10000, style = plot.style_line, color=color.blue)
//plot(fastAverage, style = plot.style_line, color=color.red)
//plot(slowAverage, style = plot.style_line, color=color.blue)

///////// Calculation of the updated value
var x = 0.0
if strategy.opentrades>strategy.opentrades[1]
    x := x + 1
else if strategy.opentrades==0
    x := 0
y = x+1

///////// Calculation of reference price data
entryPrice = strategy.opentrades==0? 0 : strategy.opentrades.entry_price(0)
limitLong = strategy.position_avg_price * (1 + longProfitPerc)
limitShort = strategy.position_avg_price * (1 - shortProfitPerc)
SteplimitLong = entryPrice[0]*(1-StepAddPurchases*y/100)
SteplimitShort = entryPrice[0]*(1+StepAddPurchases*y/100)

///////// Conditions for a long
bool EntryLong = ta.crossover(macdSignalF, macdSignalS) and Buy and strategy.opentrades==0 and strategy.position_size==0
bool PurchasesLong = Buy and strategy.opentrades==x and strategy.position_size>0 and x<=VolumePurchases
bool CancelPurchasesLong = strategy.position_size==0 and strategy.opentrades==0
bool TPLong = strategy.position_size>0 and strategy.opentrades!=0
///////// Entry Long + add.purchases + cancel purchases + Take profit Long
switch 
    EntryLong => strategy.entry("Entry Long", strategy.long, qty = EnterVolume)
    PurchasesLong => strategy.entry("PurchasesLong", strategy.long, qty = EnterVolume*math.pow(Martingale,y), limit = SteplimitLong)
    CancelPurchasesLong => strategy.cancel("PurchasesLong")
switch
    TPLong => strategy.exit("TPLong", qty_percent = 100, limit = limitLong)

///////// Conditions for a Short
bool EntryShort = ta.crossunder(macdSignalF, macdSignalS) and Sell and strategy.opentrades==0 and strategy.position_size==0
bool PurchasesShort = Sell and strategy.opentrades==x and strategy.position_size<0 and x<=VolumePurchases
bool CancelPurchasesShort = strategy.position_size==0 and strategy.opentrades==0
bool TPShort = strategy.position_size<0 and strategy.opentrades!=0

///////// Entry Short + add.purchases + cancel purchases + Take profit Short
switch
    EntryShort => strategy.entry("Entry Short", strategy.short, qty = EnterVolume)
    PurchasesShort => strategy.entry("PurchasesShort", strategy.short, qty = EnterVolume*math.pow(Martingale,y), limit = SteplimitShort)
    CancelPurchasesShort => strategy.cancel("PurchasesShort")
switch
    TPShort => strategy.exit("TPShort", qty_percent = 100, limit = limitShort)
    
/////////Calculation of conditions and reference data for level drawing
InTradeLong = strategy.position_size<0
InTradeShort = strategy.position_size>0
PickInLong = strategy.opentrades.entry_price(0)*(1-StepAddPurchases*y/100)
PickInShort = strategy.opentrades.entry_price(0)*(1+StepAddPurchases*y/100)

/////////Displaying the level of Take Profit
plot(InTradeLong ? na : limitLong, color=color.new(#00d146, 0), style=plot.style_linebr, linewidth=1)
plot(InTradeShort ? na : limitShort, color=color.new(#00d146, 0), style=plot.style_linebr, linewidth=1)

/////////Displaying the level of add.purchases
plot(InTradeLong ? na : PickInLong, color=color.white, style=plot.style_linebr, linewidth=1)
plot(InTradeShort ? na : PickInShort, color=color.white, style=plot.style_linebr, linewidth=1)

もっと