*

Trend Intensity Index という指標(2) シグナルを付加

公開日: : 最終更新日:2015/02/24 日記

以前の記事『Trend Intensity Index という指標』で紹介したインディケーターもシグナルを表示するように改変してみました。

シグナルというのは指標の移動平均をとったもので、平滑されている分、遅れて動くので、指標とのクロスで売買のシグナルにすることができるのです。

 

サブウィンドウの上が TII_RLH.ex4(オリジナル)で、下が私の改良したシグナル付加版。

下のシグナル付加版で赤と水色の線のクロスしたところ(平行して重なったところではない)が買いまたは売りとなります。

シグナルがないと指標の反転を判断するのに数値で比べないといけないのですが、シグナルがあるとクロスの有無で判定でき、より簡単にプログラムできるという裏事情があるのです。

関連記事

プログラムソース

#property  copyright "Copyright ゥ 2006, Robert Hill "
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  Red
#property  indicator_color2  Aqua
#property  indicator_width1  2
#property  indicator_width2  1

//----
extern int Major_Period=60;
extern int Major_MaMode=1; //0=sma, 1=ema, 2=smma, 3=lwma, 4=lsma
extern int Major_PriceMode=0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
extern int Minor_Period=30;
extern color LevelColor=Silver;
extern int BuyLevel=20;
extern int MidLevel=50;
extern int SellLevel=80;

extern int SigPeriod = 8;

//---- buffers
double ma[];
double ma_dev[];
double tii[];

double tiis[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   IndicatorBuffers(4);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexDrawBegin(0,Major_Period);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//---- 3 indicator buffers mapping
   SetIndexBuffer(0,tii);
   SetIndexBuffer(1,tiis);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexDrawBegin(1,Major_Period);

   SetIndexBuffer(2,ma_dev);
   SetIndexBuffer(3,ma);

//---- name for DataWindow and indicator subwindow label
   IndicatorShortName(" TII  ,  Major_Period ( "+Major_Period+" )  ,  Minor_Period  ( "+Minor_Period+" ), ");
   SetLevelStyle(STYLE_DASH,1,LevelColor);
   SetLevelValue(0,BuyLevel);
   SetLevelValue(1,MidLevel);
   SetLevelValue(2,SellLevel);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| LSMA with PriceMode                                              |
//| PrMode  0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2,    |
//| 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4  |
//+------------------------------------------------------------------+
double LSMA(int Rperiod,int prMode,int shift)
  {
   int i;
   double sum,pr;
   int length;
   double lengthvar;
   double tmp;
   double wt;
//----
   length=Rperiod;
   sum=0;
   for(i=length; i>=1;i--)
     {
      lengthvar=length+1;
      lengthvar/=3;
      tmp=0;
      switch(prMode)
        {
         case 0: pr=Close[length-i+shift];break;
         case 1: pr=Open[length-i+shift];break;
         case 2: pr=High[length-i+shift];break;
         case 3: pr=Low[length-i+shift];break;
         case 4: pr=(High[length-i+shift] + Low[length-i+shift])/2;break;
         case 5: pr=(High[length-i+shift] + Low[length-i+shift] + Close[length-i+shift])/3;break;
         case 6: pr=(High[length-i+shift] + Low[length-i+shift] + Close[length-i+shift] + Close[length-i+shift])/4;break;
        }
      tmp =(i - lengthvar)*pr;
      sum+=tmp;
     }
   wt=sum*6/(length*(length+1));
//----
   return(wt);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int i,j,limit;
   double sdPos,sdNeg;

   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   if(counted_bars==0) limit-=1+MathMax(Major_Period,Minor_Period);

//----
   for(i=limit; i>=0; i--)
     {
      if(Major_MaMode==4)
        {
         ma[i]=LSMA(Major_Period,Major_PriceMode,i);
        }
      else
        {
         ma[i]=iMA(NULL,0,Major_Period,0,Major_MaMode,Major_PriceMode,i);
        }
      ma_dev[i]=Close[i]-ma[i];
     }
//========== COLOR CODING ===========================================               
   for(i=0; i<=limit; i++)
     {
      sdPos=0;
      sdNeg=0;
      for(j=i;j<i+Minor_Period;j++)
        {
         if(ma_dev[j]>=0) sdPos=sdPos+ma_dev[j];
         if(ma_dev[j]<0) sdNeg=sdNeg+ma_dev[j];
        }
      tii[i]=100*sdPos/(sdPos-sdNeg);
     } 
   for(i=0; i<=limit; i++)
     {
      tiis[i] = iMAOnArray(tii,0,SigPeriod,0,MODE_EMA,i); 
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+<>

###

関連記事

La Mer / Trois Nocturnes

La Mer / Nocturnes Debussy Davis Bso Pol

記事を読む

ファミマでチキンカレー

チキンカレー(唐揚げカレー) 本日の昼食はファミマで買ったチキンカレー。 え、そんなのない。

記事を読む

ナポレオンのすごい悪筆ぶり

ナポレオンの逸話はいくらもありますが、そのうちの一つ。 祖国にいる奥方のジョセフィーヌのところ

記事を読む

【ふるさと納税】さくらんぼ 佐藤錦(小さな恋人) 秀L以上 1.2kg(200g×6パック) / 山形市

【ふるさと納税】FS21-827 山形市産 さくらんぼ 佐藤

記事を読む

2025-7-23 日米関税交渉成立

日米関税交渉が成立したとのことで、本日は日経平均が一時 1500円ほど上昇し、今年の最高値を更新しま

記事を読む

7プレミアム 肉焼売

本日は久々にセブンイレブンに行きました。 最近なにかと悪評の多いセブンイレブンなので、

記事を読む

明治 果汁グミ 5種×各2個(計10個)セット( ぶどう 温州みかん マスカット ゴールデンパイン いちご )

【 送料無料 あす楽 】 明治 果汁 グミ 5種 × 各2個

記事を読む

テラークの飲み会で大阪に

* 本日はテラークのメンバー+α で大阪で飲み会。 いつもは夕方は高槻から京都方面の電車に乗

記事を読む

【万年筆】 シュナイダー Schneider Ray 細字

シュナイダーはドイツの文具メーカー。 欧州規格の万年筆インクカートリッジも作っていてア

記事を読む

【ふるさと納税】 ハンバーグ 約1.5kg(約150g×10個) 山形県河北町

牛肉仲卸の国産牛肉専門店べごやさんの商品です。 国産牛100%の粗挽きハンバーグです。

記事を読む

Message

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

2026-1-13 日経平均爆上げして最高水準に

1/13 本日の日経平均は前日比プラス 1609円で、史上最高の 53

煮込みビーフカレー 森のきのこカレー

以前、楽天市場で買った「森のきのこカレーお試しセット」はなかなか良かっ

0.01%ルール

『Just Keep Buying』の著者 ニック・マジューリ

楽天SCHD(正式名称:楽天・高配当株式・米国ファンド(四半期決算型))が順調

通称「楽天SCHD」と呼ばれている 楽天・高配当株式・米国ファンド(四

【FX】2026年1月第1週目の収支報告

2026年1月第1週目の FX収支報告です。 安心してください、シリ

→もっと見る

  • 2026年1月
     1234
    567891011
    12131415161718
    19202122232425
    262728293031  
  • アクセスカウンター
PAGE TOP ↑