超トレンド指標と株式曲線取引に基づく定量的な取引戦略

作者: リン・ハーンチャオチャン,日付: 2024-01-15 11:41:53
タグ:

img

概要

この戦略の主なアイデアは,スーパートレンド指標と株式曲線取引を組み合わせることです.スーパートレンド指標が購入または売却信号を生成すると,我々は直接取引を実行しません.代わりに,現在の株式曲線が移動平均を下回っているかどうかを確認します.株式曲線が移動平均を下回っている場合にのみポジションを開きます.株式曲線が移動平均を下回っているとき,我々は現在の戦略のための取引を一時停止します.これは損失の拡大を効果的に防ぐことができます.

戦略の論理

この戦略は主に2つの部分で構成されています.

  1. 超トレンド指標
  2. 株式曲線取引

スーパートレンド指標の計算式は:

上部帯 = ソース価格 - ATR マルチプリキュア * ATR 下帯 = ソース価格 + ATR マルチプリキュア * ATR

ATRは,平均の真の範囲を表す.スーパートレンドインジケーターは,ATRを使用して上下帯を設定する.上下帯の上のブレイクアウトは販売信号を表し,下下帯の下のブレイクアウトは購入信号を表します.

株式曲線取引の背後にある考えは,戦略の株式曲線の移動平均を取ることです.株式曲線が移動平均を下回ると,現在の戦略の取引を一時停止し,再び取引を開始する前に株式曲線が移動平均以上に反転するのを待つことです.

この戦略は,2つのテクニックを組み合わせ,スーパートレンドインジケーターが取引信号を生成した後,直接取引には出ない.代わりに,現在の株式曲線が移動平均値を超えるかどうかを確認します.両方の条件が満たされたときにのみ,ポジションを開きます.これはスーパートレンドインジケーター自体に固有のリスクを効果的に軽減し,過度の損失を防ぐことができます.

利点

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

  1. 超トレンド指標のリスクを効果的に防ぐことができます.超トレンド指標自体は損失を効果的に抑制することはできません.株式曲線取引はこの欠点を補います.

  2. 取引が不良になると,過剰な損失を避けるために取引を一時停止します.市場が回復した後,取引を再開できます.

  3. 手動の介入なしにポジションを自動的に管理できます. 株式曲線が移動平均を下回ると自動停止され,株式曲線がそれ以上に反転すると再開されます.

リスク

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

  1. 誤ったパラメータ設定により,株式曲線取引が非効率になる.適切な移動平均期間の選択が必要です.

  2. 市場動向が変わると ポジションを迅速に調整できず 損失を伴う可能性があります

  3. 株価の曲線が反発するのを待つ間に 良い取引機会を逃すかもしれません

対策:

  1. パラメータを最適化し 最適な移動平均期間を選択します

  2. 傾向を判断し,それに応じてポジションを調整するために他の指標を組み込む.

  3. 取引停止の期間を短縮し,機会を逃す可能性を減らす.

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

戦略を最適化するには次の要素が必要です

  1. 適正なATR期間と倍数を見つけるために,異なるパラメータの組み合わせを試験する.

  2. 移動平均は,指数関数移動平均,ハル移動平均などです.

  3. 市場動向を判断するために他の指標を追加し,動向が変化するとポジションを調整します.

  4. 移動 平均 期間 を 最適 に し て 最良 の バランス を 見つけ ます.長すぎ た 期間 は 機会 を 逃す こと が でき,短すぎ た 期間 は 頻繁に 休憩 する こと が でき ます.

  5. ストップ・ロスの限界を設定します ストップ・ロスの限界を設定します

結論

この戦略は,スーパートレンド指標と株式曲線取引を巧みに組み合わせ,両方のテクニックの強みを活用しています.テスト結果は,ほとんどの場合,株式曲線取引を適用すると実際に収益性が低下することを示しています.したがって,この戦略は防御的なトレーダーにより適しています.パラメータと論理最適化により,非常に実践的な定量的な取引戦略になることができます.


