Navigation:Home > Content >

Win_Win_BO_Charity.mq4

Time: 2013-04-16 | Download file:Win_Win_BO_Charity.mq4

//+------------------------------------------------------------------+
//|   Win Win - Arrows Alerts & Labels                               |
//|                                                                  |
//|   Copyright © 2014 / airquest@hotmail.com                        |
//|                                                                  |
//|   http://smart-trading.world-record.ch                           |
//|   baded on BO_Tutor_Germany // Facebook.de/BO_Tutor              |
//+------------------------------------------------------------------+


   #property copyright   "Copyright © 2014 // airquest // smart-trading.world-record.ch // based on BO_Tutor_Germany // Facebook.de/BO_Tutor"
   #property link        "http://smart-trading.world-record.ch"
   #property description "Win Win - Arrows Alerts & Labels"


//------------------------------------------------------------------

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_width1 1
#property indicator_color2 Red
#property indicator_width2 1

//---- indicator parameters
extern int     ADX      = 4;
extern int     DeMarker = 4;
extern int     MFI      = 2;
extern int     WPR      = 2;
extern int     ADXLevel = 55;
extern int     ADXPrice1 = PRICE_CLOSE;
extern int     ADXPrice2 = PRICE_CLOSE;

extern double  WPRBuyLevel  = -80;
extern double  WPRSellLevel = -20;

extern double  ArrowsDisplacement = 0.8;
extern int     ArrowsWidth        = 2;
extern color   ArrowsUpColor      = Lime;
extern color   ArrowsDnColor      = Red;
extern int     ArrowsUpCode       = 233;
extern int     ArrowsDnCode       = 234;

extern bool    AlertsOn        = True;
extern bool    AlertsOnCurrent = True;
extern bool    AlertsMessage   = True;
extern bool    AlertsSound     = False;
extern bool    AlertsEmail     = False;
extern bool    AlertsPush      = False;

extern bool    ShowLabels      = False;
extern color   LabelColor      = Yellow;
extern int     LabelFontWidth  = 14;
extern int     LabelCorner     =  1;
extern int     LabelYDistance  =  0;
extern int     LabelXDistance  =  0;
extern string  MessageUp       = "Buy Signal";
extern string  MessageDn       = "Sell Signal";
extern string  UniqueID        = "Win_Win";

