ダイナミック・パターンのトレンド逆転戦略

作者: リン・ハーンチャオチャン,日付: 2023年12月13日 16:52:34
タグ:

img

概要

ダイナミック・パターンのトレンド・リバース戦略は,価格を予測するために線形回帰と移動平均線を使用して,取引信号を生成するためのパターンを形成する.予測価格が移動平均線を上向きに越えると購入信号を生み出し,下向きに下向きに越えると販売信号を生み出し,トレンド・リバースを捕捉する.

戦略の論理

  1. 予想価格を得るため,取引量に基づいて株式価格の線形回帰を計算する.
  2. 異なる条件下で移動平均を計算する
  3. 予想価格が上向きの移動平均を上回るときに購入信号を生成する
  4. 予測価格が移動平均を下回る値を超えると売り信号を生成する
  5. トレンド逆転のタイミングを決定するためのMACD指標を組み込む

上記の信号と複数の確認を組み合わせることで 誤った突破を回避し 精度が向上します

利点分析

  • 線形回帰を活用して価格傾向を予測し,信号の精度を向上させる
  • 移動平均パターンを用いてトレンド逆転を記録する
  • 取引量に基づく回帰が 経済的に意味を良くする
  • MACD などによる複数の確認は,誤った信号を減らす.

リスク分析

  • 線形回帰のパラメータは結果に重要な影響を与える
  • 移動平均値設定も信号品質に影響します
  • 偽の信号は 確証があるにも関わらず 危険性があります
  • コードをさらに最適化して取引頻度を削減し,利益率を向上させる

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

  • 線形回帰と移動平均のパラメータを最適化
  • 偽信号率を下げるために,より多くの確認条件を追加する
  • 傾向の逆転の質を判断するためのより多くの要因を組み込む
  • ストップ・ロスの戦略を強化し,個々の取引のリスクを軽減する

結論

ダイナミック・パターンのトレンド・リバース戦略は,トレンド・リバースを把握するために,線形回帰予測と移動平均パターンを統合する.単一指標戦略と比較して,より高い信頼性を持つ.パラメータ,確認,その他の最適化に関するさらなる改善により,信号品質と収益性が向上する.


/*backtest
start: 2023-12-05 00:00:00
end: 2023-12-12 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/
// © stocktechbot
//@version=5
strategy("Linear Cross", overlay=true, margin_long=100, margin_short=0)

//Linear Regression

vol = volume

// Function to calculate linear regression
linregs(y, x, len) =>
    ybar = math.sum(y, len)/len
    xbar = math.sum(x, len)/len
    b = math.sum((x - xbar)*(y - ybar),len)/math.sum((x - xbar)*(x - xbar),len)
    a = ybar - b*xbar
    [a, b]

// Historical stock price data
price = close

// Length of linear regression
len = input(defval = 21, title = 'Strategy Length')
linearlen=input(defval = 9, title = 'Linear Lookback')
[a, b] = linregs(price, vol, len)

// Calculate linear regression for stock price based on volume
//eps = request.earnings(syminfo.ticker, earnings.actual)
//MA For double confirmation

out = ta.sma(close, 200)
outf = ta.sma(close, 50)
outn = ta.sma(close, 90)
outt = ta.sma(close, 21)
outthree = ta.sma(close, 9)

// Predicted stock price based on volume
predicted_price = a + b*vol

// Check if predicted price is between open and close
is_between = open < predicted_price and predicted_price < close

//MACD
//[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)

// Plot predicted stock price
plot(predicted_price, color=color.rgb(65, 59, 150), linewidth=2, title="Predicted Price")
plot(ta.sma(predicted_price,linearlen), color=color.rgb(199, 43, 64), linewidth=2, title="MA Predicted Price")
//offset = input.int(title="Offset", defval=0, minval=-500, maxval=500)
plot(out, color=color.blue, title="MA200")
[macdLine, signalLine, histLine] = ta.macd(predicted_price, 12, 26, 9)

//BUY Signal

longCondition=false
mafentry =ta.sma(close, 50) > ta.sma(close, 90)
//matentry = ta.sma(close, 21) > ta.sma(close, 50)
matwohun = close > ta.sma(close, 200)
twohunraise = ta.rising(out, 2)
twentyrise = ta.rising(outt, 2)
macdrise = ta.rising(macdLine,2)
macdlong = ta.crossover(predicted_price, ta.wma(predicted_price,linearlen))  and (signalLine < macdLine)
if macdlong and macdrise
    longCondition := true

if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)
//Sell Signal
lastEntryPrice = strategy.opentrades.entry_price(strategy.opentrades - 1)
daysSinceEntry = len
daysSinceEntry := int((time - strategy.opentrades.entry_time(strategy.opentrades - 1)) / (24 * 60 * 60 * 1000))
percentageChange = (close - lastEntryPrice) / lastEntryPrice * 100
//trailChange = (ta.highest(close,daysSinceEntry) - close) / close * 100

//label.new(bar_index, high, color=color.black, textcolor=color.white,text=str.tostring(int(trailChange)))
shortCondition=false
mafexit =ta.sma(close, 50) < ta.sma(close, 90)
matexit = ta.sma(close, 21) < ta.sma(close, 50)
matwohund = close < ta.sma(close, 200)
twohunfall = ta.falling(out, 3)
twentyfall = ta.falling(outt, 2)
shortmafall = ta.falling(outthree, 1)
macdfall = ta.falling(macdLine,1)
macdsell = macdLine < signalLine
if macdfall and macdsell and (macdLine < signalLine) and ta.falling(low,2)
    shortCondition := true

if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)




もっと