//+------------------------------------------------------------------+
//|                                                    Ashi_Feti.mq4 |
//|                                                         Makimoto |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Makimoto"
#property link      ""


//+---------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Blue
#property indicator_color5 Aqua
#property indicator_color6 Pink

#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 3
#property indicator_width4 3
#property indicator_width5 2
#property indicator_width6 2

//+---------------------------------------------------------
double Bufhige1[]; //ヒゲ
double Bufhige2[]; //ヒゲ
double Bufopen3[]; //始値
double Bufclose4[]; //終値

double Bufbuyarrow[] ;   //買いサイン上矢印233
double Bufsellarrow[] ;  //売りサイン下矢印234

//+---------------------------------------------------------
extern int Alert_onoff = 0 ;
//+(SignalSlide * Point);
extern int SignalSlide = 30; 

extern int ARROW_onoff = 1 ;


//jikan設定
extern int jikan = 4 ;
//15m=15, 30m=30, 1h=1, 4h=4

//+---------------------------------------------------------
int init()
  {
//+---------------------------------------------------------
   SetIndexStyle(0,DRAW_HISTOGRAM, 0, 1, Red);
   SetIndexBuffer(0, Bufhige1);
   SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, Blue);
   SetIndexBuffer(1, Bufhige2);
   SetIndexStyle(2,DRAW_HISTOGRAM, 0, 3, Red);
   SetIndexBuffer(2, Bufopen3);
   SetIndexStyle(3,DRAW_HISTOGRAM, 0, 3, Blue);
   SetIndexBuffer(3, Bufclose4);

   SetIndexBuffer(4,Bufbuyarrow);
   SetIndexBuffer(5,Bufsellarrow);

   //指標スタイルの設定（上矢印 Buyシグナル）
   SetIndexStyle(4, DRAW_ARROW, STYLE_SOLID, 2, Aqua);
   SetIndexArrow(4,233);

   //指標スタイルの設定（下矢印 Sellシグナル）
   SetIndexStyle(5, DRAW_ARROW, STYLE_SOLID, 2, Pink);
   SetIndexArrow(5,234);
//+---------------------------------------------------------
   SetIndexDrawBegin(0,500);
   SetIndexDrawBegin(1,500);
   SetIndexDrawBegin(2,500);
   SetIndexDrawBegin(3,500);
   SetIndexDrawBegin(4,500);
   SetIndexDrawBegin(5,500);
//+---------------------------------------------------------

   return(0);
  }
//+------------------------------------------------------------------+
int deinit()
  {

   return(0);

  }

//+------------------------------------------------------------------+

