XO 4TF score





//+------------------------------------------------------------------+
//|                                                 XO 4TF score.mq4 |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_separate_window
#property indicator_buffers    4
#property indicator_color1     PaleGreen
#property indicator_color2     LightCoral
#property indicator_color3     Lime
#property indicator_color4     Red
#property indicator_width1     3
#property indicator_width2     3
#property indicator_width3     3
#property indicator_width4     3
#property indicator_minimum   -4
#property indicator_maximum    4
#property indicator_level1     0
#property indicator_levelwidth 1
#property indicator_levelcolor Lime 
#property indicator_levelstyle STYLE_DOT

//
//
//
//
//

extern string _           = "Parameters";
extern double KirPER      = 6.5;
extern string TF1         = "M5";
extern string TF2         = "M15";
extern string TF3         = "M30";
extern string TF4         = "H1";
extern double KirPER1     = 6.5;
extern double KirPER2     = 6.5;
extern double KirPER3     = 6.5;
extern double KirPER4     = 6.5;
extern bool   JustLastBar = true;

//
//
//
//
//

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double Hi[];
double Lo[];
double no[];
double kr[];

//
//
//
//
//

int    Kir=0;
int    tF1;
int    tF2;
int    tF3;
int    tF4;
string IndicatorFileName;



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

int init()
{
   IndicatorDigits(0);
   IndicatorBuffers(8);   
      SetIndexBuffer(0,ExtMapBuffer1); SetIndexStyle(0,DRAW_HISTOGRAM);
      SetIndexBuffer(1,ExtMapBuffer2); SetIndexStyle(1,DRAW_HISTOGRAM);
      SetIndexBuffer(2,ExtMapBuffer3); SetIndexStyle(2,DRAW_HISTOGRAM);
      SetIndexBuffer(3,ExtMapBuffer4); SetIndexStyle(3,DRAW_HISTOGRAM);
      SetIndexBuffer(4,no);
      SetIndexBuffer(5,kr);
      SetIndexBuffer(6,Hi);
      SetIndexBuffer(7,Lo);

   //
   //
   //
   //
   //
      
   if (_!="Calculate")
   {
      SetIndexEmptyValue(4,0.00);
      SetIndexEmptyValue(5,0.00);
      SetIndexEmptyValue(6,0.00);
      SetIndexEmptyValue(7,0.00);
      
      //
      //
      //
      //
      //
      
      tF1 = stringToTimeFrame(TF1);
      tF2 = stringToTimeFrame(TF2);
      tF3 = stringToTimeFrame(TF3);
      tF4 = stringToTimeFrame(TF4);
         IndicatorShortName("XO 4TF");
         IndicatorFileName = WindowExpertName();
   }
   return(0);
}



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

