ダイナミックなイデオロギートレンド反転戦略


作成日: 2023-12-13 16:52:34 最終変更日: 2023-12-13 16:52:34
コピー: 0 クリック数: 635
1
フォロー
1621
フォロワー

ダイナミックなイデオロギートレンド反転戦略

概要

動的イデオロギー トレンド反転戦略は,価格を予測する線形的な回帰を利用し,移動平均を形成するイデオロギーと組み合わせて取引信号を生成する.予測価格が移動平均を下から上へと渡るときに買取信号を生成する.予測価格が移動平均を上から下へと渡るときに売り信号を生成し,トレンド反転の捕捉を実現する.

戦略原則

  1. 取引量に基づいて株価を計算した線形回帰で,価格の予測値が得られる
  2. 異なる条件下での移動平均の計算
  3. 予想価格が移動平均を上から下へと横切ると,買入シグナルが作られます.
  4. 予想される価格が上から下へと移動平均を横切ると,売り込みシグナルが生成されます.
  5. MACDの指標と合わせて,トレンドの逆転のタイミングを判断する

上記の信号は,複数の confirmation を組み合わせて,偽突破を回避し,信号の正確性を向上させる.

優位分析

  • 線形回帰を用いて価格動向を予測し,信号の精度を向上させる
  • 移動平均と組み合わせたイデオロギーで,トレンドの逆転を捉える
  • 取引量に基づく線形回帰はより経済的に意味がある
  • 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)