//+------------------------------------------------------------------+
//|                                               maloma`s`enter.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright � 2006, maloma"

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color4 Blue
#property indicator_color5 Red

//------- ���������� ���������� --------------------------------------

//------- ������� ��������� ���������� -------------------------------
extern int        Porog=20;
extern int        FastEMA=12;
extern int        SlowEMA=26;
extern int        SignalSMA=9;


//------- ��������� ���������� -------------------------------
double     MacdBuffer[];
double     SignalBuffer[];
double     HistoBuffer[];

//------- ������ ���������� ------------------------------------------
double bufbuy[], bufsell[];

void init() {
  SetIndexStyle(0,DRAW_NONE);
  SetIndexStyle(1,DRAW_NONE);
  SetIndexStyle(2,DRAW_NONE);
  SetIndexStyle(3,DRAW_ARROW);
  SetIndexStyle(4,DRAW_ARROW);  
  IndicatorDigits(Digits+1);

  SetIndexBuffer(0,MacdBuffer);
  SetIndexBuffer(1,SignalBuffer);
  SetIndexBuffer(2,HistoBuffer);
  SetIndexBuffer(3,bufbuy);
  SetIndexBuffer(4,bufsell);
    
  IndicatorShortName("Maloma`s`enter");
  SetIndexLabel(0,"");
  SetIndexLabel(1,"");
  SetIndexLabel(2,"");
  SetIndexLabel(3,"Buy");   
  SetIndexLabel(4,"Sell");

  SetIndexArrow (3,164);
  SetIndexArrow (4,164);

  SetIndexEmptyValue(0,0);
  SetIndexEmptyValue(1,0);
  SetIndexEmptyValue(2,0);
  SetIndexEmptyValue(3,0);
  SetIndexEmptyValue(4,0);
}

void deinit() {
  Comment("");
}

void start() {
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   for(int i=0; i<limit; i++)
      MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
   for(i=0; i<limit; i++)
      SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
   for(i=0; i<limit; i++)
      HistoBuffer[i]=(MacdBuffer[i]-SignalBuffer[i])*10/Point;
   for(i=0; i<limit; i++)
     {
      if (HistoBuffer[i+1]<Porog && HistoBuffer[i]>=Porog && bufbuy[i]==0) bufbuy[i]=High[i];
      if (HistoBuffer[i+1]>-Porog && HistoBuffer[i]<=-Porog && bufsell[i]==0) bufsell[i]=Low[i];
     }
}
//+------------------------------------------------------------------+