価格内部変動チャネルに基づく強気と弱気の戦略


作成日: 2023-12-11 15:56:28 最終変更日: 2023-12-11 15:56:28
コピー: 2 クリック数: 590
1
フォロー
1621
フォロワー

価格内部変動チャネルに基づく強気と弱気の戦略

概要

この戦略は,価格の内部チャネルを使用して将来の価格動きを判断し,トレンド追跡戦略に属します.価格が一定数の内部価格波動チャネルを形成するときに,トレンド転換信号として判断し,買取または販売操作を行います.移動平均フィルターとストップ損失ストップの設定を組み合わせて利益をロックし,より一般的な定量取引戦略に属します.

戦略原則

この策略は,前後2つのK線の最高価格と最低価格の大きさの関係によって内部通路の形成を判断する.一定数のK線が,最高価格が前K線の最高価格より低い,最低価格が前K線の最低価格より高い条件を満たす場合に,価格の内部通路と判断する.

価格の内部通路の形成を判断すると同時に,戦略は,その内部通路の方向も判断する.看板の内部通路であれば,買入シグナルを生じ,看板の内部通路であれば,売出シグナルを生じする.したがって,この戦略は双方向取引戦略の類である.

偽の信号をフィルターするために,この戦略は移動平均指標も導入した.価格が移動平均以上または以下である場合にのみ,実際の取引シグナルが生成される.これは,市場を整頓する際に誤った取引を一定程度に防ぐことができる.

入場後,戦略はまた,ユーザーの選択に応じて,ストップ損失の停止ポイントを設定する.選択可能な停止方法は3種類あります:固定ポイントの停止,ATRの停止,前期最高最低ポイントの停止.ストップポイントの設定は,リスク・リターン比率の停止である.これは,利益を一定程度にロックし,リスクを制御することができます.

優位分析

この戦略の最大の優点は,トレンドの転換点を識別する能力の強さにある.価格が一定数の内部通路を形成すると,多くの場合,大きな下落が起ころうとしていることを示唆する.この判断は,伝統的な技術分析理論と高度に一致する.

また,戦略自体は非常に構成可能である.ユーザーは,内部チャネルの数,移動平均周期,止損停止方法などのパラメータを自由に選択することができる.これは,異なる品種,異なる取引スタイルに大きな柔軟性を提供します.

最後に,戦略に付加された移動平均のフィルターとストップ・ストップの設定も,取引リスクを大幅に軽減しています.これは,戦略をあらゆる種類の市場環境の取引に適用できるようにしています.

リスク分析

この策略の最大のリスクは,トレンド判断に誤りが生じる可能性が高いことである.内部チャネルは価格逆転を完全に決定することができないので,誤判の可能性はある.確定した数が不足すると,偽信号が生じる可能性がある.

さらに,整合や振動の市場では,この戦略はまったく適用されません.価格が上下波動するが,トレンドが確立されていない場合,この戦略は誤った信号を連続的に発生します.これは戦略のメカニズムによって決定されます.

最後に,ストップ・ロスの設定が保守的すぎると,戦略が十分な長期間保持できず,大きなトレンドの利益を捕捉することができません.これはユーザーの自己バランス設定を必要とします.

最適化の方向

この戦略の最適化の余地はある.いくつかの可能な最適化の方向は以下の通りです.

  1. 内部チャネルの数と形状を最適化します. 異なる数または異なる配列の組み合わせの下で取引の効果をテストできます.

  2. 移動平均の周期パラメータを最適化して,トレンドの方向性をよりよく判断できるようにする.現在のデフォルト周期は,すべての品種に適していない可能性があります.

  3. 他の指標フィルターを追加する.例えば,ブリン帯を導入し,価格がブリン帯を突破して上線または下線するときにのみ取引シグナルを生成する.

  4. ストップ・ストップ・パラメータの最適化により,戦略はより長い期間でポジションを保持することができ,スーパートレンドの利益を捕獲できます.

全体として,この戦略は,トレンド判断の正確さによって存在している.判断の正確さを保証できれば,適切なリスク管理の設定に付加されれば,より効果的なアルゴリズム取引を行うことができます.

要約する

この戦略は,全体として,価格の内部通路に基づいて将来の価格動向を判断する量化取引戦略である.それは,トレンド追跡とトレンド反転の2つの判断方法を組み合わせて,一定の優位性を持っている.しかし,いくつかの最適化可能なスペースも存在し,投資家は,特定の品種と取引環境に合わせて,自分のニーズに応じて調整することができます.この戦略は,パラメータの最適化後に,非常に理想的な量化取引戦略の1つになる可能性があります.

