Navigation:Home > Content >

MA-DKX_Arrows_Alerts_TT.mq4

Time: 2015-06-06 | Download file:MA-DKX_Arrows_Alerts_TT.mq4

//+------------------------------------------------------------------+
//|                                            DKX_Arrows_Alerts.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property  copyright "Copyright  2004,wyd95968"
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 2

#property  indicator_color1  Gainsboro
#property  indicator_color2  DarkOrange
#property indicator_width1 2
#property indicator_width2 2

//#define PREFIX "DKX_Arrows_Alerts"

//+++======================================================================+++
//+++======================================================================+++
//---- indicator parameters

extern int     SignalPeriod  =  12;
extern bool          Alerts  =  true,
                 AlertSound  =  true;
extern string     SoundFile  =  "stops.wav";
extern bool           Arrow  =  true;
extern int        ArrowSize  =  1,
                 SIGNAL_BAR  =  1;
extern color       ArrowBuy  =  DodgerBlue,   //LightCyan,
                  ArrowSell  =  Magenta;
extern string  ArrowComment  =  "DKX TT";

//+++======================================================================+++
//+++======================================================================+++
//---- indicator buffers
double MA[], MB[], MD[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
  {
//---- 1 additional buffer used for counting.
   IndicatorBuffers(3);
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
//   IndicatorDigits(Digits+1);
//---- indicator buffers mapping
   SetIndexBuffer(0,MB);
   SetIndexBuffer(1,MD);
   SetIndexBuffer(2,MA);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("DKX("+SignalPeriod+")");
   SetIndexLabel(0,"DKX.B");
   SetIndexLabel(1,"DKX.D");
//----
   SetIndexDrawBegin(0,SignalPeriod);
//---- initialization done
   return(0);
  }
//+++======================================================================+++
int deinit() 
{
   ARROWS_DELETE();
   return(0);
}

void ARROWS_DELETE() 
{
   string name;   string pref=ArrowComment + " ["+IntegerToString(SignalPeriod)+"] ";
   for (int s=ObjectsTotal()-1; s>=0; s--) 
     {
      name=ObjectName(s);
      if (StringSubstr(name,0,StringLen(pref))==pref) ObjectDelete(name);
     }
}
//+++======================================================================+++

int start()
  {
   double sum1;
   
   int i, j;
   int limit;
   
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars<0) return(0);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//+++======================================================================+++

//---- Зу єН
   for(i=0; i0) counted_bars--;
   limit=Bars-counted_bars;
   
   for( j=limit; j>=0; j--)
   {
     if(Arrow)
      {
      int s=1;
      if(MB[j+SIGNAL_BAR+1] > MD[j+SIGNAL_BAR+1]  && MB[j+SIGNAL_BAR] < MD[j+SIGNAL_BAR])  manageArr(j+1,ArrowSell,234,true );
      if(MB[j+SIGNAL_BAR+1] < MD[j+SIGNAL_BAR+1]  && MB[j+SIGNAL_BAR] > MD[j+SIGNAL_BAR])   manageArr(j+1,ArrowBuy,233,false);
    }}
//+++======================================================================+++
    
    static int PrevSignal = 0, PrevTime = 0;
	  if(SIGNAL_BAR > 0 && Time[0] <= PrevTime) 
	  return(0);

	  PrevTime = Time[0];

 if(Alerts)
  {
   if(PrevSignal <= 0)
	 {
	 if(MB[SIGNAL_BAR+1] > MD[SIGNAL_BAR+1]  && MB[SIGNAL_BAR] < MD[SIGNAL_BAR])
	   {     
	   Alert(WindowExpertName() +"  (", Symbol(), ", ", Period(), ")  -  SELL!!!");
	   }
   if(PrevSignal <= 0)
	 {
	 if(MB[SIGNAL_BAR+1] < MD[SIGNAL_BAR+1]  && MB[SIGNAL_BAR] > MD[SIGNAL_BAR])
	   {
		Alert(WindowExpertName() +"  (", Symbol(), ", ", Period(), ")  -  BUY!!!");
   }}}}
//+++======================================================================+++

   if(AlertSound)
  {
   if(PrevSignal <= 0)
	 {
	 if(MB[SIGNAL_BAR+1] > MD[SIGNAL_BAR+1]  && MB[SIGNAL_BAR] < MD[SIGNAL_BAR])
	   {     
	   PlaySound(SoundFile);
	   }
   if(PrevSignal <= 0)
	 {
	 if(MB[SIGNAL_BAR+1] < MD[SIGNAL_BAR+1]  && MB[SIGNAL_BAR] > MD[SIGNAL_BAR])
	   {
		PlaySound(SoundFile);
   }}}}   
//----      
   return(0);
  }
//+++======================================================================+++
//+++======================================================================+++

void manageArr(int z, color clr, int theCode, bool up)   
{
   string objName = ArrowComment + " ["+IntegerToString(SignalPeriod)+"] " + Time[z];
   double gap  = 2.5*iATR(NULL,0,20,z)/4.0;
   
   ObjectCreate(objName, OBJ_ARROW,0,Time[z],0);
   ObjectSet   (objName, OBJPROP_COLOR, clr);  
   ObjectSet   (objName, OBJPROP_ARROWCODE,theCode);
   ObjectSet   (objName, OBJPROP_WIDTH,ArrowSize);  
  if (up)
      ObjectSet(objName,OBJPROP_PRICE1,High[z]+gap);
     else  
      ObjectSet(objName,OBJPROP_PRICE1,Low[z] -gap);
}
//+++======================================================================+++
//+++======================================================================+++

Recommend