ダイナミック・プライス・スウィング・オシレーター戦略

作者: リン・ハーンチャオチャン開催日:2023年11月23日 10:45:02
タグ:

img

概要

ダイナミック・プライス・スウィング・オシレーター (Dynamic Price Swing Oscillator) は,価格動向を特定するための戦略である.動向平均,価格チャネル,フィボナッチ・リトラセーションを組み合わせ,ダイナミック・エントリー&エグジットを実装する.この戦略の利点は,柔軟な操作のために価格動向の変化を特定できることである.

原則

この戦略は主に以下の原則に基づいています.

  1. 価格トレンドの方向性を決定するために高速EMAと遅いEMAを使用し,トレンドに反する取引を防ぐ

  2. 突破信号を決定するために価格上限と下限のチャネルを用い,価格が上限チャネルを突破するとショート,下限チャネルを突破するとロング

  3. 判断の信号として移動平均のクロスオーバーを使用し 金色のクロスでロング,死のクロスでショート

  4. 判断信号としてフィボナッチリトレースラインを使用し,価格がフィボナッチ上限線を突破するとショート,下限線を突破するとロング

これらの指標に基づいて 市場への参入やストップ・ロスト,収益脱出のメカニズムが決定された後,

利点分析

この戦略の最大の利点は,価格動向の変化を特定するために複数の指標を組み合わせることです.主な利点は以下の通りです.

  1. 主要なトレンドを決定するために,迅速な EMA と遅い EMA を使用することで,トレンドに反する取引を防止し,損失を減らすことができます.

  2. 価格チャネル判断は,より大きな利益の可能性を持つ価格ブレイク機会を捉えることができます

  3. 移動平均のクロスオーバー判断は単純で実用的で,実行が簡単です

  4. フィボナッチリトレースは,戦略をより3次元的にするために別の判断方法を追加します.

リスク分析

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

  1. 迅速なEMAと遅いEMAのパラメータの設定が正しくない場合,誤った判断につながる可能性があります.

  2. 価格チャネルの上限と下限を突破するタイミングが正しくない場合,損失オーダーが発生する可能性があります.

  3. 移動平均の交差値の選択も慎重でなければならない

  4. フィボナッチ回転帯の誤った幅設定も判断効果に影響を与える

これらのリスクはパラメータの最適化によって軽減できます

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

この戦略に最適化できるいくつかの方向性があります:

  1. EMA サイクル,チャネル幅,移動平均期などのパラメータをテストし最適化します

  2. RSIやボリンジャー・バンドなどの他の技術指標に対する判断規則を追加する

  3. OBVなどの取引量エネルギー指標を組み合わせてブレイクアウトの信頼性を決定する

  4. 機械学習やその他の技術を使用して,最適なパラメータを自動的に探す

結論

ダイナミック・プライス・スウィング・オシレーターは,高度に柔軟で適応性の高い戦略である.複数の指標判断を通じてブレイクアウトを決定した後,価格変化と取引に動的に適応することができる.いくつかのリスクがあるにもかかわらず,戦略の安定性と収益性を向上させるために継続的な最適化によって軽減することができる.戦略は深入の研究に値する.


/*backtest
start: 2023-11-15 00:00:00
end: 2023-11-22 00:00:00
period: 1m
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/
//@version=4

// ██████╗██████╗ ███████╗ █████╗ ████████╗███████╗██████╗     ██████╗ ██╗   ██╗    
//██╔════╝██╔══██╗██╔════╝██╔══██╗╚══██╔══╝██╔════╝██╔══██╗    ██╔══██╗╚██╗ ██╔╝                       
//██║     ██████╔╝█████╗  ███████║   ██║   █████╗  ██║  ██║    ██████╔╝ ╚████╔╝                        
//██║     ██╔══██╗██╔══╝  ██╔══██║   ██║   ██╔══╝  ██║  ██║    ██╔══██╗  ╚██╔╝                         
//╚██████╗██║  ██║███████╗██║  ██║   ██║   ███████╗██████╔╝    ██████╔╝   ██║                          
// ╚═════╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝╚═════╝     ╚═════╝    ╚═╝                          
                                                                                                     
//███████╗ ██████╗ ██╗     ██╗   ██╗████████╗██╗ ██████╗ ███╗   ██╗███████╗ ██╗ █████╗ ███████╗ █████╗ 
//██╔════╝██╔═══██╗██║     ██║   ██║╚══██╔══╝██║██╔═══██╗████╗  ██║██╔════╝███║██╔══██╗╚════██║██╔══██╗
//███████╗██║   ██║██║     ██║   ██║   ██║   ██║██║   ██║██╔██╗ ██║███████╗╚██║╚██████║    ██╔╝╚█████╔╝
//╚════██║██║   ██║██║     ██║   ██║   ██║   ██║██║   ██║██║╚██╗██║╚════██║ ██║ ╚═══██║   ██╔╝ ██╔══██╗
//███████║╚██████╔╝███████╗╚██████╔╝   ██║   ██║╚██████╔╝██║ ╚████║███████║ ██║ █████╔╝   ██║  ╚█████╔╝
//╚══════╝ ╚═════╝ ╚══════╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝ ╚═╝  ╚═══╝╚══════╝ ╚═╝ ╚════╝    ╚═╝   ╚════╝ 
                                                                                                     

strategy(shorttitle='DPS',title='Dynamic Price Swing', overlay=true, scale=scale.left, initial_capital = 1000, process_orders_on_close=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type=strategy.commission.percent, commission_value=0.18, calc_on_every_tick=true)


// -----------------  Strategy Inputs -------------------------------------------------------------
//Backtest dates with auto finish date of today
start = input(defval = timestamp("22 June 2021 00:00 -0500"), title = "Start Time")
finish = input(defval = timestamp("31 December 2021 00:00 -0600"), title = "End Time")
window()  => true       // create function "within window of time"

// Strategy Selection - Long, Short, or Both
stratinfo = input(true, "Long/Short for Mixed Market, Long for Bull, Short for Bear")
strat = input(title="Trade Types", defval="Long/Short", options=["Long Only", "Long/Short", "Short Only"])
strat_val = strat == "Long Only" ? 1 : strat == "Long/Short" ? 0 : -1

// Risk Management Inputs
sl= input(10.0, "Stop Loss %", minval = 0, maxval = 100, step = 0.01)
stoploss = sl/100
tp = input(20.0, "Target Profit %", minval = 0, maxval = 100, step = 0.01)
TargetProfit = tp/100
ld = input(2, "Stop Trading After This Many Losing Days", type=input.integer, minval=0, maxval=100, step=1)
// strategy.risk.max_cons_loss_days(count=ld)
ml = input(10, "Maximum % of Equity Lost to Halt Trading", type=input.integer, minval=1, maxval=100, step=1)
// strategy.risk.max_drawdown(value=ml, type=strategy.percent_of_equity)

// Price Movement Inputs
PriceInfo = input(true, "Number of bars to look back on to calculate price swings.")
lkbk = input(5,"Max Lookback Period")
high_source = input(high,"High Source")
low_source= input(low,"Low Source")

// Trend Inputs
TrendInfo = input(true, "Trend uses Fast and Slow EMA to prevent going the wrong direction")
length = input(14, "RSI Length", minval=1)
fastLength = input(12, minval=1, title="EMA Fast Length")
slowLength = input(26, minval=1, title="EMA Slow Length")

// Trigger Selection
usePrice = input(true, "Use Average Price Channel Only")
useMA = input(false, "Use Price Moving Average Only")
useFib = input(false, "Use Price Fibonacci Average Only")


// Trend Direction Calculation
rsi_ema = ema(rsi(close, length), length)
emaA = ema(rsi_ema, fastLength)                                     
emaFast = 2 * emaA - ema(emaA, fastLength)
emaB = ema(rsi_ema, slowLength)                                     
emaSlow = 2 * emaB - ema(emaB, slowLength) 


bullishRule =emaFast > emaSlow and rsi_ema >=rsi_ema[1]
bearishRule =emaFast < emaSlow and rsi_ema <= rsi_ema[1]


// Price Channel

lasthigh = highest(high_source, lkbk)
lastlow = lowest(low_source, lkbk)


// Fibonacci and Moving Average
MA1 = sma(close,5),HA1 = sma(high,5),LA1 = sma(low,5),
MA2 = sma(close,8),HA2 = sma(high,8),LA2 = sma(low,8),
MA3 = sma(close,13),HA3 = sma(high,13),LA3 = sma(low,13),
MA4 = sma(close,21),HA4 = sma(high,21),LA4 = sma(low,21),
MA5 = sma(close,34),HA5 = sma(high,34),LA5 = sma(low,34),
MA6 = sma(close,55),HA6 = sma(high,55),LA6 = sma(low,55),
MA7 = sma(close,89),HA7 = sma(high,89),LA7 = sma(low,89),

CMA = (MA1+MA2+MA3+MA4+MA5+MA6+MA7)/7,
HMA = (HA1+HA2+HA3+HA4+HA5+HA6+HA7)/7,
HMA2 = CMA + (atr(lkbk)*1.618)

LMA = (LA1+LA2+LA3+LA4+LA5+LA6+LA7)/7,
LMA2 = CMA - (atr(lkbk)*1.618)


plot(CMA, title="CMA", color=color.new(#00ffaa, 70), linewidth=2)
plot(HMA, title="HMA", color=color.maroon, linewidth=2)
plot(HMA2, title="HMA Fib", color=color.red, linewidth=3)
plot(LMA, title="LMA", color=color.green, linewidth=2)
plot(LMA2, title="LMA Fib", color=color.teal, linewidth=3)

    

// -------------------------------- Entry and Exit Logic ------------------------------------

// Entry Logic

Channel_Sell = close >= lasthigh[1] and bearishRule and window()
Channel_Buy =  close <= lastlow[1] and bullishRule and window()

MA_Sell = high>HMA and window()
MA_Buy = low<LMA and window()

Fib_Sell = high>HMA2 and window()
Fib_Buy = low<LMA2 and window()

qty = strategy.equity/close


// Strategy Entry and Exit with built in Risk Management
if(strategy.opentrades==0 and strat_val>-1)
    GoLong = usePrice ? Channel_Buy : useMA ? MA_Buy : useFib ? Fib_Buy : false
    if (GoLong)
        strategy.entry("LONG", strategy.long, qty)

if(strategy.opentrades==0 and strat_val<1)
    GoShort = usePrice ? Channel_Sell : useMA ? MA_Sell : useFib ? Fib_Sell : false
    if (GoShort) 
        strategy.entry("SHORT", strategy.short, qty)


longStopPrice  = strategy.position_avg_price * (1 - stoploss)
longTakePrice  = strategy.position_avg_price * (1 + TargetProfit)
shortStopPrice = strategy.position_avg_price * (1 + stoploss)
shortTakePrice = strategy.position_avg_price * (1 - TargetProfit)

if (strategy.position_size > 0)
    strategy.exit(id="Exit Long", from_entry = "LONG", stop = longStopPrice, limit = longTakePrice)
    
if (strategy.position_size < 0)
    strategy.exit(id="Exit Short", from_entry = "SHORT", stop = shortStopPrice, limit = shortTakePrice)

CloseShort= usePrice ? Channel_Buy : useMA ? MA_Buy : useFib ? Fib_Buy : false
CloseLong = usePrice ? Channel_Sell : useMA ? MA_Sell : useFib ? Fib_Sell : false

if(CloseLong and strategy.position_size > 0)
    strategy.close("LONG")
        

if(CloseShort and strategy.position_size < 0)
    strategy.close("SHORT")


もっと