BetterVolume 1.5 Alerts

Author: VSA TRADERS
Price Data Components
Series array that contains tick volumes of each bar
Miscellaneous
It issuies visual alerts to the screenIt sends emailsIt plays sound alerts
0 Views
0 Downloads
0 Favorites
BetterVolume 1.5 Alerts
ÿþ//+------------------------------------------------------------------+

//|                                     BetterVolume 1.5a Alerts.mq5 |

//|                                             MT4 to MT5 Leonardo4 |

//|                          https://www.mql5.com/ru/users/leonardo4 |

//+------------------------------------------------------------------+

#property copyright "VSA TRADERS"



#property indicator_separate_window



#property indicator_buffers 7

#property indicator_plots 7            // :>;8G5AB2> >B>1@0605<KE 1CD5@>2



#property indicator_color1 Red         // Climax High Red 

#property indicator_color2 DeepSkyBlue // Neutral DeepSkyBlue 

#property indicator_color3 Yellow      // Low Yellow 

#property indicator_color4 Lime        // High Churn Lime 

#property indicator_color5 White       // Climax Low CadetBlue LightSeaGreen White 

#property indicator_color6 Orange      // Climax Churn 

#property indicator_color7 Maroon      // Ma Maroon 





input string   Note                    = "0 means Display all bars";

input int      MAPeriod                = 24 ;

input int      LookBack                = 20;

input int      width1                  = 2 ;





input string   ahi="******* ALERTs on COLORCHANGE?";

input bool     AlertOnColorChange      = false;//fxdaytrader

input string   ahi1="-----: ignore some colorchanges?";

input bool     IgnoreLightSeaGreen     = false;

input bool     IgnoreWhite             = false;

input bool     IgnoreFireBrick         = false;

input bool     IgnoreDodgerBlue        = false;

input bool     IgnoreLightSalmon       = false;

input bool     IgnoreMagenta           = false;

input string   ahi2="******* ALERTs on MOVING AVERAGE CROSS?";

input bool     AlertOnMAcross          = false;

input string   ahi3="-----: alert methods:";

input int      AlertCandleShift        = 0;           //0:current candle

input bool     PopupAlerts             = true;

input bool     EmailAlerts             = false;

input bool     PushNotificationAlerts  = false;

input bool     SoundAlerts             = false;

input string   SoundFile               = "alert.wav"; //fxdaytrader



input int      History                 = 300; // History candle



string msg,crossdir;





double red[],blue[],yellow[],green[],white[],magenta[],v4[];



// Variables for alerts:

color CurrentColor[3] = {White, White, White};

//datetime LastAlertTime = D'1980.01.01';



bool     FirstStartFlag;

int      cnt_bars;               // AG5BG8: 10@>2

int bar, limit;



//int      handle_iMA;

//double   iMA_Buffer[];



//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//---- indicators

   SetIndexBuffer(0,red);

   PlotIndexSetString(0,PLOT_LABEL,"Climax High ");

   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_HISTOGRAM);

   PlotIndexSetInteger(0,PLOT_LINE_WIDTH,width1);



   SetIndexBuffer(1,blue);

   PlotIndexSetString(1,PLOT_LABEL,"Neutral");

   PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_HISTOGRAM);

   PlotIndexSetInteger(1,PLOT_LINE_WIDTH,width1);



   SetIndexBuffer(2,yellow);

   PlotIndexSetString(2,PLOT_LABEL,"Low ");

   PlotIndexSetInteger(2,PLOT_DRAW_TYPE,DRAW_HISTOGRAM);

   PlotIndexSetInteger(2,PLOT_LINE_WIDTH,width1);



   SetIndexBuffer(3,green);

   PlotIndexSetString(3,PLOT_LABEL,"HighChurn ");

   PlotIndexSetInteger(3,PLOT_DRAW_TYPE,DRAW_HISTOGRAM);

   PlotIndexSetInteger(3,PLOT_LINE_WIDTH,width1);



   SetIndexBuffer(4,white);

   PlotIndexSetString(4,PLOT_LABEL,"Climax Low ");

   PlotIndexSetInteger(4,PLOT_DRAW_TYPE,DRAW_HISTOGRAM);

   PlotIndexSetInteger(4,PLOT_LINE_WIDTH,width1);



   SetIndexBuffer(5,magenta);

   PlotIndexSetString(5,PLOT_LABEL,"ClimaxChurn ");

   PlotIndexSetInteger(5,PLOT_DRAW_TYPE,DRAW_HISTOGRAM);

   PlotIndexSetInteger(5,PLOT_LINE_WIDTH,width1);



   SetIndexBuffer(6,v4);

   PlotIndexSetString(6,PLOT_LABEL,"Average("+(string)MAPeriod+")");

   PlotIndexSetInteger(6,PLOT_DRAW_TYPE,DRAW_LINE);

   PlotIndexSetInteger(6,PLOT_LINE_WIDTH,1);

   

   

   // #AB0=02;8205< ?>@O4>: 8=45:A0F88 1CD5@>2

   ArraySetAsSeries(red, true);

   ArraySetAsSeries(blue, true);

   ArraySetAsSeries(yellow, true);

   ArraySetAsSeries(green, true);

   ArraySetAsSeries(white, true);

   ArraySetAsSeries(magenta, true);

   ArraySetAsSeries(v4, true);



   IndicatorSetString(INDICATOR_SHORTNAME,"Better Volume 1.5");



      cnt_bars = History;// >;-2> 10@>2 4;O ?>4AG5B0 A83=0;>2

      bar   = 0;

      limit = 0;

      FirstStartFlag = true;

      

      ChartRedraw(0);