//---- indicator buffers
double ArrowsBuy[];
double ArrowsSell[];
double trend[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   IndicatorBuffers(3);
//---- drawing settings
   SetIndexBuffer(0,ArrowsBuy);     SetIndexStyle(0,DRAW_ARROW,NULL,ArrowsWidth,ArrowsUpColor);    SetIndexArrow(0,ArrowsUpCode);
   SetIndexBuffer(1,ArrowsSell);    SetIndexStyle(1,DRAW_ARROW,NULL,ArrowsWidth,ArrowsDnColor);    SetIndexArrow(1,ArrowsDnCode);
   SetIndexBuffer(2,trend);

//---- initialization done
   return(0);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
{
   DeleteLabels();
   return(0);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
{
   int i,counted_bars = IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit = MathMin(Bars-counted_bars,Bars-1);

   for(i=limit; i>=0; i--)
   {
      double ADXMain   = iADX(NULL,0,ADX,PRICE_CLOSE,MODE_MAIN,i+1);
      double DMIPlus0  = iADX(NULL,0,ADX,ADXPrice2,MODE_PLUSDI,i);
      double DMIPlus1  = iADX(NULL,0,ADX,ADXPrice1,MODE_PLUSDI,i+1);
      double DMIMinus0 = iADX(NULL,0,ADX,ADXPrice1,MODE_MINUSDI,i);
      double DMIMinus1 = iADX(NULL,0,ADX,ADXPrice2,MODE_MINUSDI,i+1);
      double DeMark    = iDeMarker(NULL,0,DeMarker,i+1);
      double MFIBuf    = iMFI(NULL,0,MFI,i+1);
      double WPRBuf1   = iWPR(NULL,0,WPR,i+1);
      double WPRBuf2   = iWPR(NULL,0,WPR,i+2);

      if      ((DMIPlus1DMIMinus0) && DeMark == 0 && MFIBuf ==   0 && (WPRBuf2 > WPRBuyLevel  || WPRBuf1 > WPRBuyLevel)  && ADXMain > ADXLevel) trend[i] =  1;
      else if ((DMIPlus1>DMIMinus1 && DMIPlus0 ADXLevel) trend[i] = -1;
      else                                                                                                                                                             trend[i] = EMPTY_VALUE;

      double gap  = iATR(NULL,0,100,i);
      double high = High[i] + gap * ArrowsDisplacement;
      double low  = Low[i]  - gap * ArrowsDisplacement;

      ArrowsBuy[i]  = EMPTY_VALUE;
      ArrowsSell[i] = EMPTY_VALUE;

      if      (trend[i] ==  1)
      {
         ArrowsBuy[i]  = low;
      }
      else if (trend[i] == -1)
      {
         ArrowsSell[i] = high;
      }
   }

   if(ArrowsBuy[0] != EMPTY_VALUE)
   {
      if(AlertsOn)
      {
         if (AlertsOnCurrent)
         int  whichBar = 0;
         else whichBar = 1;
         doAlert(whichBar,MessageUp);
      }
      if(ShowLabels) AddLabels(MessageUp);
   }
   
   if(ArrowsSell[0] != EMPTY_VALUE)
   {
      if(AlertsOn)
      {
         if (AlertsOnCurrent)
              whichBar = 0;
         else whichBar = 1;
         doAlert(whichBar,MessageDn);
      }
      if(ShowLabels) AddLabels(MessageDn);
   }

   return(0);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
  void doAlert(int forBar, string doWhat)
{
   static string   previousAlert = "Nothing";
   static datetime previousTime;
   string message;

   if (previousAlert != doWhat && previousTime != Time[forBar])
   {
       previousAlert  = doWhat;
       previousTime   = Time[forBar];

       message = StringConcatenate(Symbol()," - ",TimeFrameToString(Period())," - "+UniqueID+": ",doWhat);
          if (AlertsMessage) Alert(message);
          if (AlertsEmail)   SendMail(StringConcatenate(Symbol(),""+UniqueID+": "),message);
          if (AlertsPush)    SendNotification(message);
          if (AlertsSound)   PlaySound("alert2.wav");
   }
}

string TimeFrameToString(int tf)
{
   string tfs;
   switch(tf)
   {
      case PERIOD_M1:     tfs = "M1";      break;
      case PERIOD_M5:     tfs = "M5";      break;
      case PERIOD_M15:    tfs = "M15";     break;
      case PERIOD_M30:    tfs = "M30";     break;
      case PERIOD_H1:     tfs = "H1";      break;
      case PERIOD_H4:     tfs = "H4";      break;
      case PERIOD_D1:     tfs = "D1";      break;
      case PERIOD_W1:     tfs = "W1";      break;
      case PERIOD_MN1:    tfs = "MN1";
      default: tfs = "M" + DoubleToStr(tf,0);
   }
   return(tfs);
}

void AddLabels(string message)
{
   DeleteLabels();
   string name = UniqueID+"_Labels";
      ObjectDelete(name);
      ObjectCreate(0,name,OBJ_LABEL,0,Time[0],Close[0]);
      ObjectSetText(name,message,LabelFontWidth,NULL,LabelColor);
      ObjectSet(name,OBJPROP_XDISTANCE,LabelXDistance);
      ObjectSet(name,OBJPROP_YDISTANCE,LabelYDistance);
      ObjectSet(name,OBJPROP_CORNER,LabelCorner);
}

void DeleteLabels()
{
   string name = UniqueID+"_Labels";
   ObjectDelete(name);
}

Recommend