//+------------------------------------------------------------------+ //|TDMovingAverage2 //|Copyright ゥ 2006, senseki //| //+------------------------------------------------------------------+ #property copyright "Copyright ゥ 2006, Senseki" #property link "none" #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Blue #property indicator_color2 Red //パラメーター設定 extern double MA_Period=3; extern double MA_Shift=0; extern int Backcheck=2; extern int MAType=0; extern int Price=0;//0=PRICE_CLOSE; 1=PRICE_OPEN; 2=PRICE_HIGH; 3=PRICE_LOW; 4=PRICE_MEDIAN; 5=PRICE_TYPICAL; 6=PRICE_WEIGHTED extern int MA_Check_Price=0;//0=PRICE_CLOSE; 1=PRICE_OPEN; 2=PRICE_HIGH; 3=PRICE_LOW; 4=PRICE_MEDIAN; 5=PRICE_TYPICAL; 6=PRICE_WEIGHTED extern int MA_back_Check_Price=0;//0=PRICE_CLOSE; 1=PRICE_OPEN; 2=PRICE_HIGH; 3=PRICE_LOW; 4=PRICE_MEDIAN; 5=PRICE_TYPICAL; 6=PRICE_WEIGHTED //---- インディケータバッファ double Buf0[]; double Buf1[]; //---- インジケータ一時作業 double Buf0tmp; double Buf1tmp; int MAMode; string strMAType; //+------------------------------------------------------------------+ //| インディケータ初期化関数 | //+------------------------------------------------------------------+ int init() { //---- バッファのインディケータへの割り当て SetIndexBuffer(0, Buf0); SetIndexBuffer(1, Buf1); //---- インディケータの種類の設定 SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2); SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2); switch (MAType) { case 0: strMAType="SMA"; MAMode=MODE_SMA; break; case 1: strMAType="EMA"; MAMode=MODE_EMA; break; case 2: strMAType="SMMA"; MAMode=MODE_SMMA; break; case 3: strMAType="LWMA"; MAMode=MODE_LWMA; break; } return(0); } //+------------------------------------------------------------------+ //| インディケータ処理関数 | //+------------------------------------------------------------------+ int start() { int limit; int counted_bars = IndicatorCounted(); //---- check for possible errors if (counted_bars<0) return(-1); //---- last counted bar will be recounted if (counted_bars>0) counted_bars--; limit = Bars - counted_bars; for(int i=limit; i>=0; i--) { // 移動平均一時作業 Buf0tmp = iMA(NULL, 0, MA_Period, MA_Shift, MAType, MA_Check_Price, i); Buf1tmp = iMA(NULL, 0, MA_Period, MA_Shift, MAType, MA_back_Check_Price, i+Backcheck); // 移動平均比較着色 if (Buf0tmp > Buf1tmp) { Buf0[i] = iMA(NULL, 0, MA_Period, MA_Shift, MAType, Price, i); } if (Buf0tmp < Buf1tmp) { Buf1[i] = iMA(NULL, 0, MA_Period, MA_Shift, MAType, Price, i); } } return(0); } //+------------------------------------------------------------------+