Heat_Map





//+------------------------------------------------------------------+
//|                                                     Heat_Map.mq4 |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      "mladenfx@gmail.com"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1

//
//
//
//
//

extern string CurrenciesHorizontal   = "EUR;GBP;CHF;CAD;AUD;NZD";
extern string CurrenciesVertical     = "USD;JPY";  // EUR;GBP;JPY;CHF;CAD;AUD;NZD";
extern string TimeFrames   = "H1;D1";
extern color  StrongUp     = LimeGreen;
extern color  WeakUp       = Green;
extern color  NoMove       = DimGray;
extern color  WeakDown     = FireBrick;
extern color  StrongDown   = Red;
extern color  DoesNotExist = Black;
extern bool   UseMSLineDrawFont = false;

//
//
//
//
//

string shortName;
int    cpairsLenH;
int    cpairsLenV;
int    shortLength;
int    window;  

//
//
//
//
//

int    ctimesLen;
string cpairsh[];
string cpairsv[];
int    aTimes[];
string addition  = "";
string FontToUse = "Terminal";

//
//
//
//
//

int init()
{
   if (UseMSLineDrawFont) FontToUse = "MS LIneDraw";

      setUpStrings(cpairsh,cpairsLenH,CurrenciesHorizontal);
      setUpStrings(cpairsv,cpairsLenV,CurrenciesVertical);

      //
      //
      //
      //
      //

      TimeFrames = StringUpperCase(StringTrimLeft(StringTrimRight(TimeFrames)));
      if (StringSubstr(TimeFrames,StringLen(TimeFrames)-1,1) != ";")
                       TimeFrames = StringConcatenate(TimeFrames,";");

         //
         //
         //
         //
         //                                   
            
         int s = 0;
         int i = StringFind(TimeFrames,";",s);
         int time;
            while (i > 0)
            {
               string current = StringSubstr(TimeFrames,s,i-s);
               time    = stringToTimeFrame(current);
               if (time > 0) {
                     ArrayResize(aTimes,ArraySize(aTimes)+1);
                                 aTimes[ArraySize(aTimes)-1] = time; }
                                 s = i + 1;
                                     i = StringFind(TimeFrames,";",s);
            }
      ctimesLen = ArraySize(aTimes);
      
   //
   //
   //
   //
   //
   
   if (IsMini())   addition="m";
   if (IsDotted()) addition="..";
      shortName   = MakeUniqueName("CHM ","");
      shortLength = StringLen(shortName);
      IndicatorShortName(shortName);
   return(0);
}

//
//
//
//
//

int deinit()
{
   clearObjects();
   return(0);
}

//
//
//
//
//

int start()
{
   string name;
   int    gaph = (cpairsLenH*50+10);
   int    gapv = (cpairsLenV*15+20);
   int    i,k,t;

         window = WindowFind(shortName);  
   
   //
   //
   //
   //
   //

      for (t = 0; t < ctimesLen; t++ )
      {
         name = shortName+"t"+t+i;
         if (ObjectFind(name) == -1)
             ObjectCreate(name,OBJ_LABEL,window,0,0,0,0);
                ObjectSet(name,OBJPROP_XDISTANCE,5 +(t%2)*30);
                ObjectSet(name,OBJPROP_YDISTANCE,20+(t/2)*15);
                ObjectSetText(name,TimeFrameToString(aTimes[t]),8,"Arial Bold");

         //
         //
         //
         //
         //
         
         for (i = 0; i < cpairsLenH; i++)
         {
            name = shortName+"h"+t+i;
            if (ObjectFind(name) == -1)
                ObjectCreate(name,OBJ_LABEL,window,0,0,0,0);
                   ObjectSet(name,OBJPROP_XDISTANCE,i*50+114+gaph*(t%2));
                   ObjectSet(name,OBJPROP_YDISTANCE,       1+gapv*(t/2));
                   ObjectSetText(name,cpairsh[i],8,"Arial Bold");
         }                   
         for (i = 0; i < cpairsLenV; i++)
         {
            name = shortName+"v"+t+i;
            if (ObjectFind(name) == -1)
               ObjectCreate(name,OBJ_LABEL,window,0,0,0,0);
                ObjectSet(name,OBJPROP_XDISTANCE,     65);
                ObjectSet(name,OBJPROP_YDISTANCE,i*10+13+gapv*(t/2));
                ObjectSetText(name,cpairsv[i],8,"Arial Bold");
         }                
      }
      
   //
   //
   //
   //
   //      

   for (t = 0; t < ctimesLen;  t++)
   for (i = 0; i < cpairsLenH; i++)
   for (k = 0; k < cpairsLenV; k++)
   {
      string symbol = cpairsh[i]+cpairsv[k]+addition;
      double price  = iClose(symbol,aTimes[t],0);
      bool   normal = true;
      bool   exist  = true;
         
            if (price == 0)
            {
               symbol = cpairsv[k]+cpairsh[i]+addition;
               price  = iClose(symbol,aTimes[t],0);
               normal = false;
            }                  
            if (price == 0) exist = false;

         if (!exist) continue;      
         double close = iClose(symbol,aTimes[t],1);
         double high  = iHigh(symbol,aTimes[t],1);
         double low   = iLow(symbol,aTimes[t],1);
         
      //
      //
      //
      //
      //
       
      color  theColor = DoesNotExist;
         if (!normal)
            while (true)
            {
               if (price > high)  { theColor = StrongUp;   break; }
               if (price > close) { theColor = WeakUp;     break; }
               if (price== close) { theColor = NoMove;     break; }
               if (price < low)   { theColor = StrongDown; break; }
                                    theColor = WeakDown;   break; 
            }
         else               
            while (true)
            {
               if (price > high)  { theColor = StrongDown; break; }
               if (price > close) { theColor = WeakDown;   break; }
               if (price== close) { theColor = NoMove;     break; }
               if (price < low)   { theColor = StrongUp;   break; }
                                    theColor = WeakUp;     break; 
            }
            
            //
            //
            //
            //
            //
            
            name = shortName+t+k+i;
            if (ObjectFind(name) == -1)
                  ObjectCreate(name,OBJ_LABEL,window,0,0,0,0);
                  ObjectSet(name,OBJPROP_XDISTANCE,i*50+100+gaph*(t%2));
                  ObjectSet(name,OBJPROP_YDISTANCE,k*10+ 15+gapv*(t/2));
                  ObjectSetText(name,"ÛÛÛÛÛÛÛÛ",8,FontToUse,theColor);
   }
   return(0);
}

//
//
//
//
//

bool   IsMini()   { return(StringFind(Symbol(),"m") > -1); }
bool   IsDotted() { return(StringFind(Symbol(),"..") > -1); }
string MakeUniqueName(string first, string rest)
{
   string result = first+(MathRand()%1001)+rest;

   while (WindowFind(result)> 0)
          result = first+(MathRand()%1001)+rest;
   return(result);
}

//
//
//
//
//

void clearObjects()
{
   for (int i = ObjectsTotal(); i>=0; i--)
   {
         string name = ObjectName(i);
         if (StringSubstr(name,0,shortLength) == shortName) ObjectDelete(name);
   }         
}

//
//
//
//
//

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;
  return(tf);
}
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="MN";
   }
   return(tfs);
}

//
//
//
//
//

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);
}

//
//
//
//
//

void setUpStrings(string& array[],int& length, string source)
{
   source = StringUpperCase(StringTrimLeft(StringTrimRight(source)));
   if (StringSubstr(source,StringLen(source)-1,1) != ";")
                    source = StringConcatenate(source,";");

   //
   //
   //
   //
   //
   
   int  s = 0;
   int  i = StringFind(source,";",s);
   string current;
      while (i > 0)
      {
         current = StringSubstr(source,s,i-s);
         ArrayResize(array,ArraySize(array)+1);
                     array[ArraySize(array)-1] = current;
                     s = i + 1;
                     i = StringFind(source,";",s);
      }
   length = ArraySize(array);
}





Sample





Analysis



Market Information Used:

Series array that contains close prices for each bar
Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar


Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:

Other Features: