モメント・リバーサル・トレーディング・戦略

作者: リン・ハーンチャオチャン,日付: 2023年10月7日 16:52:05
タグ:

概要

この戦略は,モメンタム逆転取引の概念に基づいています.現在のトレンド方向を決定するために,RSI,ストック,MACDを使用し,トレンド逆転を効率的に捕捉できる自動化取引戦略を実装するために,ATRに基づいてストップロスを設定し,利益を上げます.

取引の論理

この戦略は,現在のトレンド方向を決定するための3つの指標として,RSI,ストック,MACDを使用しています. 具体的な論理は:

  • RSI (RSI) (7): 50を超えるRSIは上昇傾向を示し,50以下のRSIは下落傾向を示します.
  • ストック (%K,14,3,3): %K 50以上は上昇傾向,50以下は下落傾向
  • MACD (MACD,12,26,9): 信号線上のMACDは上昇傾向で,下の傾向は下落傾向です

3つの指標がすべて上昇している場合,バーの色は緑に設定されます.すべての指標が下落している場合,バーの色は赤に設定されます.指標の間の差がある場合は,バーの色は黒に設定されます.

取引規則は以下のとおりです

  • 現在のバーが緑色で,前のバーが黒か赤である場合,ロングします. 入場価格はバーの高値より0.01です.
  • 現在のバーが赤で,前のバーが黒か緑であるとき,ショートします.エントリー価格はバーの低値より0.01以下です.
  • ロングポジション中にバーが赤か黒に変わると,ロングトレードを閉じる.
  • ショートポジション中にバーが緑色または黒色になる場合は,ショートトレードを閉じる.

この戦略は,ストップ・ロスを設定し,利益を得るためにATR (7).ストップ・ロスはATRの1.5倍,利益を得ることはATRの3倍に設定されています.

利点分析

この戦略の利点は以下の通りです.

  1. 傾向を決定するために複数の指標を使用することで,誤ったブレイクアウトを効果的にフィルタリングできます.RSI,ストック,MACDが一致した場合,傾向逆転の確率は高いです.

  2. ATRのストップ・ロストとテイク・プロフィートの設定は合理的である.ATRは市場の変動を効果的に追跡することができる.ATRの倍数を使用して,ストップとターゲットは市場の状況に基づいて動的に調整することができます.

  3. シンプルで明快な論理 分かりやすく自動化され 自動化された取引戦略として適しています

リスク分析

この戦略のリスクは以下のとおりです.

  1. 個々の指標のエラーはエントリータイミングに影響を与えます.エラーを減らすためにパラメータを調整するか,より多くの確認指標を追加することを検討できます.

  2. ATRの大きさは,停止とターゲットに大きく影響する.誤ったATR計算は,停止が幅が広いかターゲットが狭すぎる結果になる可能性があります.ATRを確認するために追加の指標を追加することができます.

  3. トレンド決定の欠如.逆転取引に焦点を当て,十分なトレンド分析が範囲の市場でウィップソーにつながる可能性があります.トレンドインジケーターを追加することができます.

  4. パーマータと規則の信頼性を確認するために徹底的なバックテストが必要です

改善 の 方向

この戦略の改善の可能性:

  1. 逆転点を決定する精度を高めるために指標を調整または追加する.例えば,過剰購入/過剰販売レベルをチェックするためにボリンジャー帯を追加する.

  2. ATR計算を最適化して波動性をよりよく追跡する.例えば,ATR/価格比を使用する.

  3. 変動市場での変動を避けるために傾向指標を追加します.例えば移動平均値です.

  4. 資金管理の最適化,例えば引き上げに基づいてポジションサイズ調整

  5. 期間最適化により 耐久性をテストする

  6. 信頼性を確認するために 様々な製品と期間をバックテストします

概要

この戦略は,モメント逆転の概念に基づいて設計されており,RSI,ストック,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*********************************






















もっと