休止範囲反転戦略


作成日: 2023-10-30 10:54:00 最終変更日: 2023-10-30 10:54:00
コピー: 1 クリック数: 569
1
フォロー
1617
フォロワー

休止範囲反転戦略

概要

休眠範囲の反転戦略は,価格変動率が低下した時期をポジション構築の信号として利用し,価格変動率が再び上昇すると利平ポジションを獲得する.それは,価格が狭い振動の休眠範囲に制限されている状況を認識して,即興の爆発的な価格トレンドを捕捉する.この戦略は,通常,現在の変動率が低いレベルにあるが,将来の爆発が起こりうる場合に適用される.

戦略原則

この戦略は,まず,休憩範囲を識別します.これは,価格が前の取引日の価格範囲に制限されている場合です.これは,現在の変動率が,前数日に比べて減少していることを示します.我々は,現在の取引日の最高価格とn日前の (通常は4日) の最高価格を比較し,現在の取引日の最低価格とn日前の最低価格を比較して,休憩範囲に適合するかどうかを判断します.

休止範囲が確認されたら,この戦略は同時に2つの掛札を開きます. 買取掛札は範囲の高点近くに置き,売売掛札は範囲の低点近くに置き. その後,価格が休止範囲を破るのを待って,上方へ進むか下方へ進む. 価格が上方へ突破すると,買取は多頭位を確立させられ,下方へ突破すると,売売は空頭位を確立させられる.

ポジションを確立した後,戦略は,ストップ・ロース・オールとストップ・ストップ・オールを設定する. ストップ・ロース・オールは,下行リスクを制限し,ストップ・オールは,利益を得た後に平仓に使用される. ストップ・ロース・オールは,入場価格から,リスク管理パラメータによって設定された比例の距離である. ストップ・オールは,入場価格から,休止範囲の大きさである.

最後に,この戦略には,資金管理モジュールが含まれています. 固定倍率法によって,注文取引の資金量を調整し,収益性のあるときに資金活用率を増やし,損失のあるときにリスクを軽減します.

優位分析

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

  1. 波動率の低下をポジションシグナルとして利用し,価格トレンドが起こる前にチャンスを捉えることができる.

  2. また,多空の双方向取引オーダーを設定して,上昇または下降のトレンドをキャプチャできます.

  3. ストップ・ストップ・ストップの戦略により,単一取引のリスクを効果的にコントロールできます.

  4. 固定倍率の資金管理法を適用することで,資金使用の効率が向上する.

  5. 戦略の論理はシンプルで,明快で,実行しやすい.

リスク分析

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

  1. 休眠範囲の破裂方向を誤判するリスク。価格が上下突破もはっきりしない可能性があり,入場方向を誤導する危険。

  2. 突破後,方向性での運行が継続できないリスク.突破は,短期的な反転にすぎません.

  3. ストップダメージが突破されるリスク.特大情勢ではストップダメージラインを直接突破する可能性がある.

  4. 固定倍率法加仓損失拡大のリスク. 固定倍率値を下げてリスクを軽減することができる.

  5. パラメータを正しく設定しない場合, 策略の効果が低下する可能性があります.

最適化の方向

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

  1. 突破を回避するフィルター信号を追加して,誤った突破を回避する.

  2. 移転停止,リストアップ停止など,損失停止戦略の改善.

  3. 市場を回転させないようにする.

  4. 固定倍率を最適化して,利益と損失の比率を均衡させる.

  5. 複数のタイムサイクル分析を組み合わせて,利益の確率を高めます.

  6. 機械学習によるパラメータの自動最適化.

要約する

休眠範囲の逆転戦略の全体的な考え方は明確で,一定の利益の可能性があります.パラメータ最適化,リスク管理,信号フィルタリングなどの手段によって戦略の安定性をさらに向上させることができます.しかし,いかなるトレンド逆転戦略にも一定のリスクがあります.慎重に使用し,適切なポジションスケールを調整する必要があります.この戦略は,逆転操作に慣れ親しんだリスク意識のある取引ユーザーのために適しています.