//--- :>=5F DC=:F88 8=8F80;870F88 A>25B=8:0

      return(INIT_SUCCEEDED);

  } 

  

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime& time[],

                const double& open[],

                const double& high[],

                const double& low[],

                const double& close[],

                const long& tick_volume[],

                const long& volume[],

                const int& spread[])

   {



//---          

       ArraySetAsSeries(time,true);

       ArraySetAsSeries(open,true);

       ArraySetAsSeries(high,true);

       ArraySetAsSeries(low,true);

       ArraySetAsSeries(close,true);

       ArraySetAsSeries(tick_volume,true);

       ArraySetAsSeries(volume,true);



      int x;

      int n;

//---

     if(History>=rates_total) cnt_bars=rates_total-1;

     else cnt_bars=History;

     

//----+ ?@>25@:0 :>;8G5AB20 10@>2 =0 4>AB0B>G=>ABL 4;O :>@@5:B=>3> @0AGQB0 8=48:0B>@0

      if(rates_total<=cnt_bars)

         {

            

            Print("54>AB0B>G=> 8AB>@88. ABL "+IntegerToString(rates_total-1)+" =04> "+IntegerToString(cnt_bars));																																						 

            return(0);

         }

         

//--- ?@8 ?5@2>< 70?CA:5 8=8F80;870F8O 8=48:0B>@=>3> 1CD5@0  

     if(FirstStartFlag) 

      {

         

//--- >1=C;8< 2A5 1CD5@K 

         int out;

         

         out = ArrayInitialize(red,EMPTY_VALUE);

         if(out>0) Print("OnCalculate: >;8G5AB2> 8=8F80;878@>20==KE M;5<5=B>2 <0AA820 red = "+IntegerToString(out));

         

         out = ArrayInitialize(blue,EMPTY_VALUE);

         if(out>0) Print("OnCalculate: >;8G5AB2> 8=8F80;878@>20==KE M;5<5=B>2 <0AA820 blue = "+IntegerToString(out));

         

         out = ArrayInitialize(yellow,EMPTY_VALUE);

         if(out>0) Print("OnCalculate: >;8G5AB2> 8=8F80;878@>20==KE M;5<5=B>2 <0AA820 yellow = "+IntegerToString(out));

         

         out = ArrayInitialize(green,EMPTY_VALUE);

         if(out>0) Print("OnCalculate: >;8G5AB2> 8=8F80;878@>20==KE M;5<5=B>2 <0AA820 green = "+IntegerToString(out));

         

         out = ArrayInitialize(white,EMPTY_VALUE);

         if(out>0) Print("OnCalculate: >;8G5AB2> 8=8F80;878@>20==KE M;5<5=B>2 <0AA820 white = "+IntegerToString(out));

         

         out = ArrayInitialize(magenta,EMPTY_VALUE);

         if(out>0) Print("OnCalculate: >;8G5AB2> 8=8F80;878@>20==KE M;5<5=B>2 <0AA820 magenta = "+IntegerToString(out));

	

         out = ArrayInitialize(v4,EMPTY_VALUE);

         if(out>0) Print("OnCalculate: >;8G5AB2> 8=8F80;878@>20==KE M;5<5=B>2 <0AA820 v4 = "+IntegerToString(out));

	

         for(x=rates_total-1; x>=0 && !IsStopped(); x--)

            {

               red[x] = EMPTY_VALUE;

               blue[x] = EMPTY_VALUE;

               yellow[x] = EMPTY_VALUE;

               green[x] = EMPTY_VALUE;

               white[x] = EMPTY_VALUE;

               magenta[x] = EMPTY_VALUE;

               v4[x] = EMPTY_VALUE;

            }

         FirstStartFlag = false;

         

         ChartRedraw(0);

      }

      

   limit=cnt_bars-1;   



   double VolLowest,Range,Value2,Value3,HiValue2,HiValue3,LoValue3,tempv2,tempv3,tempv;



   for(int i=0; i<limit; i++)

     {

      red[i] = 0;

      blue[i] = (double)tick_volume[i];

      

      yellow[i] = 0;

      green[i] = 0;

      white[i] = 0;

      magenta[i] = 0;

      Value2=0;

      Value3=0;

      HiValue2=0;

      HiValue3=0;

      LoValue3=99999999;

      tempv2=0;

      tempv3=0;

      tempv=0;

      if(i <= 2)

         CurrentColor[i] = White;





      VolLowest = (double)tick_volume[iLowest(NULL,0,MODE_VOLUME,20,i)];

      if(tick_volume[i] == VolLowest)

        {

         yellow[i] = NormalizeDouble(tick_volume[i],0);

         blue[i]=0;

         if(i <= 2)

            CurrentColor[i] = FireBrick;

        }



      Range = (high[i]-low[i]);

      Value2 = tick_volume[i]*Range;



      if(Range != 0)

         Value3 = tick_volume[i]/Range;



      for(n=i; n<i+MAPeriod; n++)

        {

         tempv= tick_volume[n] + tempv;

        }

      v4[i] = NormalizeDouble(tempv/MAPeriod,0);//moving average



      for(n=i; n<i+LookBack; n++)

        {

         tempv2 = tick_volume[n]*((high[n]-low[n]));

         if(tempv2 >= HiValue2)

            HiValue2 = tempv2;



         if(tick_volume[n]*((high[n]-low[n])) != 0)

           {

            tempv3 = tick_volume[n] / ((high[n]-low[n]));

            if(tempv3 > HiValue3)

               HiValue3 = tempv3;

            if(tempv3 < LoValue3)

               LoValue3 = tempv3;

           }

        }



      if(Value2 == HiValue2  && close[i] > (high[i] + low[i]) / 2)

        {

         red[i] = NormalizeDouble(tick_volume[i],0);

         blue[i]=0;

         yellow[i]=0;

         if(i <= 2)

            CurrentColor[i] = LightSeaGreen;

        }



      if(Value3 == HiValue3)

        {

         green[i] = NormalizeDouble(tick_volume[i],0);

         blue[i] =0;

         yellow[i]=0;

         red[i]=0;

         if(i <= 2)

            CurrentColor[i] = DodgerBlue;

        }

      if(Value2 == HiValue2 && Value3 == HiValue3)

        {

         magenta[i] = NormalizeDouble(tick_volume[i],0);

         blue[i]=0;

         red[i]=0;

         green[i]=0;

         yellow[i]=0;

         if(i <= 2)

            CurrentColor[i] = Magenta;

        }

      if(Value2 == HiValue2  && close[i] <= (high[i] + low[i]) / 2)

        {

         white[i] = NormalizeDouble(tick_volume[i],0);

         magenta[i]=0;

         blue[i]=0;

         red[i]=0;

         green[i]=0;

         yellow[i]=0;

         if(i <= 2)

            CurrentColor[i] = LightSalmon;

        }

     }

//----

//Alerts on volume-ma-cross:

   static datetime LastCrossAlertTime=0;

   if(AlertOnMAcross && CheckForVolMaCross(AlertCandleShift) && LastCrossAlertTime!=iTime(NULL,0,0))

     {

      string msg2="BetterVolume 1.5a Alert on "+Symbol()+", period "+TFtoStr(Period())+": Moving Average/Volume cross "+crossdir;

      doAlerts(msg2,SoundFile);

      LastCrossAlertTime=iTime(NULL,0,0);

     }

//----

//Alerts on color change:

   static datetime LastAlertTime=0;

   if(AlertOnColorChange && (CurrentColor[AlertCandleShift] != CurrentColor[AlertCandleShift+1]) && (LastAlertTime != iTime(NULL,0,0)))

     {

      if((CurrentColor[AlertCandleShift] == LightSeaGreen) && (IgnoreLightSeaGreen))

         return rates_total;

      if((CurrentColor[AlertCandleShift] == White) && (IgnoreWhite))

         return rates_total;

      if((CurrentColor[AlertCandleShift] == FireBrick) && (IgnoreFireBrick))

         return rates_total;

      if((CurrentColor[AlertCandleShift] == DodgerBlue) && (IgnoreDodgerBlue))

         return rates_total;

      if((CurrentColor[AlertCandleShift] == LightSalmon) && (IgnoreLightSalmon))

         return rates_total;

      if((CurrentColor[AlertCandleShift] == Magenta) && (IgnoreMagenta))

         return rates_total;

      //alerts:

      msg="BetterVolume 1.5a Alert on "+Symbol()+", period "+TFtoStr(Period())+": Color changed from "+ColorToString2(CurrentColor[AlertCandleShift+1])+" to "+ColorToString2(CurrentColor[AlertCandleShift]);

      doAlerts(msg,SoundFile);

      //SendMail("Better Volume Alert - " + ColorToString2(CurrentColor[AlertCandleShift+1]) + " -> " + ColorToString2(CurrentColor[AlertCandleShift]), Time[AlertCandleShift] + " BetterVolume - Color changed from " + ColorToString2(CurrentColor[AlertCandleShift+1]) + " to " + ColorToString2(CurrentColor[AlertCandleShift]) + ".");

      LastAlertTime = iTime(NULL,0,0);

     }//if ((CurrentColor[1] != CurrentColor[2]) && (LastAlertTime != Time[1]))

//

   return rates_total;

  }



