
この戦略の核心思想は,移動平均の斜率を利用して市場のトレンドを判断し,トレンド分析指数 (Trend Analysis Index,TAI) を取引信号として構築することである.価格がトレンドの中で動作するときは,移動平均の斜率は大きくなり,価格が明確なトレンドのない区間内で振動するときは,移動平均の斜率は小さくなり,トレンド分析指数の増加はトレンドに入ることを示し,減少はトレンドの終了を示している.
この戦略は,まず,価格の単純な移動平均 ((X日移動平均) を計算する.それから,この移動平均の過去Y日の最高値と最低値を計算し,この2つの極端値を使って,過去Y日の移動平均の波動範囲を計算する.最後に,このY日の波動範囲と価格を比較して,0-1の間の標準化指標に変換する.つまり,トレンド分析指数を構築する.指数は,ある値より高いとき,プラス,ある値より低いとき,空になる.
この戦略の利点は以下の通りです.
この戦略にはリスクもあります.
対応方法:
この戦略は以下の点で最適化できます.
この戦略は,全体として,移動平均の斜率によってトレンドを判断する中長線戦略であり,トレンドを効果的に捉えることができるが,ある程度の偽信号の危険性もある.他の指標の組み合わせと使用し,ストップ・ロスを加え,パラメータ最適化などの手段によって,戦略をより安定して信頼できるようにすることができる.本質的には,比較的単純なトレンド追跡戦略である.
//@version=2
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 21/12/2017
// In essence, it is simply the standard deviation of the last x bars of a
// y-bar moving average. Thus, the TAI is a simple trend indicator when prices
// trend with authority, the slope of the moving average increases, and when
// prices meander in a trendless range, the slope of the moving average decreases.
//
// You can change long to short in the Input Settings
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
strategy(title="Trend Analysis Index", shorttitle="TAI")
AvgLen = input(28, minval=1)
TAILen = input(5, minval=1)
TopBand = input(0.11, step=0.01)
LowBand = input(0.02, step=0.01)
reverse = input(false, title="Trade reverse")
hline(TopBand, color=red, linestyle=line)
hline(LowBand, color=green, linestyle=line)
xPrice = close
xSMA = sma(xPrice, AvgLen)
xHH = highest(xSMA, TAILen)
xLL = lowest(xSMA, TAILen)
nRes = (xHH - xLL) * 100 / xPrice
pos = iff(nRes > TopBand, 1,
iff(nRes < LowBand, -1, nz(pos[1], 0)))
possig = iff(reverse and pos == 1, -1,
iff(reverse and pos == -1, 1, pos))
if (possig == 1)
strategy.entry("Long", strategy.long)
if (possig == -1)
strategy.entry("Short", strategy.short)
barcolor(possig == -1 ? red: possig == 1 ? green : blue )
plot(nRes, color=blue, title="TAI")