モメンタム反転戦略


作成日: 2023-10-07 16:52:05 最終変更日: 2023-10-07 16:52:05
コピー: 0 クリック数: 675
1
フォロー
1621
フォロワー

概要

この戦略は,動量逆転の取引理念に基づいており,RSI,Stoch,MACDの3つの指標によって現在のトレンドを判断し,ATRと組み合わせて,ストップ・ロスト・ポジションを設定し,トレンド逆転を効率的にキャプチャする自動取引戦略を実現します.

戦略原則

この戦略は,RSI,Stoch,MACDの3つの指標を使用して,現在のトレンドの方向を判断します.具体的ロジックは次のとおりです.

  • RSI ((7日):RSIが50以上なら上昇し,50未満なら下落する
  • Stoch ((%K,14,3,3):%K値が50より大きいのは看板で,50より小さいのは看板
  • MACD ((12,26,9):MACDはシグナルより大きく,シグナルより小さい

3つの指標が同時に上昇すると,このBarは緑に設定されます. 3つの指標が同時に下落すると,このBarは赤に設定されます.指標信号が異なっていたら,黒に設定されます.

取引ルールは以下の通りです。

  • 現在のバーが緑で,前のバーが黒か赤である場合,追加入場を行い,入場料は,そのバーの高点に0.01を加えます.
  • 現在のバーが赤で,前のバーが黒か緑の場合は,空白で入場し,そのバーの低点への入場価格を0.01で減らします.
  • ポジションを多頭持っていたときに赤または黒のバーが表示された場合,平仓
  • 空頭ポジション中に緑色または黒色のバーが現れた場合,平仓

この戦略はまた,ATR ((7日平均線) を使って,ストップ・ローズ・ストップの位置を設定する.ストップ・ローズはATRの1.5倍,ストップ・ローズはATRの3倍である.

優位分析

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

  1. 複数の指標を用いてトレンドを判断し,偽の突破を効果的にフィルターすることができる. RSI,Stoch,MACDの3つの指標が同時に上下すると,概率はトレンドの逆転点である.

  2. ATRのストップ・ストップの設定は優れている。ATRは市場の波動程度を効果的に追跡することができ,ATRの多倍数のストップ・ストップの設定を使用し,市場の状況に応じてストップ・ストップの位置を動的に調整することができ,ストップ・ストップが過度に緩やかまたは過度に緊密であることを防ぐ。

  3. 取引ロジックはシンプルでわかりやすく,理解しやすい実装で,自動取引戦略として使用できます.

リスク分析

この戦略には以下のリスクがあります.

  1. 複数の指標の組み合わせ判断は,個々の指標が誤信号を発している場合があるため,入場タイミングに影響を与える可能性がある.指標パラメータを調整するか,検証のために他の指標を追加することを検討して,誤信号率を下げることができる.

  2. ATRのサイズは,止損のストップに大きく影響する.ATRの計算が正確でない場合,止損が大きすぎたり,ストップが小さすぎたりする可能性があります.ATRのサイズを確認するために,他の指標を添加することを考えることができます.

  3. トレンド判断の欠如. この戦略は反転取引に焦点を当て,トレンド判断は不十分で,震動の状況で閉じ込められやすい. トレンド指数補助判断を添えることができる.

  4. 適合過度のリスクがある.充分な反省を行い,パラメータと規則の信頼性を検証すべきである.

最適化の方向

この戦略は,以下の点で最適化できます.

  1. 指標を調整または追加し,トレンドの逆転のタイミングを判断する精度を向上させる.例えば,ブリンラインを足して超買い超売状態を判断する.

  2. ATRの計算方法の最適化により,市場の変動をよりよく追跡できる.例えばATRを価格に比する.

  3. トレンド判断の指標を増やして,波動的な状況で被套されないようにする.例えば,移動平均を加えることでトレンドの方向を判断する.

  4. 資金管理の最適化,例えば,撤収に応じてポジションの調整

  5. 周期最適化を行い,異なる時間周期パラメータの安定性を検証する.

  6. より多くの品種と時間帯で追跡調査を行い,戦略の安定した信頼性を検証する.

要約する

この戦略は,動量反転思路の設計に基づいて,RSI,StochとMACDの組み合わせを使用して,トレンド反転のタイミングを判断し,ATRのダイナミック設定のストップ・ストップと連携して,より完全なトレンド反転取引戦略を形成する.戦略は,取引論理の明確性,ストップ・ストップの合理的な設定などの利点がありますが,指標の誤信号,トレンド判断の欠如などの欠陥もあります.将来,指標のパラメータを最適化,トレンド判断に加入,資金管理を調整するなど,戦略をより安定して信頼できるように改善することができます.

ストラテジーソースコード
/*backtest
start: 2023-09-06 00:00:00
end: 2023-10-06 00:00:00
period: 2h
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/
// © jwitt98
//The PowerX strategy - based on the rules outlined in the book "The PowerX Strategy: How to Trade Stocks and Options in Only 15 Minutes a Day" by Markus Heitkoetter

//@version=5
strategy("PowerX", overlay=true)
strategy.initial_capital = 50000
longEntry = "Enter long"
shortEntry = "Enter short"
longExit = "Exit long"
shortExit = "Exit short"

//*********************************Begin inputs*********************************

//get time range inputs and set time range bool
timeRangeGroup = "Select the trading range"
startDate = input(timestamp("1 Jan 2021 00:00 +0000"), "Start date", "Select the start date for the trading range", "", timeRangeGroup)
endDate = input(timestamp("1 Jan 2050 00:00 +0000"), "End date", "Select the end date for the trading range", "", timeRangeGroup)
isInTimeRange = true

//get long/short inputs
positionsAllowedGroup = "Select the direction(s) of trades to allow"
isLongsAllowed = input.bool(true, "Allow long positions", "Check the box if you want to allow long positions", "", positionsAllowedGroup)
isShortsAllowed = input.bool(true, "Allow short positions", "Check the box if you want to allow short positions", "", positionsAllowedGroup)

//get the stop loss and profit target multiples.  Per the PowerX rules the ratio shoud be 1:2.  1.5 and 3 are defaults
adrMultuplesGroup="Select the multipliers for the stop loss and profit targets"
stopLossMultiple = input.float(1.5, "Stop loss multiple", 0.1, 10, 0.1, "The ADR is multiplied by the stop loss multiple to calculate the stop loss", group=adrMultuplesGroup)
profitTargetMultiple=input.float(3.0, "Profit target multiple", 0.1, 10, 0.1, "The ADR is multiplied by the profit target multiple to calculate the profit target", group=adrMultuplesGroup)

//get the option to use the money management stategy or not.  This is a fixed ratio type management system
moneyManagementGroup="Money management"
isUsingMoneyManagement=input.bool(false, "Use money management", "Check the box if you want to use a fixed ratio type money management system, such as the type described in PowerX", group=moneyManagementGroup)
initial_riskPercent=input.float(2.0, "Percent risk per trade", .1, 100, .1, "The percentage of capital you want to risk when starting out.  This will increase or decrease base on the money management rules.  Only applicable if money managent is used", group=moneyManagementGroup)/100
isRiskDowsideLimited=input.bool(false, "Keep risk at or above the set point", "Check the box if you don't want the risk to fall below the set \"risk per trade\" percentage, for example, when your equity is underwater. Only applicable if money management is used", "", moneyManagementGroup)
initial_riskPerTrade=initial_riskPercent * strategy.initial_capital 
riskFactor = 0.0
currentProfit = 0.0
currentRisk = 0.0

//*********************************End inputs*********************************

//*********************************Begin money management*********************************

if(isUsingMoneyManagement)
    currentProfit := strategy.equity - strategy.initial_capital
    if(currentProfit < 0)
        currentProfit:=math.abs(currentProfit)
        riskFactor := 0.5*(math.pow(1+8*currentProfit/(2*initial_riskPerTrade), 0.5)+1)
        currentRisk := 1/riskFactor * initial_riskPercent * strategy.initial_capital
        if(isRiskDowsideLimited)
            currentRisk := initial_riskPerTrade
    else
        riskFactor := 0.5*(math.pow(1+8*currentProfit/(2*initial_riskPerTrade), 0.5)+1)
        currentRisk := riskFactor * initial_riskPercent * strategy.initial_capital
        
plot(strategy.equity, "Strategy equity")
plot(currentRisk, "Current risk")
plot(riskFactor, "Risk Factor")

//*********************************End money management*********************************


//*********************************Begin indicators*********************************
//4 indicators are used in this strategy, RSI(7), Stochastics(14, 3, 3), MACD(12, 26, 9), and ADR(7)

rsiVal = ta.rsi(close, 7)//this checks out
plot(rsiVal, "RSI(7)", color.lime)

stochKVal = ta.sma(ta.sma(ta.stoch(close, high, low, 14),3),3)//this formula checks out
plot(stochKVal, "Stoch %K", color.lime)

[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)
plot(histLine, "MACD Hist", color.lime)

adr = ta.sma(high, 7) - ta.sma(low, 7)
plot(adr, "Average daily range", color.orange)


//*********************************End indicators*********************************

//*********************************Define the bar colors*********************************

greenBar = rsiVal > 50 and stochKVal > 50 and histLine > 0
redBar = rsiVal < 50 and stochKVal < 50 and histLine < 0
blackBar = not greenBar and not redBar

color currentBarColor = switch
    greenBar => color.green
    redBar => color.red
    blackBar => color.gray //because black is too hard to see in dark mmode
    => color.yellow
    
barcolor(currentBarColor)

//*********************************End defining the bar colors*********************************

//*********************************Define the entry, stop loss and profit target*********************************

longStopLimit = high + .01
longProfitTarget = high + (profitTargetMultiple * adr)
longStopLoss = high - (stopLossMultiple * adr)

shortStopLimit = low - .01
shortProfitTarget = low - (profitTargetMultiple * adr)
shortStopLoss = low + (stopLossMultiple * adr)

qtyToTrade= math.floor(currentRisk / (stopLossMultiple * adr))//only if using money management
if(qtyToTrade * high > strategy.equity)
    qtyToTrade := math.floor(strategy.equity / high)

//*********************************End defining stop loss and profit targets*********************************

//*********************************Execute trades, set rules, stop loss and profit targets*********************************

if (greenBar and not greenBar[1] and isInTimeRange and isLongsAllowed)
    if(isUsingMoneyManagement)
        strategy.order(longEntry, strategy.long, qtyToTrade, limit=longStopLimit, stop=longStopLimit)
        //strategy.order(longEntry, strategy.long, qtyToTrade, stop=longStopLimit)
    else
        strategy.order(longEntry, strategy.long, limit=longStopLimit,stop=longStopLimit)
        //strategy.order(longEntry, strategy.long, stop=longStopLimit)
    strategy.exit("Long limit/stop", from_entry=longEntry, limit=longProfitTarget, stop=longStopLoss)
    

if(blackBar or redBar)
    strategy.cancel(longEntry)
    strategy.close(longEntry, longExit)
    

if (redBar and not redBar[1] and isInTimeRange and isShortsAllowed)
    if(isUsingMoneyManagement)
        strategy.order(shortEntry, strategy.short, qtyToTrade, limit=shortStopLimit, stop=shortStopLimit)
        //strategy.order(shortEntry, strategy.short, qtyToTrade, stop=shortStopLimit)
    else
        strategy.order(shortEntry, strategy.short, limit=shortStopLimit, stop=shortStopLimit)
        //strategy.order(shortEntry, strategy.short, stop=shortStopLimit)
    strategy.exit("Short limit/stop", from_entry=shortEntry, limit=shortProfitTarget, stop=shortStopLoss)

if(blackBar or greenBar)
    strategy.cancel(shortEntry)
    strategy.close(shortEntry, shortExit)
    

//*********************************End execute trades, set rules, stop loss and profit targets*********************************