Navigation´╝ÜHome > Content >

Corridor_SSA_normalized_end-pointed_&_alerts_2_nmc.mq4

Time: 2016-01-08 | Download file:Corridor_SSA_normalized_end-pointed_&_alerts_2_nmc.mq4

//+--------------------------------------------------------------------------------------+
//|                                                                                      |
//+--------------------------------------------------------------------------------------+
#property copyright "www.forex-tsd.com"
#property link      "www.forex-tsd.com"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 LimeGreen
#property indicator_color3 Orange
#property indicator_width2 2
#property indicator_width3 2
#property indicator_level1 0.0

#import "libSSA.dll"
   void fastSingular(double& sourceArray[],int arraySize, int lag, int numberOfComputationLoops, double& destinationArray[]);
#import

//
//
//
//
//

extern string TimeFrame               = "Current time frame";
extern int    SSAPrice                =  PRICE_CLOSE;
extern int    SSALag                  = 25;
extern int    SSANumberOfComputations =  2;
extern int    SSAPeriodNormalization  = 25;
extern int    SSANumberOfBars         = 300;
extern int    FirstBar                = 400; 
extern double HighLowStep             = 0.005;
extern bool   alertsOn                = false;
extern bool   alertsOnCurrent         = true;
extern bool   alertsMessage           = true;
extern bool   alertsSound             = false;
extern bool   alertsEmail             = false;

//
//
//
//
//

double in[];
double no[];
double ssaIn[];
double ssaOut[];
double max[];
double min[];
double trend[];

int    timeFrame;
string indicatorFileName;
bool   returnBars;
bool   calculateValue;

//+--------------------------------------------------------------------------------------+
//|                                                                                      |
//+--------------------------------------------------------------------------------------+
//
//
//
//
//

int init()
{
   IndicatorBuffers(5);
      SetIndexBuffer(0,in);
      SetIndexBuffer(1,max);
      SetIndexBuffer(2,min);
      SetIndexBuffer(3,no);
      SetIndexBuffer(4,trend);
         indicatorFileName = WindowExpertName();
         calculateValue    = (TimeFrame=="calculateValue"); if (calculateValue) return(0);
         returnBars        = (TimeFrame=="returnBars");     if (returnBars)     return(0);
         timeFrame         = stringToTimeFrame(TimeFrame);
   IndicatorShortName("Corridor SSA normalized end-pointed V");
   return(0);
}
int deinit(){return(0);}

//+--------------------------------------------------------------------------------------+
//|                                                                                      |
//+--------------------------------------------------------------------------------------+
//
//
//
//
//

int start()
{
   int i,limit,counted_bars = IndicatorCounted();

      if(counted_bars < 0) return(-1);
      if(counted_bars > 0) counted_bars--;
         limit = MathMin(Bars-counted_bars,Bars-1);
         if (returnBars) { in[0] = limit+1; return(0); }

   //
   //
   //
   //
   //
      
   if (calculateValue || timeFrame==Period())
   {
      for(i=limit; i>=0; i--)
      {
         double ma    = iMA(NULL,0,SSAPeriodNormalization,0,MODE_SMA,SSAPrice,i);
         double dev   = 3.0*iStdDev(NULL,0,SSAPeriodNormalization,0,MODE_SMA,SSAPrice,i);
         double price = iMA(NULL,0,1,0,MODE_SMA,SSAPrice,i);
            if (dev == 0) dev = 0.000001;
             no[i] = (price-ma)/dev;
             in[i] = 0;
             min[i] = 0;
             max[i] = 0;
            
         //
         //
         //
         //
         //
            
         if (i<=FirstBar)
         {
            int ssaBars = MathMin(Bars-i,SSANumberOfBars);
            if (ssaBars0) trend[i] =  1;
               if (in[i]<0) trend[i] = -1;
         }                   
     }                  
      if (alertsOn)
      {
         if (alertsOnCurrent)
              int whichBar = 0;
         else     whichBar = 1; 
         if (trend[whichBar] != trend[whichBar+1])
         {
            if (trend[whichBar] == 1) doAlert("up");
            if (trend[whichBar] ==-1) doAlert("down");
         }         
      }
      SetIndexDrawBegin(0,Bars-FirstBar);
      SetIndexDrawBegin(1,Bars-FirstBar);
      SetIndexDrawBegin(2,Bars-FirstBar);
      return(0);
   }            
   
   //
   //
   //
   //
   //

   limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period()));
   for(i=limit; i>=0; i--) 
   {
      int y = iBarShift(NULL,timeFrame,Time[i]);
         in[i]  = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",SSAPrice,SSALag,SSANumberOfComputations,SSAPeriodNormalization,SSANumberOfBars,FirstBar,HighLowStep,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,0,y);
         max[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",SSAPrice,SSALag,SSANumberOfComputations,SSAPeriodNormalization,SSANumberOfBars,FirstBar,HighLowStep,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,1,y);
         min[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",SSAPrice,SSALag,SSANumberOfComputations,SSAPeriodNormalization,SSANumberOfBars,FirstBar,HighLowStep,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,2,y);
   }
   SetIndexDrawBegin(0,Bars-FirstBar*timeFrame/Period());
   SetIndexDrawBegin(1,Bars-FirstBar*timeFrame/Period());
   SetIndexDrawBegin(2,Bars-FirstBar*timeFrame/Period());
   return(0); 
}

//+-------------------------------------------------------------------
//|                                                                  
//+-------------------------------------------------------------------
//
//
//
//
//

void doAlert(string doWhat)
{
   static string   previousAlert="nothing";
   static datetime previousTime;
   string message;
   
      if (previousAlert != doWhat || previousTime != Time[0]) {
          previousAlert  = doWhat;
          previousTime   = Time[0];

          //
          //
          //
          //
          //

          message =  timeFrameToString(Period())+" "+Symbol()+" at "+TimeToStr(TimeLocal(),TIME_SECONDS)+" Corridor normalized end-point SSA crossed zero line "+doWhat;
             if (alertsMessage) Alert(message);
             if (alertsEmail)   SendMail(StringConcatenate(Symbol()," Corridor normalized end-point SSA "),message);
             if (alertsSound)   PlaySound("alert2.wav");
      }
}

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

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

//
//
//
//
//

int stringToTimeFrame(string tfs)
{
   tfs = stringUpperCase(tfs);
   for (int i=ArraySize(iTfTable)-1; i>=0; i--)
         if (tfs==sTfTable[i] || tfs==""+iTfTable[i]) return(MathMax(iTfTable[i],Period()));
                                                      return(Period());
}
string timeFrameToString(int tf)
{
   for (int i=ArraySize(iTfTable)-1; i>=0; i--) 
         if (tf==iTfTable[i]) return(sTfTable[i]);
                              return("");
}

//
//
//
//
//

string stringUpperCase(string str)
{
   string   s = str;

   for (int length=StringLen(str)-1; length>=0; length--)
   {
      int tchar = StringGetChar(s, length);
         if((tchar > 96 && tchar < 123) || (tchar > 223 && tchar < 256))
                     s = StringSetChar(s, length, tchar - 32);
         else if(tchar > -33 && tchar < 0)
                     s = StringSetChar(s, length, tchar + 224);
   }
   return(s);
}

Recommend