TSIクロスオーバー戦略

TSI EMA ATR TEMA
作成日: 2024-06-07 16:36:24 最終変更日: 2024-06-07 16:36:24
コピー: 7 クリック数: 628
1
フォロー
1617
フォロワー

TSIクロスオーバー戦略

概要

この戦略は,TSI指標を主要な取引信号として使用します.TSI指標が信号ラインと交差し,TSI指標が下限または上限を下回ると,戦略はポジション開設信号を生成します.この戦略は,EMAやATRなどの指標を使用して戦略のパフォーマンスを最適化します.戦略は,特定の取引時間内にのみ動作し,過剰取引を制御するために最小取引頻度が設定されます.

戦略原則

  1. TSI指標値と信号線値の計算
  2. 現在の取引が許可された時間範囲内であり,現在のバーは,少なくとも指定された最小バー数から最後の取引の距離を隔てているかどうかを判断する.
  3. もしTSI指標が信号線を下から上へと通過し,この時点で信号線が指定された下限より低いなら,多信号が生成される.
  4. TSI指標が信号線を上から下へと通過し,この時点で信号線が指定された上限より高い場合は空白信号が生じる.
  5. 現在多頭ポジションを保有している場合,TSI指標が上から下へと信号線を横切ると,すべての多頭ポジションを平らにする。
  6. もし現在空頭ポジションを保有しているなら,TSI指標が下から上へと信号線を横切ると,空頭ポジションをすべて平らにする。

優位分析

  1. 策略の論理は明確で,TSI指標の交差を唯一の開口条件として使用し,簡単で分かりやすい.
  2. 取引時間や取引頻度を制限することで,過剰取引のリスクを効果的にコントロールできます.
  3. ストップ・ロストをタイムリーに止めて,逆のシグナルが出た時に平仓を断ち,単一取引のリスクの限界をコントロールする.
  4. EMA,ATRなど,複数の指標を用いて判断を補助し,戦略の安定性を強化した.

リスク分析

  1. 策略はTSI指標のパラメータの選択に敏感であり,異なるパラメータは大きな性能差をもたらし,慎重に選択する必要があります.
  2. ポジションの開設条件とポジション条件は比較的単純で,トレンド判断や波動率の制限がなく,震動の状況では損失が発生する可能性がある.
  3. ポジション管理と資金管理が不足し,撤収を制御することが困難で,連続的な損失が大きな撤収につながります.
  4. トレンドを観察しないことで,トレンドの動きを見逃す機会が多くあります.

最適化の方向

  1. TSI指標のパラメータを最適化し,より安定したパラメータの組み合わせを見つけます.遺伝的アルゴリズムなどの方法を使用して自動的に最適化することができます.
  2. MAやMACDのようなトレンド判断指標を足して,ポジション開設時に順調な方向を選択し,成功率を高めます.
  3. ATRのような波動性指標を足し,波動性の高い市場環境で取引回数を減らす.
  4. ポジション管理モデルを導入し,近年の市場パフォーマンスや口座の純額などの動向に基づいて各取引のポジションサイズを調整する.
  5. トレンド追跡のロジックを増やし,トレンドの動きの中でポジションを維持し,戦略の大きな動きを捕捉する能力を向上させることができます.

要約する

この戦略は,TSI指標を中心に,TSIと信号線の交差によって取引信号を生成する.同時に,取引時間と取引頻度を制限してリスクを制御する.戦略の優点は,論理がシンプルで明確であり,時効的な止損防止である.しかし,戦略の欠点は,トレンド判断とポジション管理の欠如であり,TSIパラメータに敏感であり,逆転の動きを捕捉してトレンドの動きを逃すのみである.将来,トレンドと波動率の判断,ポジション管理,パラメータ最適化などの側面で戦略を完善することができる.

ストラテジーソースコード
/*backtest
start: 2024-05-30 00:00:00
end: 2024-06-06 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © nikgavalas

//@version=5
strategy("TSI Entries", overlay=true, margin_long=100, margin_short=100)

//
// INPUTS
//

// Define the start and end hours for trading
string sessionInput = input("1000-1530", "Session")

// Day of the week.
string daysInput = input.string("23456", tooltip = "1 = Sunday, 7 = Saturday")

// Minimum number of bar's between entries
requiredBarsBetweenEntries = input.int(12, "Required Bars Between Entries")

// Show debug labels
bool showDebugLabels = input.bool(false, "Show Debug Labels")

//
// FUNCTIONS
//

//@function Define the triple exponential moving average function
tema(src, len) => tema = 3 * ta.ema(src, len) - 3 * ta.ema(ta.ema(src, len), len) + ta.ema(ta.ema(ta.ema(src, len), len), len)

//@function Atr with EMA
atr_ema(length) =>
    trueRange = na(high[1])? high-low : math.max(math.max(high - low, math.abs(high - close[1])), math.abs(low - close[1]))
    //true range can be also calculated with ta.tr(true)
    ta.ema(trueRange, length)

//@function Check if time is in range
timeinrange() => 
    sessionString = sessionInput + ":" + daysInput
    inSession = not na(time(timeframe.period, sessionString, "America/New_York"))

//@function Displays text passed to `txt` when called.
debugLabel(txt, color, y, style) =>
    if (showDebugLabels) 
        label.new(bar_index, y, text = txt, color = color, style = style, textcolor = color.black, size = size.small)


//
// INDICATOR CODE
//

long = input(title="TSI Long Length", defval=8)
short = input(title="TSI Short Length", defval=8)
signal = input(title="TSI Signal Length", defval=3)
lowerLine = input(title="TSI Lower Line", defval=-50)
upperLine = input(title="TSI Upper Line", defval=50)

price = close
double_smooth(src, long, short) =>
	fist_smooth = ta.ema(src, long)
	ta.ema(fist_smooth, short)

pc = ta.change(price)
double_smoothed_pc = double_smooth(pc, long, short)
double_smoothed_abs_pc = double_smooth(math.abs(pc), long, short)
tsiValue = 100 * (double_smoothed_pc / double_smoothed_abs_pc)
signalValue = ta.ema(tsiValue, signal)

//
// COMMON VARIABLES
//

var color trendColor = na
var int lastEntryBar = na

bool tradeAllowed = timeinrange() == true and (na(lastEntryBar) or bar_index - lastEntryBar > requiredBarsBetweenEntries)

// 
// CROSSOVER
//

bool crossOver = ta.crossover(tsiValue, signalValue)
bool crossUnder = ta.crossunder(tsiValue,signalValue)

if (tradeAllowed) 
	if (signalValue < lowerLine and crossOver == true)
		strategy.entry("Up", strategy.long)
		lastEntryBar := bar_index

	else if (signalValue > upperLine and crossUnder == true)

		strategy.entry("Down", strategy.short)
		lastEntryBar := bar_index

// 
// EXITS
// 

if (strategy.position_size > 0 and crossUnder == true)
	strategy.close("Up", qty_percent = 100)

else if (strategy.position_size < 0 and crossOver == true)
	strategy.close("Down", qty_percent = 100)