//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

string ColorToString2(color Color)

  {

   switch(Color)

     {

      case LightSeaGreen:

         return("LightSeaGreen");

      case White:

         return("White");

      case FireBrick:

         return("FireBrick");

      case DodgerBlue:

         return("DodgerBlue");

      case LightSalmon:

         return("LightSalmon");

      case Magenta:

         return("Magenta");

      default:

         return("Unknown");

     }

  }

//+------------------------------------------------------------------+

//fxdaytrader:

bool CheckForVolMaCross(int shift)

  {

   double ma=v4[shift];

   double mab4=v4[shift+1];

   double vol=(double)iVolume(NULL,0,shift);

   double volb4=(double)iVolume(NULL,0,shift+1);

   crossdir="NONE";

   if(vol>ma && volb4<=mab4)

     {

      crossdir="UP";

      return(true);

     }

   if(vol<ma && volb4>=mab4)

     {

      crossdir="DOWN";

      return(true);

     }

   return(false);

  }//bool CheckForVolMaCross(int shift) {



//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void doAlerts(string msg3,string _SoundFile)

  {

   string emailsubject="MT4 alert on acc. "+(string)AccountInfoInteger(ACCOUNT_LOGIN)+", "+MQLInfoString(MQL_PROGRAM_NAME)+" - Alert on "+Symbol()+", period "+TFtoStr(Period());

   if(PopupAlerts)

      Alert(msg3);

   if(EmailAlerts)

      SendMail(emailsubject,msg3);

   if(PushNotificationAlerts)

      SendNotification(msg3);

   if(SoundAlerts)

      PlaySound(_SoundFile);

  }//void doAlerts(string msg,string SoundFile) {



//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

string TFtoStr(int period)

  {

   switch(period)

     {

      case 1     :

         return("M1");

         break;

      case 5     :

         return("M5");

         break;

      case 15    :

         return("M15");

         break;

      case 30    :

         return("M30");

         break;

      case 60    :

         return("H1");

         break;

      case 240   :

         return("H4");

         break;

      case 1440  :

         return("D1");

         break;

      case 10080 :

         return("W1");

         break;

      case 43200 :

         return("MN1");

         break;

      default    :

         return(DoubleToString(period,0));

     }

   return("UNKNOWN");

  }//string TFtoStr(int period) {

//+------------------------------------------------------------------+

Comments