int start()
{
   double cur,valuel,valueh;
   int    counted_bars=IndicatorCounted();
   int    i,limit;


   if(counted_bars<0) return(-1);
         
   //
   //
   //
   //
   //

   if (_!="Calculate")
   {
         if (JustLastBar)
            {
               limit = Bars-counted_bars;
            }               
         else
            {            
               if(counted_bars>0) counted_bars--;
                  limit = Bars-counted_bars;
                  limit = MathMax(limit,tF1/Period());
                  limit = MathMax(limit,tF2/Period());
                  limit = MathMax(limit,tF3/Period());
                  limit = MathMax(limit,tF4/Period());
            }                  
         
         
         //
         //
         //
         //
         //
         
         int y1 = 0;
         int y2 = 0;
         int y3 = 0;
         int y4 = 0;
         for(i=0; i<limit; i++)
         {
            y1 = iBarShift( NULL, tF1, Time[i], false );
            y2 = iBarShift( NULL, tF2, Time[i], false );
            y3 = iBarShift( NULL, tF3, Time[i], false );
            y4 = iBarShift( NULL, tF4, Time[i], false );
         
         
            //
            //
            //
            //
            //
            
            double totalUp = 0;
            double totalDn = 0;
                totalUp += iCustom(NULL,tF1,IndicatorFileName,"Calculate",KirPER1,0,y1);
                totalUp += iCustom(NULL,tF2,IndicatorFileName,"Calculate",KirPER2,0,y2);
                totalUp += iCustom(NULL,tF3,IndicatorFileName,"Calculate",KirPER3,0,y3);
                totalUp += iCustom(NULL,tF4,IndicatorFileName,"Calculate",KirPER4,0,y4);
            ExtMapBuffer1[i] = 0.00;
            ExtMapBuffer2[i] = 0.00;
            ExtMapBuffer3[i] = 0.00;
            ExtMapBuffer4[i] = 0.00;
            
            //
            //
            //
            //
            //
            
            totalDn = (totalUp-4);
            if (totalUp == 4 || totalDn== -4)
               {               
                  ExtMapBuffer3[i] = totalUp;
                  ExtMapBuffer4[i] = totalDn;
               }
            else
               {
                 ExtMapBuffer1[i] = totalUp;
                 ExtMapBuffer2[i] = totalDn;
               }                  
         }
      return(0);         
   }

   //
   //
   //
   //
   //
                  
   if(counted_bars>0) counted_bars--;
           limit = Bars-counted_bars;
   for(i = limit; i >= 0; i--)
   {         
      if (Kir<1) { Hi[i+1]=Close[i]; Lo[i+1]=Close[i]; Kir =1; }

      //
      //
      //
      //
      //
      
      cur   = Close[i];
      Hi[i] = Hi[i+1];
      Lo[i] = Lo[i+1];
      no[i] = no[i+1];
      kr[i] = kr[i+1];

         if (cur > (Hi[i]+KirPER * Point)) 
         {
            Hi[i] = cur;
            Lo[i] = cur-KirPER*Point;
            kr[i] = 1;
            no[i] = 0;
         }
         if (cur < (Lo[i]-KirPER*Point)) 
         {
            Lo[i] = cur;
            Hi[i] = cur+KirPER*Point;
            no[i] = 1;
            kr[i] = 0;
         }

      //
      //
      //
      //
      //
      
      valueh=kr[i];
      ExtMapBuffer1[i]=valueh;
         
         if (valueh < 0) { ExtMapBuffer1[i] = 0; } 
         if (valueh > 0) { ExtMapBuffer1[i] = 1; } 

      valuel=0-no[i];
      ExtMapBuffer2[i]=valuel;

         if (valuel > 0) { ExtMapBuffer2[i] =  0; } 
         if (valuel < 0) { ExtMapBuffer2[i] = -1; } 

   }
   return(0);
}



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

int stringToTimeFrame(string tfs)
{
   int tf=0;
       tfs = StringTrimLeft(StringTrimRight(StringUpperCase(tfs)));
         if (tfs=="M1" || tfs=="1")     tf=PERIOD_M1;
         if (tfs=="M5" || tfs=="5")     tf=PERIOD_M5;
         if (tfs=="M15"|| tfs=="15")    tf=PERIOD_M15;
         if (tfs=="M30"|| tfs=="30")    tf=PERIOD_M30;
         if (tfs=="H1" || tfs=="60")    tf=PERIOD_H1;
         if (tfs=="H4" || tfs=="240")   tf=PERIOD_H4;
         if (tfs=="D1" || tfs=="1440")  tf=PERIOD_D1;
         if (tfs=="W1" || tfs=="10080") tf=PERIOD_W1;
         if (tfs=="MN" || tfs=="43200") tf=PERIOD_MN1;
         if (tf<Period()) tf=Period();
  return(tf);
}

//
//
//
//
//

string StringUpperCase(string str)
{
   string   s = str;
   int      lenght = StringLen(str) - 1;
   int      char;
   
   while(lenght >= 0)
      {
         char = StringGetChar(s, lenght);
         
         //
         //
         //
         //
         //
         
         if((char > 96 && char < 123) || (char > 223 && char < 256))
                  s = StringSetChar(s, lenght, char - 32);
         else 
              if(char > -33 && char < 0)
                  s = StringSetChar(s, lenght, char + 224);
         lenght--;
   }
   
   //
   //
   //
   //
   //
   
   return(s);
}



Sample





Analysis



Market Information Used:

Series array that contains open time of each bar
Series array that contains close prices for each bar


Indicator Curves created:

Implements a curve of type DRAW_HISTOGRAM


Indicators Used:




Custom Indicators Used:
IndicatorFileName

Order Management characteristics:

Other Features: