LOCLinePipsHistoryScript

Author: Mikhail LandOfCash
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
0 Views
0 Downloads
0 Favorites
LOCLinePipsHistoryScript
//+---------------------------------------------------------------------+
//|                                              LOCLinePipsHistory.mq4 |
//| For more EXPERTS, INDICATORS, TRAILING EAs and SUPPORT Please visit:|
//|                                      http://www.landofcash.net      |
//|           Our forum is at:   http://forex-forum.landofcash.net      |
//+---------------------------------------------------------------------+
#property copyright "Mikhail LandOfCash"
#property link      "http://www.landofcash.net"

string _verName="LOCLinePipsHistory";
string _ver="v1.1";

extern color _textColor=Crimson;
extern int _sleepTimeMS=50;

bool _isRunning=false;
string _fullName;
string _objPref="LOCLinePipsHistory";


int start()
{
   _fullName=_verName+" "+_ver;
   Print("LandOfCash.net "+_fullName+" Started.");  
   Comment("LandOfCash.net "+_fullName);
   if(!_isRunning){
      Iterate();
   }
   DeleteLabels(_objPref);
   return (0);
}
  

void DoJob(){
   int    obj_total=ObjectsTotal();
   string name;
   DeleteLabels(_objPref);
   bool hasCross=false;
   string value;
   int minuteBar = 0;
   for(int i=0;i<obj_total;i++)
   {
      name=ObjectName(i);        
      if(ObjectType(name)==OBJ_HLINE){
         double price = ObjectGet(name, OBJPROP_PRICE1) ;
         value=DoubleToStr(MathAbs((Bid-price)/Point),0)+" pip";         
         //bar cross
         hasCross=false;
         for(int b=0; b<Bars; b++){
            if(iHigh(Symbol(),Period(),b)>price && iLow(Symbol(),Period(),b)<price){
               if(Period()>1){
                  int endBar=iBarShift(Symbol(),PERIOD_M1,iTime(Symbol(),Period(),b));
                  int startBar=endBar-Period();
                  if(startBar<0){
                     startBar=0;
                  }                  
                  for(minuteBar=startBar; minuteBar<endBar;minuteBar++){
                      if(iHigh(Symbol(),PERIOD_M1,minuteBar)>price && iLow(Symbol(),PERIOD_M1,minuteBar)<price){                        
                        break;
                      }
                  }
               }
               value=value+"|"+b+" bars ("+(MinutesToString(minuteBar))+")";
               hasCross=true;
               break;
            }            
         }
         if(!hasCross){
            value=value+ "| no historic cross.";
         }
         CreateText(_objPref+name,Time[0],price,_textColor,value);
      }      
   }
}


void Iterate() {
   _isRunning=true;
   while(!IsStopped())    
   {              
    RefreshRates();     
    DoJob();
    Sleep(_sleepTimeMS);        
   }
}

void CreateText(string name, datetime time1, double price,color boxcolor, string text){
   ObjectDelete(name);
   if(!ObjectCreate(name, OBJ_TEXT,0, time1, price))
   {
    Print("error: cant create OBJ_TEXT! code #",GetLastError());
    return(0);
   }
   ObjectSetText(name, text, 7, "Verdana", boxcolor);
}
void DeleteLabels(string objPref){
   int    obj_total=ObjectsTotal();
   string name;
   for(int i=0;i<obj_total;i++)
   {
    name=ObjectName(i);    
    if(StringFind(name, objPref,0)>-1){      
      ObjectDelete(name);
      i--;
    }
   }
}

string MinutesToString(int totalMinutes){
   if(totalMinutes>60){
      int hours = totalMinutes/(60);
      int minutes = totalMinutes - hours * 60;
      return (hours+" hours "+minutes+" minutes");
   }
   return (totalMinutes + " minutes");
}
//+------------------------------------------------------------------+

Comments