Schaff Trend Cycle(シャフ・トレンド・サイクル STC)(計算式、チャート、エクセルVBAコード)テクニカル指標


2008年12月24日



 

Schaff Trend Cycle(STC)について。計算式、チャート、エクセルVBAコード

 

STCは簡単に言うとMACDを2回ストキャス化した指標なのですが、計算式やその指標そのものの情報がネット上等にも少なく、計算式の確立や自動売買システムUGへの実装に苦労したことを覚えています。

Schaff Trend cycle は「シャフ・トレンド・サイクル」と読むそうです。

 

 

 

英文の計算方法を掲載したPDFファイルを見ながら、試行錯誤の上、見た目はSTCのラインとなっていますが、実際のところ計算式などこれであっているのかどうかは確認するすべがないのが現状です。

 

ですので、ここではUGに実装している内容に沿って掲載させていただきますので、上記の、「正確ではないかもしれない」ということをご考慮ください。

 

 

 

SchaffTrendCycleの計算式(Nは足数)

計算方法ですが、まずMACDを計算します。

MACDは、指数平滑移動平均線(EMA)から計算される指標で下記計算式にて求められます。

 

EMA(x1) = 直前EMA(x1) + ( ( 終値 – 直前EMA(x1) ) * 2 / ( 1 + x1 )
※最初のデータのみx1の単純移動平均

 

EMA(x2) = 直前EMA(x2) + ( ( 終値 – 直前EMA(x2) ) * 2 / ( 1 + x2 )
※最初のデータのみx2の単純移動平均

 

MACD = EMA(x1) – EMA(x2)

 

これでx1とx2のMACDが計算されます。

 

次に、MACDのストキャスティクス化ですが、ストキャスティクスは一定期間内の最大値、最小値を計算されます。

 

STCで使用するのは、MACDをストキャスティクス化した場合の%Kのデータまでですので、ここでは%Kの計算式のみを掲載しています。

 

%K(m) = ( MACD – Min1(x3) ) / ( Max1(x3) – Min1(x3) ) * 100
Min1(x3) = x3本のMACDの最小値
Max1(x3) = x3本のMACDの最大値

 

MACDの%K化の次に、PFという値を計算します

PF1 = 直前PF1 + ( 0.5 * ( %K(m) – 直前PF1 ) )
※最初のデータのみ PF1 = %K(m)

 

次に、計算したPFをもう一度ストキャスティクスの%K化し、上記PFと同じ計算を行うことでSTCが計算されます。

 

%K(PF1) = ( PF1 – Min2(x3) ) / ( Max2(x3) – Min2(x3) ) * 100
Min2(x3) = x3本のPF1の最小値
Max2(x3) = x3本のPF1の最大値

PF2 = 直前PF2 + ( 0.5 * ( %K(PF1) – 直前PF2 ) )
※最初のデータのみ PF = %K(PF1)

 

計算されたF2の値がSTCの値となります。

 

 

SchaffTrendCycleのチャート

STC(23,50,10)

 

 

SchaffTrendCycleのエクセルVBAコード

‘※ エクセルの1列目(A列)に行番号、2列目(B列)に日時、
‘※ 3列目(C列)~6列目(F列)に始値・高値・安値・終値
‘********************************
‘ ema_1 :指数平滑1の採用本数
‘ ema_2 :指数平滑2の採用本数
‘ stc1 :STCの採用本数
‘ num:現在の行
‘ r_now:現在値
‘ cell_ema1:指数平滑線1計算値書込み列
‘ cell_ema2:指数平滑線2計算値書込み列
‘ cell_macd:MACD計算値書込み列
‘ cell_v1:MACDのストキャス化1回目計算用数値書込み列
‘ cell_v2:MACDのストキャス化1回目計算値入力列
‘ cell_v3:MACDのストキャス化2回目計算用数値書込み列
‘ cell_STC:MACDのストキャス化2回目計算値(=STC)入力列
‘********************************
‘—–ema1
If num + 2 = ema_1 Then
Cells(num, cell_ema1) = Application.WorksheetFunction. _
Average(.Range(Cells(num – (ema_1 – 1), 5), Cells(num, 5)))
End If
If num + 2 > ema_1 Then
Cells(num, cell_ema1) = Cells(num – 1, cell_ema1) + _
((r_now – Cells(num – 1, cell_ema1)) * 2 / (ema_1 + 1))
End If
‘—–ema2
If num + 2 = ema_2 Then
Cells(num, cell_ema2) = Application.WorksheetFunction. _
Average(.Range(Cells(num – (ema_2 – 1), 5), Cells(num, 5)))
End If
If num + 2 > ema_2 Then
Cells(num, cell_ema2) = Cells(num – 1, cell_ema2) + _
((r_now – Cells(num – 1, cell_ema2)) * 2 / (ema_2 + 1))
End If
‘—–macd
If Cells(num – 1, cell_ema1) <> “” _
And Cells(num – 1, cell_ema2) <> “” Then
Cells(num, cell_macd) = Cells(num, cell_ema1) – Cells(num, cell_ema2)
End If

‘—-Value1,2
If num – 2 >= ema_2 + stc1 – 1 _
And Cells(num – (stc1 – 1), cell_macd) <> “” Then
v1_1 = Application.Min _
(.Range(Cells(num – (stc1 – 1), cell_macd), Cells(num, cell_macd)))
v1_2 = Application.Max _
(.Range(Cells(num – (stc1 – 1), cell_macd), Cells(num, cell_macd))) – v1_1
‘—-flac1,PF
If v1_2 > 0 Then Cells(num, cell_v1) = _
((Cells(num, cell_macd) – v1_1) / v1_2) * 100 _
Else Cells(num, cell_v1) = Cells(num – 1, cell_v1)
If Cells(num – 1, cell_v1) = “” And Cells(num, cell_v1) <> “” Then
Cells(num, cell_v2) = Cells(num, cell_v1)
Else
If Cells(num, cell_v1) <> “” Then Cells(num, cell_v2) = _
Cells(num – 1, cell_v2) + (0.5 * (Cells(num, cell_v1) – _
Cells(num – 1, cell_v2)))
End If
If Cells(num, cell_v1) = “” Then
xxxxx = 1
End If
End If
‘—-Value3,4
If num – 2 >= ema_2 + stc1 + stc1 – 1 _
And Cells(num – (stc1 – 1), cell_v2) <> “” Then
v1_3 = Application.Min _
(.Range(Cells(num – (stc1 – 1), cell_v2), Cells(num, cell_v2)))
v1_4 = Application.Max _
(.Range(Cells(num – (stc1 – 1), cell_v2), Cells(num, cell_v2))) – v1_3
‘—-flac2,PFf
If v1_4 > 0 Then Cells(num, cell_v3) = _
((Cells(num, cell_v2) – v1_3) / v1_4) * 100 _
Else Cells(num, cell_v3) = Cells(num – 1, cell_v3)
If Cells(num – 1, cell_v3) = “” And Cells(num, cell_v3) <> “” Then
Cells(num, cell_STC) = Cells(num, cell_v3)
Else
If Cells(num, cell_v3) <> “” Then _
Cells(num, cell_STC) = Cells(num – 1, cell_STC) + _
(0.5 * (Cells(num, cell_v3) – Cells(num – 1, cell_STC)))
End If
End If

 

 

テクニカル指標一覧

罫線談義一覧

(外部リンク)テクニカル指標(Wikipedia)

 

 

Schaff Trend Cycle(シャフ・トレンド・サイクル STC)(計算式、チャート、エクセルVBAコード)テクニカル指標」への3件のフィードバック

  1. ピンバック: 色んな指標をストキャス化してみる | IBI-Square

  2. ピンバック: コマ足(平均足)(計算式、チャート、エクセルVBAコード)テクニカル指標 | IBI-Square

  3. ピンバック: Schaff Trend Cycleを使うトレード手法

コメントは停止中です。