
//+---------------------------------------+
//|                        N3HeikinMA.mq4 |


#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 LightPink
#property indicator_color2 LightBlue
//矢印
#property indicator_color3 LightBlue //上矢印買い233
#property indicator_color4 LightPink //下矢印売り234

//線の幅、太さ
#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 2
#property indicator_width4 2


//---- parameters
extern int MaMetod  = 1;  //MODE_EMA 1
extern int MaPeriod = 8;



//N本前の足のopenからcloseまで
extern int N_Period = 3 ;
extern int Alert_onoff = 1 ;
extern int ARROW_onoff = 1 ;
extern int SignalSlide = 10; 


//---- buffers
double h_open[];
double h_close[];
//矢印
double BufBuy[];    //上矢印買い233
double BufSell[];   //下矢印売り234

//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM, 0, 3, LightPink);
   SetIndexBuffer(0, h_open);
   SetIndexStyle(1,DRAW_HISTOGRAM, 0, 3, LightBlue);
   SetIndexBuffer(1, h_close);
   //指標バッファの割り当て
   SetIndexBuffer(2, BufBuy);    //上矢印買い233
   SetIndexBuffer(3, BufSell);   //下矢印売り234

   //指標スタイルの設定（上矢印 Buyシグナル）
   SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID, 2, LightBlue);
   SetIndexArrow(2,233);

   //指標スタイルの設定（下矢印 Sellシグナル）
   SetIndexStyle(3, DRAW_ARROW, STYLE_SOLID, 2, LightPink);
   SetIndexArrow(3,234);


//----
   SetIndexDrawBegin(0,50);
   SetIndexDrawBegin(1,50);
   SetIndexDrawBegin(2,50);
   SetIndexDrawBegin(3,50);


//---- initialization done
   return(0);
  }
int deinit()
  {

//----------------------------
   return(0);
  }

//+------------------------------------------------------------------+
int start()
  {
   double maOpen, maClose, maLow, maHigh;
   double haOpen, haHigh, haLow, haClose;
   if(Bars<=10) return(0);
   ExtCountedBars=IndicatorCounted();
//---- check for possible errors
   if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
   if (ExtCountedBars>0) ExtCountedBars--;
   int pos=Bars-ExtCountedBars-1;
   while(pos>=0)
     {
//+++++++++++++++++++++++++++++++++++++
      maOpen=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_OPEN,pos);
      maClose=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_CLOSE,pos);
      maLow=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_LOW,pos);
      maHigh=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_HIGH,pos);
//+++++++++++++++++++++++++++++++++++++


      haOpen=(h_open[pos+N_Period]+h_close[pos+1])/2;
      haClose=(maHigh+maLow+maClose+maOpen)/4;

      h_open[pos]=haOpen;
      h_close[pos]=haClose;

//+------------------------------------------------------------------+
      //Buyシグナル
      BufBuy[pos] = EMPTY_VALUE;
      if( (h_open[pos+2] > h_close[pos+2]) &&
          (h_open[pos+1] < h_close[pos+1]) )
					{
          if(ARROW_onoff == 1)
      		BufBuy[pos] = h_open[pos] - (SignalSlide * Point) ;
						//買いシグナルアラート
            if((Alert_onoff == 1 ) && (pos <= 1) && (Volume[pos] == 1 ))
						{
						Alert(Symbol(),"N3HeikinMA_", Symbol(), " at ", Ask);
						}
					}


//+-------------------------------------
      //Sellシグナル
      BufSell[pos] = EMPTY_VALUE;
      if( (h_open[pos+2] < h_close[pos+2]) &&
          (h_open[pos+1] > h_close[pos+1]) )
					{
          if(ARROW_onoff == 1)
      		BufSell[pos] = h_close[pos] + (SignalSlide * Point) ;
						//売りシグナルアラート
            if((Alert_onoff == 1 ) && (pos <= 1) && (Volume[pos] == 1 ))
						{
						Alert(Symbol(),"N3HeikinMA_", Symbol(), " at ", Bid);
						}
					}

//+------------------------------------------------------------------+

 	   pos--;
     } //while(pos>=0)END
//----
   return(0);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+