/*backtest
start: 2023-01-14 00:00:00
end: 2024-01-14 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy('Supertrend & Equity curve with EMA', overlay=false, format=format.price, precision=2, initial_capital=100000)

eqlen = input.int(25, "EQ EMA len", group = "New Equity Curve Settings")
shEQandMA = input.bool(true, "Show Original Equity Curve and MA")
shEQfilt = input.bool(true, "Show Filtered Equity Curve by MA")

Periods = input(title='ATR Period', defval=10, group = "SuperTrend Settings")
src = input(hl2, title='Source', group = "SuperTrend Settings")
Multiplier = input.float(title='ATR Multiplier', step=0.1, defval=3.0, group = "SuperTrend Settings")
changeATR = input(title='Change ATR Calculation Method ?', defval=true, group = "SuperTrend Settings")

//SuperTrend Code
atr2 = ta.sma(ta.tr, Periods)
atr = changeATR ? ta.atr(Periods) : atr2
up = src - Multiplier * atr
up1 = nz(up[1], up)
up := close[1] > up1 ? math.max(up, up1) : up
dn = src + Multiplier * atr
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? math.min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend

// Strategy main code
buySignal = trend == 1 and trend[1] == -1
sellSignal = trend == -1 and trend[1] == 1
if buySignal
    strategy.entry('Long', strategy.long)
if sellSignal
    strategy.entry('Short', strategy.short)



//Equity Curve calcs
eq = strategy.netprofit
ch = ta.change(eq)
neq = ch != 0 ? eq : na
mova = ta.ema(neq,eqlen)

// New Equity Curve
var float neweq = 0
var int ttrades = 0
var int wintrades = 0
var int losetrades = 0

switch
    strategy.netprofit == strategy.netprofit[1]  => na
    strategy.netprofit < mova and strategy.netprofit[1] > mova  => neweq := neweq + ch
    strategy.netprofit < mova and strategy.netprofit[1] < mova => na
    strategy.netprofit > mova and strategy.netprofit[1] > mova => neweq := neweq + ch

newch = ta.change(neweq)
switch
    newch == 0 => na
    newch > 0 => 
        wintrades := wintrades +1
        ttrades := ttrades +1
    newch < 0 =>
        losetrades := losetrades +1
        ttrades := ttrades +1

//plot(eq, linewidth = 2)
//plot(mova, color=color.red)
//plot(neweq, color= color.green, linewidth = 3)


//Table 
var testTable = table.new(position = position.top_right, columns = 5, rows = 10, bgcolor = color.green, border_width = 1)
table.cell(table_id = testTable, column = 0, row = 0, text = "Strategy: ", bgcolor=color.white)     
table.cell(table_id = testTable, column = 1, row = 0, text = "Original: ", bgcolor=color.white)     
table.cell(table_id = testTable, column = 2, row = 0, text = "Equity Curve EMA: ", bgcolor=color.white)     

table.cell(table_id = testTable, column = 0, row = 1, text = "Total Trades: ", bgcolor=color.white)     
table.cell(table_id = testTable, column = 0, row = 2, text = "Win Trades: ", bgcolor=color.white)     
table.cell(table_id = testTable, column = 0, row = 3, text = "Lose Trades: ", bgcolor=color.white)     
table.cell(table_id = testTable, column = 0, row = 4, text = "Win Rate: ", bgcolor=color.white)     
table.cell(table_id = testTable, column = 0, row = 5, text = "Net Profit: ", bgcolor=color.white)     

//Equity Curve EMA stat
table.cell(table_id = testTable, column = 2, row = 1, text = str.tostring(ttrades), bgcolor=color.white)     
table.cell(table_id = testTable, column = 2, row = 2, text = str.tostring(wintrades), bgcolor=color.white)
table.cell(table_id = testTable, column = 2, row = 3, text = str.tostring(losetrades), bgcolor=color.white)
table.cell(table_id = testTable, column = 2, row = 4, text = str.tostring(math.round(100*wintrades/ttrades,2)), bgcolor=color.white)
table.cell(table_id = testTable, column = 2, row = 5, text = str.tostring(math.round(neweq)), bgcolor=color.white)

//Original Strategy stat
// table.cell(table_id = testTable, column = 1, row = 1, text = str.tostring(strategy.closedtrades), bgcolor=color.white)     
// table.cell(table_id = testTable, column = 1, row = 2, text = str.tostring(strategy.wintrades), bgcolor=color.white)
// table.cell(table_id = testTable, column = 1, row = 3, text = str.tostring(strategy.losstrades), bgcolor=color.white)
// table.cell(table_id = testTable, column = 1, row = 4, text = str.tostring(math.round(100*strategy.wintrades/strategy.closedtrades,2)), bgcolor=color.white)
// table.cell(table_id = testTable, column = 1, row = 5, text = str.tostring(math.round(strategy.netprofit)), bgcolor=color.white)




//New Equity curve
var newcurve = array.new_float(0)
var int ida = 0
var bool printEQ = false
if newch !=0 
    array.push(newcurve, neweq)
if bar_index > last_bar_index - array.size(newcurve) - 1 - 20  and array.size(newcurve) > 20 
    printEQ := true
else
    printEQ := false

plot(printEQ and ida < strategy.closedtrades and shEQfilt ? array.get(newcurve, ida) : na, color=color.green, linewidth = 2)

if printEQ
    ida := ida + 1
if ida >= array.size(newcurve) and printEQ
    ida := array.size(newcurve) -1



//Original Equity curve
var newcurve2 = array.new_float(0)
var int ida2 = 0
var bool printEQ2 = false
if ch !=0 
    array.push(newcurve2, eq)
if bar_index > last_bar_index - array.size(newcurve2) - 1 - 20  and array.size(newcurve2) > 20 
    printEQ2 := true
else
    printEQ2 := false

plot(printEQ2 and ida2 < strategy.closedtrades and shEQandMA  ? array.get(newcurve2, ida2) : na, color=color.blue, linewidth = 2)

if printEQ2
    ida2 := ida2 + 1
if ida2 >= array.size(newcurve2) and printEQ2
    ida2 := array.size(newcurve2) -1



//Moving Average Array
var marray = array.new_float(0)
if ch
    array.push(marray, mova)

plot(printEQ2 and  array.size(marray) > 40 and shEQandMA ? array.get(marray, ida2-1) : na, color=color.red, linewidth = 1)

hline(0,"0 line", color=color.black, linestyle = hline.style_dotted)


if (last_bar_index-1) and array.size(newcurve2) > 20 and array.size(newcurve) > 20
    l = label.new(bar_index+2, array.get(newcurve2, array.size(newcurve2)-1), "Original Equity Curve", color=color.rgb(33, 149, 243, 85), textcolor = color.black, style = label.style_label_left)
    label.delete(l[1])
    f = label.new(bar_index+2, array.get(newcurve, array.size(newcurve)-1), "Filtered Equity Curve", color=color.rgb(69, 238, 97, 85), textcolor = color.black, style = label.style_label_left)
    label.delete(f[1])

もっと