ストラテジーソースコード
/*backtest
start: 2023-09-29 00:00:00
end: 2023-10-29 00:00:00
period: 1d
basePeriod: 1h
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/
// © gsanson66


//This code is based on the Narrow Range strategy
//Interactive Broker fees are applied on this strategy
//@version=5
strategy("NARROW RANGE BACKTESTING", shorttitle="NR BACKTESTING", overlay=true, initial_capital=1000, default_qty_type=strategy.fixed, commission_type=strategy.commission.percent, commission_value=0.18)


//--------------------------------FUNCTIONS------------------------------------//

//@function to print label
debugLabel(txt, color) =>
    label.new(bar_index, high, text = txt, color=color, style = label.style_label_lower_right, textcolor = color.black, size = size.small)

//@function which looks if the close date of the current bar falls inside the date range
inBacktestPeriod(start, end) => (time >= start) and (time <= end)


//--------------------------------USER INPUTS------------------------------------//

//Narrow Range Length 
nrLength = input.int(4, minval=2, title="Narrow Range Length", group="Strategy parameters")
//Risk Management
stopLossInput = input.float(0.5, title="Stop Loss (in percentage of reference range)", group="Strategy parameters")
//Money Management
fixedRatio = input.int(defval=400, minval=1, title="Fixed Ratio Value ($)", group="Money Management")
increasingOrderAmount = input.int(defval=200, minval=1, title="Increasing Order Amount ($)", group="Money Management")
//Backtesting period
startDate = input(title="Start Date", defval=timestamp("1 Janv 2020 00:00:00"), group="Backtesting Period")
endDate = input(title="End Date", defval=timestamp("1 July 2024 00:00:00"), group="Backtesting Period")


//--------------------------------VARIABLES INITIALISATION--------------------------//
strategy.initial_capital = 50000
bool nr = na
var bool long = na
var bool short = na
var float stopPriceLong = na
var float stopLossLong = na
var float takeProfitLong = na
var float stopPriceShort = na
var float stopLossShort = na
var float takeProfitShort = na
var float takeProfit = na
var float stopLoss = na
bool inRange = na
int closedtrades = strategy.closedtrades
equity = math.abs(strategy.equity - strategy.openprofit)
var float capital_ref = strategy.initial_capital
var float cashOrder = strategy.initial_capital * 0.95


//------------------------------CHECKING SOME CONDITIONS ON EACH SCRIPT EXECUTION-------------------------------//

//Checking if the date belong to the range
inRange := true

//Checking performances of the strategy
if equity > capital_ref + fixedRatio
    spread = (equity - capital_ref)/fixedRatio
    nb_level = int(spread)
    increasingOrder = nb_level * increasingOrderAmount
    cashOrder := cashOrder + increasingOrder
    capital_ref := capital_ref + nb_level*fixedRatio
if equity < capital_ref - fixedRatio
    spread = (capital_ref - equity)/fixedRatio
    nb_level = int(spread)
    decreasingOrder = nb_level * increasingOrderAmount
    cashOrder := cashOrder - decreasingOrder
    capital_ref := capital_ref - nb_level*fixedRatio

//We check if a trade has been closed to cancel all previous orders
if closedtrades > closedtrades[1]
    strategy.cancel("Long")
    strategy.cancel("Short")
    stopPriceLong := na
    stopPriceShort := na

//Checking if we close all trades in case where we exit the backtesting period
if strategy.position_size!=0 and not inRange
    debugLabel("END OF BACKTESTING PERIOD : we close the trade", color=color.rgb(116, 116, 116))
    strategy.close_all()
    long := na
    short := na
    stopPriceLong := na
    stopLossLong := na
    takeProfitLong := na
    stopPriceShort := na
    stopLossShort := na
    takeProfitShort := na
    takeProfit := na
    stopLoss := na

//----------------------------------FINDING NARROW RANGE DAY------------------------------------------//

// We find the Narrow Range Day
if low > low[nrLength] and high < high[nrLength]
    nr := true 


//------------------------------------STOP ORDERS--------------------------------------------//

// We handle plotting of stop orders and cancellation of other side order if one order is triggered
if strategy.position_size > 0 and not na(stopPriceLong) and not na(stopPriceShort)
    long := true
    strategy.cancel("Short")
    stopPriceLong := na
    stopPriceShort := na
    takeProfit := takeProfitLong
    stopLoss := stopLossLong
if strategy.position_size < 0 and not na(stopPriceLong) and not na(stopPriceShort)
    short := true
    strategy.cancel("Long") 
    stopPriceLong := na
    stopPriceShort := na
    takeProfit := takeProfitShort
    stopLoss := stopLossShort


//------------------------------------STOP LOSS & TAKE PROFIT--------------------------------//

// If an order is triggered we plot TP and SL
if not na(takeProfit) and not na(stopLoss) and long
    if high >= takeProfit and closedtrades == closedtrades[1] + 1
        takeProfit := na
        stopLoss := na
        long := na
    if low <= stopLoss and closedtrades == closedtrades[1] + 1
        takeProfit := na
        stopLoss := na
        long := na
if not na(takeProfit) and not na(stopLoss) and short
    if high >= stopLoss and closedtrades == closedtrades[1] + 1
        takeProfit := na
        stopLoss := na
        short := na
    if low <= takeProfit and closedtrades == closedtrades[1] + 1
        takeProfit := na
        stopLoss := na
        short := na


//-----------------------------LONG/SHORT CONDITION-------------------------//

// Conditions to create two stop orders (one for Long and one for Short) and SL & TP calculation
if nr and inRange and strategy.position_size == 0
    stopPriceLong := high[4]
    takeProfitLong := high[4] + (high[4] - low[4])
    stopLossLong := high[4] - (high[4] - low[4])*stopLossInput
    qtyLong = cashOrder/stopPriceLong
    strategy.entry("Long", strategy.long, qtyLong, stop=stopPriceLong)
    strategy.exit("Exit Long", "Long", limit=takeProfitLong ,stop=stopLossLong)
    stopPriceShort := low[4]
    takeProfitShort := low[4] - (high[4] - low[4])
    stopLossShort := low[4] + (high[4] - low[4])*stopLossInput
    qtyShort = cashOrder/stopPriceShort
    strategy.entry("Short", strategy.short, qtyShort, stop=stopPriceShort)
    strategy.exit("Exit Short", "Short", limit=takeProfitShort ,stop=stopLossShort)


//--------------------------PLOTTING ELEMENT----------------------------//

plotshape(nr, "NR", shape.arrowdown, location.abovebar, color.rgb(255, 132, 0), text= "NR4", size=size.huge)
plot(stopPriceLong, "Stop Order", color.blue, 3, plot.style_linebr)
plot(stopPriceShort, "Stop Order", color.blue, 3, plot.style_linebr)
plot(takeProfit, "Take Profit", color.green, 3, plot.style_linebr)
plot(stopLoss, "Stop Loss", color.red, 3, plot.style_linebr)