Navigation´╝ÜHome > Content >

rsi_triplehull_col_turbo-alerts-arrows_v1.01.mq4

Time: 2014-11-04 | Download file:rsi_triplehull_col_turbo-alerts-arrows_v1.01.mq4

//+------------------------------------------------------------------+
//|                              RSI_TripleHull_COL_TURBO.mq4        |
//|                              Modified by Mladen 19 July 2011     |
//+------------------------------------------------------------------+
#property copyright "AHGDP"
#property link      "RSI_TripleHull_COL_TURBO"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 White
#property indicator_width1 4
#property indicator_color2 Magenta
#property indicator_width2 4

#property indicator_maximum 105
#property indicator_minimum -5

extern int        Len_1M=15;//10 
extern int        Len_5M         = 10;
extern int        Len_15M        = 10;
extern int        Len_30M        = 4;
extern int        Len_60M        = 4;


extern string     THC_6          = "=== LINESIZE =====";
extern int        LineSize1      = 4;
extern int        Len_Style      = 0;
extern int        CountBars      = 600;
extern bool       NoName         = false;
extern bool   arrowsVisible=true;//**************************
extern string arrowsIdentifier   ="RsiTHull1";
extern color  arrowsUpColor=Aqua;//**********
extern color  arrowsDnColor=Magenta;//********
extern double dnarrowgap         = 3;
extern double uparrowgap         = 3;
extern bool   alertsOn           = false;
extern bool   alertsOnCurrent    = false;
extern bool   alertsMessage      = false;
extern bool   alertsSound        = false;
extern bool   alertsEmail        = false;

string            shortName_THTUR= "THTUR";
int               MagicNumber    = 0;

double  VelocityRaw,vel_HMA1,vel_HMA2,vol_HMA1;
double Mixing,MixingC,vel_1A,vel_1B,vel_2A,vol_HMA2;
double  vol_1A,vol_1B,vol_2A,vol_2B,vel_2B;

double MapBuffer1[];
double MapBuffer2[];
double trend[];
double point=0;
double pipMultiplier=1;

int digit;
//==========================================================================================
int init()
  {

   digit=Digits;

   if(digit==3 || digit==5)
     {
      point=Point*10;
      pipMultiplier=10;
     }
   else
     {
      point=Point;
      pipMultiplier=1;
     }

   IndicatorDigits(+0);
   IndicatorBuffers(3);

   SetIndexStyle(0,DRAW_LINE,Len_Style,LineSize1);
   SetIndexBuffer(0,MapBuffer1);
   SetIndexStyle(1,DRAW_LINE,Len_Style,LineSize1);
   SetIndexBuffer(1,MapBuffer2);
   SetIndexBuffer(2,trend);

//=========MagicNumber Generator + shortname========================= 
   MathSrand(TimeLocal()+TimeCurrent());
   int mn=MathRand();
   MathSrand(mn);
   mn=MathRand();
   MagicNumber=mn;
   IndicatorShortName("THTUR");
//======================================================================================      
 return(0);
  }

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

int deinit()
  {
   Refresh();
   deleteArrows();
   return(0);
  }
//+------------------------------------------------------------------------------------------+           
//+------------------------------------------------------------------------------------------+
int start()
  {
   Refresh();
   int counted_bars=IndicatorCounted(),limit,shift;
   double   Len=0;

//  if(counted_bars>Len) limit=Bars-counted_bars-1;
   SetIndexDrawBegin(0,Bars-CountBars);
   SetIndexDrawBegin(1,Bars-CountBars);

//=============HORIZONTAL COLOR LINES ==============================================================  

   double indlev1,indlev2,indlev3;
   switch(Period())
     {
      case 1:  case 5: case 15: case 30:  case 60: case 240: case 1440: case 10080: case 43200:

         indlev1=95; indlev2=5; indlev3=50; break;
     }
   drawLine_THTUR(indlev1,"Up1_THTUR"+MagicNumber,Red);
   drawLine_THTUR(indlev2,"Dn1_THTUR"+MagicNumber,Lime);
   drawLine_THTUR(indlev3,"Zer_THTUR"+MagicNumber,BurlyWood);

//======================  CHANGE PERIOD   ===========================================================   
   switch(Period())
     {
      case 1:     Len=Len_1M; break;
      case 5:     Len = Len_5M; break;
      case 15:    Len = Len_15M; break;
      case 30:    Len = Len_30M; break;
      case 60:    Len = Len_60M; break;
      case 240:   Len = Len_60M; break;
      case 1440:  Len = Len_60M; break;
      case 10080: Len = Len_60M; break;
      case 43200: Len = Len_60M; break;
     }
//========================  SHORTNAME  =================================================         

   if(NoName==false)
     {
      string  Text="(THTUR)";
      Text=Text+"(";
      Text=Text+""+DoubleToStr (Len,0);
      Text=Text+")";
      IndicatorShortName(Text);
     }
//====================================================================================== 
   if((Len+2.0)!=0)
      Mixing=3.0/(Len+2.0);
   MixingC=1.0-Mixing;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-Len-2;
//======================================================================================               

   for(shift=limit;shift>=0;shift--)
     {
      VelocityRaw=100.0*(Close[shift]-Close[shift+1]); // velocity f8 - f10;

                                                       //  a Hull MA.
      vel_1A = MixingC * vel_1A + Mixing * VelocityRaw;
      vel_1B = Mixing * vel_1A + MixingC * vel_1B;
      vel_HMA1=vel_1A*1.5-vel_1B*0.5;

      // another Hull MA
      vel_2A = MixingC * vel_2A + Mixing * vel_HMA1;
      vel_2B = Mixing * vel_2A + MixingC * vel_2B;
      vel_HMA2=vel_2A*1.5-vel_2B*0.5;

      // Onto volatility. 
      vol_1A = MixingC * vol_1A + Mixing * MathAbs(VelocityRaw);
      vol_1B = Mixing * vol_1A + MixingC * vol_1B;
      vol_HMA1=vol_1A*1.5-vol_1B*0.5;

      // Hull MA
      vol_2A = MixingC * vol_2A + Mixing * vol_HMA1;
      vol_2B = Mixing * vol_2A + MixingC * vol_2B;
      vol_HMA2=vol_2A*1.5-vol_2B*0.5;

      if(vol_HMA2!=0)
         MapBuffer1[shift]=(vel_HMA2/vol_HMA2+1.0)*50.0;

      trend[shift]=0;
      if(MapBuffer1[shift] > 65) trend[shift] =  1;
      if(MapBuffer1[shift] < 35) trend[shift] = -1;
      manageArrow(shift);

      //=============  COLOR CODE THM =============================================================================

      MapBuffer2[shift]=EMPTY_VALUE;

      if(MapBuffer1[shift+1]MapBuffer1[shift])
           {
            if(MapBuffer2[shift+1]==EMPTY_VALUE) MapBuffer2[shift+1]=MapBuffer1[shift+1];
            MapBuffer2[shift]=MapBuffer1[shift];
           }
        }
     }