ストラテジーソースコード
/*backtest
start: 2023-12-03 00:00:00
end: 2023-12-10 00:00:00
period: 3m
basePeriod: 1m
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/

// From "Day Trading Cryptocurrency 
// Strategies, Tactics, Mindset, and Tools Required To Build Your 
// New Income Stream"
// by Phil C. Senior

// "Inside bars are a two -bar pattern. They can indicate either a continuation of the 
// existing move or a reversal. A continuation occurs when there is no significant 
// support or resistance level in sight, while a reversal occurs close to a strong sup- 
// port or resistance level...
// ...A lot of traders are aware of inside bars but few manage to make money with 
// them. Why is this so? It goes back to interpreting price action. A lot of traders look 
// to trade in geometric ways. What I mean is that they search for fancy shapes on a 
// chart and think that this is what represents true price action. 
// This is not the case. A shape is just a shape. The formation by itself means 
// nothing unless underlying order flow backs it up. This is why it’s extremely impor- 
// tant that you look for inside bars when a trend is already in place. The best place to 
// look for them is in the beginning of trends."

// © tweakerID

//@version=4
strategy("Inside Bar Strategy w/ SL", 
     overlay=true, 
     default_qty_type=strategy.percent_of_equity, 
     default_qty_value=100, 
     initial_capital=10000, 
     commission_value=0.04, 
     calc_on_every_tick=false, 
     slippage=0)

direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)
strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))

/////////////////////// STRATEGY INPUTS ////////////////////////////////////////
title1=input(true, "-----------------Strategy Inputs-------------------")  

i_NBars = input(defval=1, type=input.integer, title="# Of Inside Bars in pattern", options=[1, 2, 3, 4])
i_BarsDirection = input(false, title="Only trade using complete bullish or bearish patterns")
i_MAFilter = input(true, title="Use MA Trend Filter")
i_MALen = input(65, title="MA Length")

/////////////////////// BACKTESTER /////////////////////////////////////////////
title2=input(true, "-----------------General Inputs-------------------")  

// Backtester General Inputs
i_SL=input(true, title="Use Stop Loss and Take Profit")
i_SLType=input(defval="ATR Stop", title="Type Of Stop", options=["Strategy Stop", "Swing Lo/Hi", "ATR Stop"])
i_SPL=input(defval=10, title="Swing Point Lookback")
i_PercIncrement=input(defval=1, step=.1, title="Swing Point SL Perc Increment")*0.01
i_ATR = input(14, title="ATR Length")
i_ATRMult = input(5, step=.1, title="ATR Multiple")
i_TPRRR = input(2, step=.1, title="Take Profit Risk Reward Ratio")
TS=input(false, title="Trailing Stop")

// Bought and Sold Boolean Signal
bought = strategy.position_size > strategy.position_size[1] 
 or strategy.position_size < strategy.position_size[1]

// Price Action Stop and Take Profit
LL=(lowest(i_SPL))*(1-i_PercIncrement)
HH=(highest(i_SPL))*(1+i_PercIncrement)
LL_price = valuewhen(bought, LL, 0)
HH_price = valuewhen(bought, HH, 0)
entry_LL_price = strategy.position_size > 0 ? LL_price : na 
entry_HH_price = strategy.position_size < 0 ? HH_price : na 
tp=strategy.position_avg_price + (strategy.position_avg_price - entry_LL_price)*i_TPRRR
stp=strategy.position_avg_price - (entry_HH_price - strategy.position_avg_price)*i_TPRRR

// ATR Stop
ATR=atr(i_ATR)*i_ATRMult
ATRLong = ohlc4 - ATR
ATRShort = ohlc4 + ATR
ATRLongStop = valuewhen(bought, ATRLong, 0)
ATRShortStop = valuewhen(bought, ATRShort, 0)
LongSL_ATR_price = strategy.position_size > 0 ? ATRLongStop : na 
ShortSL_ATR_price = strategy.position_size < 0 ? ATRShortStop : na 
ATRtp=strategy.position_avg_price + (strategy.position_avg_price - LongSL_ATR_price)*i_TPRRR
ATRstp=strategy.position_avg_price - (ShortSL_ATR_price - strategy.position_avg_price)*i_TPRRR


// Strategy Stop
float LongStop = valuewhen(bought,low[1],0)*(1-i_PercIncrement)
float ShortStop = valuewhen(bought,high[1],0)*(1+i_PercIncrement)
float StratTP = na
float StratSTP = na

/////////////////////// STRATEGY LOGIC /////////////////////////////////////////

MAFilter=close > sma(close, i_MALen)
plot(i_MAFilter ? sma(close, i_MALen) : na)
bullBar=close > open
bearBar=close < open
contbullBar=barssince(not bullBar) >= (i_NBars+1)
contbearBar=barssince(not bearBar) >= (i_NBars+1)

InsideBar(NBars) =>
    Inside1Bar=high < high[1] and low > low[1] 
    Inside2Bar=high < high[2] and low > low[2] and Inside1Bar
    Inside3Bar=high < high[3] and low > low[3] and Inside1Bar and Inside2Bar
    Inside4Bar=high < high[4] and low > low[4] and Inside1Bar and Inside2Bar and Inside3Bar
    if NBars == 1
        inside1Bar=Inside1Bar
        [inside1Bar]
    else if NBars == 2
        inside2Bar=Inside2Bar
        [inside2Bar]
    else if NBars == 3
        inside3Bar=Inside3Bar   
        [inside3Bar]
    else if NBars == 4
        inside4Bar=Inside4Bar
        [inside4Bar]
    else
        [na]
[insideBar] = InsideBar(i_NBars) 
    
bullInsideBar=bar_index > 40 and insideBar and bullBar 
     and (i_BarsDirection ? contbullBar : true) and (i_MAFilter ? MAFilter : true)
bearInsideBar=bar_index > 40 and insideBar and bearBar 
     and (i_BarsDirection ? contbearBar : true) and (i_MAFilter ? not MAFilter : true)

BUY = bullInsideBar
SELL = bearInsideBar

//Debugging Plots
plot(contbullBar ? 1:0, transp=100, title="contbullBar")
plot(contbearBar ? 1:0, transp=100, title="contbearBar")

//Trading Inputs
DPR=input(true, "Allow Direct Position Reverse")
reverse=input(false, "Reverse Trades")

// Entries
if reverse
    if not DPR
        strategy.entry("long", strategy.long, when=SELL and strategy.position_size == 0)
        strategy.entry("short", strategy.short, when=BUY and strategy.position_size == 0)
    else     
        strategy.entry("long", strategy.long, when=SELL)
        strategy.entry("short", strategy.short, when=BUY)
else
    if not DPR 
        strategy.entry("long", strategy.long, when=BUY and strategy.position_size == 0)
        strategy.entry("short", strategy.short, when=SELL and strategy.position_size == 0)
    else
        strategy.entry("long", strategy.long, when=BUY)
        strategy.entry("short", strategy.short, when=SELL)

SL= i_SLType == "Swing Lo/Hi" ? entry_LL_price : i_SLType == "ATR Stop" ? LongSL_ATR_price : LongStop
SSL= i_SLType == "Swing Lo/Hi" ? entry_HH_price : i_SLType == "ATR Stop" ? ShortSL_ATR_price : ShortStop
TP= i_SLType == "Swing Lo/Hi" ? tp : i_SLType == "ATR Stop" ? ATRtp : StratTP
STP= i_SLType == "Swing Lo/Hi" ? stp : i_SLType == "ATR Stop" ? ATRstp : StratSTP

//TrailingStop
dif=(valuewhen(strategy.position_size>0 and strategy.position_size[1]<=0, high,0))
 -strategy.position_avg_price
trailOffset     = strategy.position_avg_price - SL
var tstop = float(na)
if strategy.position_size > 0
    tstop := high- trailOffset - dif
    if tstop<tstop[1]
        tstop:=tstop[1]
else
    tstop := na
StrailOffset     = SSL - strategy.position_avg_price
var Ststop = float(na)
Sdif=strategy.position_avg_price-(valuewhen(strategy.position_size<0 
 and strategy.position_size[1]>=0, low,0))
if strategy.position_size < 0
    Ststop := low+ StrailOffset + Sdif
    if Ststop>Ststop[1]
        Ststop:=Ststop[1]
else
    Ststop := na

strategy.exit("TP & SL", "long", limit=TP, stop=TS? tstop : SL, when=i_SL)
strategy.exit("TP & SL", "short", limit=STP, stop=TS? Ststop : SSL, when=i_SL)

/////////////////////// PLOTS //////////////////////////////////////////////////

plot(i_SL and strategy.position_size > 0 and not TS ? SL : i_SL and strategy.position_size > 0 and TS ? tstop : na , title='SL', style=plot.style_cross, color=color.red)
plot(i_SL and strategy.position_size < 0 and not TS ? SSL : i_SL and strategy.position_size < 0 and TS ? Ststop : na , title='SSL', style=plot.style_cross, color=color.red)
plot(i_SL and strategy.position_size > 0 ? TP : na, title='TP', style=plot.style_cross, color=color.green)
plot(i_SL and strategy.position_size < 0 ? STP : na, title='STP', style=plot.style_cross, color=color.green)
// Draw price action setup arrows
plotshape(BUY ? 1 : na, style=shape.triangleup, location=location.belowbar, 
 color=color.green, title="Bullish Setup", size=size.auto)
plotshape(SELL ? 1 : na, style=shape.triangledown, location=location.abovebar, 
 color=color.red, title="Bearish Setup", size=size.auto)