int start()
  {
   double hei_Op ;
   double hei_Hi ;
   double hei_Lo ;
   double hei_Cl ;

   //指標の計算範囲
	int counted_bar = IndicatorCounted(); 
	if(Bars<=500) return(0);
	int limit = Bars-counted_bar ;
//+------------------------------------------------------------------+

   for(int i=limit-1; i>=0; i--)
   {

		hei_Op = ( Bufopen3[i+1] + Bufclose4[i+1] )/2 ;
		hei_Cl = ( Open[i] + High[i] + Low[i] + Close[i] )/4 ;
		hei_Hi = MathMax( High[i], MathMax(hei_Op, hei_Cl) ) ;
		hei_Lo = MathMin( Low[i], MathMin(hei_Op, hei_Cl) ) ;
//+--------------------------
			if (hei_Op < hei_Cl) 
			{
			Bufhige1[i] = hei_Lo ;
			Bufhige2[i] = hei_Hi ;
			} 
//+-------------else---------
      else
				{
				Bufhige1[i] = hei_Hi ;
				Bufhige2[i] = hei_Lo ;
				} 
//+--------------------------
		Bufopen3[i] = hei_Op ;
		Bufclose4[i] = hei_Cl ;








//+------------------------------------------------------------------+
//平均足のOpen
double M15_open = iCustom(NULL,PERIOD_M15,"Heiken Ashi",2,i ) ;
double M30_open = iCustom(NULL,PERIOD_M30,"Heiken Ashi",2,i ) ;
double H1_open = iCustom(NULL,PERIOD_H1,"Heiken Ashi",2,i ) ;
double H4_open = iCustom(NULL,PERIOD_H4,"Heiken Ashi",2,i ) ;

//+------------------------------------------------------------------+
//平均足のClose
double M15_close = iCustom(NULL,PERIOD_M15,"Heiken Ashi",3,i ) ;
double M30_close = iCustom(NULL,PERIOD_M30,"Heiken Ashi",3,i ) ;
double H1_close = iCustom(NULL,PERIOD_H1,"Heiken Ashi",3,i ) ;
double H4_close = iCustom(NULL,PERIOD_H4,"Heiken Ashi",3,i ) ;

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
	//Buyシグナル
	Bufbuyarrow[i] = EMPTY_VALUE;
//+------------------------------------------------------------------+
if( jikan == 4 )
{
		if( (Bufopen3[i+2] > Bufclose4[i+2]) && 
        (Bufopen3[i+1] < Bufclose4[i+1]) && 
        (M15_open < M15_close) && 
        (M30_open < M30_close) && 
        (H1_open < H1_close) && 
        (H4_open < H4_close) )
        
        		{  //if01
		Bufbuyarrow[i] = Bufopen3[i] - (SignalSlide * Point) ;


		if( (Alert_onoff == 1) && (i <= 1) && ( Volume[i] < 2 ) )
			{
			Alert(Symbol()," bikyaku_BUY",  " at ", Ask);
			}
		}  //if01 END
}
//+--------------------------------
if( jikan == 1 )
{
		if( (Bufopen3[i+2] > Bufclose4[i+2]) && 
        (Bufopen3[i+1] < Bufclose4[i+1]) && 
        (M15_open < M15_close) && 
        (M30_open < M30_close) && 
        (H1_open < H1_close) )
        
        		{  //if01
		Bufbuyarrow[i] = Bufopen3[i] - (SignalSlide * Point) ;


		if( (Alert_onoff == 1) && (i <= 1) && ( Volume[i] < 2 ) )
			{
			Alert(Symbol()," bikyaku_BUY",  " at ", Ask);
			}
		}  //if01 END
}

//+--------------------------------
if( jikan == 30 )
{
		if( (Bufopen3[i+2] > Bufclose4[i+2]) && 
        (Bufopen3[i+1] < Bufclose4[i+1]) && 
        (M15_open < M15_close) && 
        (M30_open < M30_close) )
        
        		{  //if01
		Bufbuyarrow[i] = Bufopen3[i] - (SignalSlide * Point) ;


		if( (Alert_onoff == 1) && (i <= 1) && ( Volume[i] < 2 ) )
			{
			Alert(Symbol()," bikyaku_BUY",  " at ", Ask);
			}
		}  //if01 END
}

//+--------------------------------
if( jikan == 15 )
{
		if( (Bufopen3[i+2] > Bufclose4[i+2]) && 
        (Bufopen3[i+1] < Bufclose4[i+1]) && 
        (M15_open < M15_close) )
        
        		{  //if01
		Bufbuyarrow[i] = Bufopen3[i] - (SignalSlide * Point) ;


		if( (Alert_onoff == 1) && (i <= 1) && ( Volume[i] < 2 ) )
			{
			Alert(Symbol()," bikyaku_BUY",  " at ", Ask);
			}
		}  //if01 END
}

//+--------------------------------
/*
		{  //if01
		Bufbuyarrow[i] = Bufopen3[i] - (SignalSlide * Point) ;


		if( (Alert_onoff == 1) && (i <= 1) && ( Volume[i] < 2 ) )
			{
			Alert(Symbol()," bikyaku_BUY",  " at ", Ask);
			}
		}  //if01 END

*/
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
	//Sellシグナル
	Bufsellarrow[i] = EMPTY_VALUE;
//+------------------------------------------------------------------+
if( jikan == 4 )
{
		if( (Bufopen3[i+2] < Bufclose4[i+2]) && 
        (Bufopen3[i+1] > Bufclose4[i+1]) &&
        (M15_open > M15_close) && 
        (M30_open > M30_close) && 
        (H1_open > H1_close) && 
        (H4_open > H4_close) )
        
        		{  //if02
		Bufsellarrow[i] = Bufopen3[i] + (SignalSlide * Point) ;


		if( (Alert_onoff == 1) && (i <= 1) && ( Volume[i] < 2 ) )
			{
			Alert(Symbol()," bikyaku_SELL", " at ", Bid);
			}
		}  //if02 END
}
//+--------------------------------
if( jikan == 1 )
{
		if( (Bufopen3[i+2] < Bufclose4[i+2]) && 
        (Bufopen3[i+1] > Bufclose4[i+1]) &&
        (M15_open > M15_close) && 
        (M30_open > M30_close) && 
        (H1_open > H1_close) )
        
        		{  //if02
		Bufsellarrow[i] = Bufopen3[i] + (SignalSlide * Point) ;


		if( (Alert_onoff == 1) && (i <= 1) && ( Volume[i] < 2 ) )
			{
			Alert(Symbol()," bikyaku_SELL", " at ", Bid);
			}
		}  //if02 END
}
//+--------------------------------
if( jikan == 30 )
{
		if( (Bufopen3[i+2] < Bufclose4[i+2]) && 
        (Bufopen3[i+1] > Bufclose4[i+1]) &&
        (M15_open > M15_close) && 
        (M30_open > M30_close) )
        
        		{  //if02
		Bufsellarrow[i] = Bufopen3[i] + (SignalSlide * Point) ;


		if( (Alert_onoff == 1) && (i <= 1) && ( Volume[i] < 2 ) )
			{
			Alert(Symbol()," bikyaku_SELL", " at ", Bid);
			}
		}  //if02 END
}
//+--------------------------------
if( jikan == 15 )
{
		if( (Bufopen3[i+2] < Bufclose4[i+2]) && 
        (Bufopen3[i+1] > Bufclose4[i+1]) &&
        (M15_open > M15_close) )
        
        		{  //if02
		Bufsellarrow[i] = Bufopen3[i] + (SignalSlide * Point) ;


		if( (Alert_onoff == 1) && (i <= 1) && ( Volume[i] < 2 ) )
			{
			Alert(Symbol()," bikyaku_SELL", " at ", Bid);
			}
		}  //if02 END
}
//+--------------------------------
/*

		{  //if02
		Bufsellarrow[i] = Bufopen3[i] + (SignalSlide * Point) ;


		if( (Alert_onoff == 1) && (i <= 1) && ( Volume[i] < 2 ) )
			{
			Alert(Symbol()," bikyaku_SELL", " at ", Bid);
			}
		}  //if02 END
*/
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+

//+-------------------------------------------+
 }  //   for(i=limit-1; i>=0; i--)END
//+-------------------------------------------+
//+-------------------------------------------+
   return(0);
}
//+------------------------------------------------------------------+
