//===========================================================================================================
   manageAlerts();
   return(0);
  }
//================HORIZONTAL COLOR LINES=====================================
void drawLine_THTUR(double lvl_THTUR,string name_THTUR,color Col_THTUR)
  {
   int indicatorWindow_THTUR=WindowFind(shortName_THTUR);
   if(indicatorWindow_THTUR<0)
      return;

   ObjectDelete(name_THTUR);
   ObjectCreate(name_THTUR,OBJ_HLINE,indicatorWindow_THTUR,Time[0],lvl_THTUR,Time[0],lvl_THTUR);
   ObjectSet(name_THTUR,OBJPROP_STYLE,STYLE_DOT);
   ObjectSet(name_THTUR,OBJPROP_COLOR,Col_THTUR);
   ObjectSet(name_THTUR,OBJPROP_BACK,true);
   ObjectSet(name_THTUR,OBJPROP_WIDTH,1);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Refresh()
  {
   ObjectDelete("Up1_THTUR");
   ObjectDelete("Dn1_THTUR");
   ObjectDelete("Zer_THTUR");
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

void manageArrow(int i)
  {
   if(arrowsVisible)
     {
      deleteArrow(Time[i]);
      if(trend[i]!=trend[i+1])
        {
         if(trend[i+1] ==  1 && trend[i] != 1) drawArrow(i,arrowsDnColor,226,true);
         if(trend[i+1] == -1 && trend[i] !=-1) drawArrow(i,arrowsUpColor,225,false);
        }
     }
  }
//
//
//
//
//

void drawArrow(int i,color theColor,int theCode,bool up)
  {
   string name = arrowsIdentifier+":"+Time[i];
   double gap  = 3.0*iATR(NULL,0,20,i)/4.0;

//
//
//
//
//

   ObjectCreate(name,OBJ_ARROW,0,Time[i],0);
   ObjectSet(name,OBJPROP_ARROWCODE,theCode);
   ObjectSet(name,OBJPROP_COLOR,theColor);
   if(up)
      ObjectSet(name,OBJPROP_PRICE1,High[i]+gap);
   else  ObjectSet(name,OBJPROP_PRICE1,Low[i]-gap);
  }
//
//
//
//
//

void deleteArrows()
  {
   string lookFor       = arrowsIdentifier+":";
   int    lookForLength = StringLen(lookFor);
   for(int i=ObjectsTotal()-1; i>=0; i--)
     {
      string objectName=ObjectName(i);
      if(StringSubstr(objectName,0,lookForLength)==lookFor) ObjectDelete(objectName);
     }
  }
//
//
//
//
//

void deleteArrow(datetime time)
  {
   string lookFor=arrowsIdentifier+":"+time; ObjectDelete(lookFor);
  }
//
//
//
//
//

void manageAlerts()
  {
   if(alertsOn)
     {
      if(alertsOnCurrent)
         int whichBar = 0;
      else     whichBar = 1;
      if(trend[whichBar]!=trend[whichBar+1])
        {
         if(trend[whichBar+1] ==  1 && trend[whichBar] != 1) doAlert(whichBar,"sell");
         if(trend[whichBar+1] == -1 && trend[whichBar] !=-1) doAlert(whichBar,"buy");
        }
     }
  }
//
//
//
//
//

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()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," RSI Turbo broke level 50 ",doWhat);
      if(alertsMessage) Alert(message);
      if(alertsEmail) SendMail(StringConcatenate(Symbol(),"RSI Hull Turbo"),message);
      if(alertsSound) PlaySound("ENTRY-voice.wav");//("alert2.wav")
     }
  }
//+------------------------------------------------------------------+

Recommend