//+------------------------------------------------------------------+
//|                                      Bemac Clock & Pip Value.mq4 |
//|                                         Copyright © 2010, Bemac. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Bemac."

#property indicator_chart_window

//---- input parameters
extern int     chart_window   = 0;
extern int     corner         = 0;
extern int     xdis           = 5;
extern int     ydis           = 15;
extern string  Font           = "Arial";
extern int     FontSize       = 8;
extern color   FontColor      = Maroon;

string   This_Pair   = "";
string   Second_Curr = "";

string   BS;
string   PVal;
string   Cost;
string   Bemac;
string   InfoValue;
string   InfoSpread;
string   InfoCost;
//-----Pairs.(used to call Last Bid).
double   AudUsd, EurUsd, GbpUsd, NzdUsd, UsdCad, UsdChf, UsdJpy;

//-----Spread & Cost Variables.
double   BEMACSPREAD = 0.0;
double   PipValue    = 0.00;
double   PV          = 0.00;
double   EntCost     = 0.00;
double   mult        = 0.00;



//+------------------------------------------------------------------+
//|           Bemac Pip Value initialization function                |
//+------------------------------------------------------------------+
//----- Begin Initiation
int init()
  {
//-----Last Bid for these Pairs required.  
   AudUsd = MarketInfo("AUDUSD",MODE_BID); EurUsd = MarketInfo("EURUSD",MODE_BID); GbpUsd = MarketInfo("GBPUSD",MODE_BID);
   NzdUsd = MarketInfo("NZDUSD",MODE_BID); UsdCad = MarketInfo("USDCAD",MODE_BID); UsdChf = MarketInfo("USDCHF",MODE_BID);
   UsdJpy = MarketInfo("USDJPY",MODE_BID);
       
   ObjectCreate("Bemacs Spread"  ,  OBJ_LABEL, chart_window, 0, 0);
   ObjectSet   ("Bemacs Spread"  ,  OBJPROP_CORNER, corner);
   ObjectSet   ("Bemacs Spread"  ,  OBJPROP_XDISTANCE, xdis);
   ObjectSet   ("Bemacs Spread"  ,  OBJPROP_YDISTANCE, ydis +  0);
   
   ObjectCreate ("Clock"         ,  OBJ_LABEL, chart_window, 0, 0);
   ObjectSet    ("Clock"         ,  OBJPROP_CORNER, corner);
   ObjectSet    ("Clock"         ,  OBJPROP_XDISTANCE, xdis);
   ObjectSet    ("Clock"         ,  OBJPROP_YDISTANCE, ydis + 10);
         
   ObjectCreate("Full Pip Spread",  OBJ_LABEL, chart_window, 0, 0);
   ObjectSet   ("Full Pip Spread",  OBJPROP_CORNER, corner);
   ObjectSet   ("Full Pip Spread",  OBJPROP_XDISTANCE, xdis);
   ObjectSet   ("Full Pip Spread",  OBJPROP_YDISTANCE, ydis + 20);
   
   ObjectCreate("Full Pip Value" ,  OBJ_LABEL, chart_window, 0, 0);
   ObjectSet   ("Full Pip Value" ,  OBJPROP_CORNER, corner);
   ObjectSet   ("Full Pip Value" ,  OBJPROP_XDISTANCE, xdis);
   ObjectSet   ("Full Pip Value" ,  OBJPROP_YDISTANCE, ydis + 30);

   ObjectCreate("Cost to Enter"  ,  OBJ_LABEL, chart_window, 0, 0);
   ObjectSet   ("Cost to Enter"  ,  OBJPROP_CORNER, corner);
   ObjectSet   ("Cost to Enter"  ,  OBJPROP_XDISTANCE, xdis);
   ObjectSet   ("Cost to Enter"  ,  OBJPROP_YDISTANCE, ydis + 40);
     
//----
   return(0);
  }

int start()
  {
//+------------------------------------------------------------------+
//|Clock Calculation                                                 |
//+------------------------------------------------------------------+
//*****Clock*****
//double   s1[];
string   clock= "";

double   i;
int      h, m, s, k;                
    m = Time[0] + Period()*60 - CurTime();
    s = m % 60;
    i = m / 60.0;
    h = i / 60.0;
    m = i - h * 60;

string hr=DoubleToStr(h,0);    
string mn=DoubleToStr(m,0);
string sc=DoubleToStr(s,0);
//*****Clock*****

//+------------------------------------------------------------------+
//| Bemac Pip Value Calculation                                      |
//+------------------------------------------------------------------+
//*****Pip Value & Cost*****
   if (Digits == 2) mult = 1.00;  
                     
   if (Digits == 3) mult = 0.10;
                     
   if (Digits == 4) mult = 1.00;
                        
   if (Digits == 5) mult = 0.10;
   
//---- Calculate Full Pip Values
   This_Pair   = Symbol();
   Second_Curr = StringSubstr(This_Pair, 3, 3);

   if(Second_Curr=="USD") PipValue = 10.00;
      if(Second_Curr=="JPY") PipValue = 1000/UsdJpy;
         if(Second_Curr=="GBP") PipValue = 10/(1/GbpUsd);
            if(Second_Curr=="CHF") PipValue = 10/UsdChf;
               if(Second_Curr=="CAD") PipValue = 10/UsdCad;
                  if(Second_Curr=="AUD") PipValue = 10/(1/AudUsd);
                     if(Second_Curr=="NZD") PipValue = 10/(1/NzdUsd);
                     
   PV =  PipValue;                                            
//----
    BEMACSPREAD = (Ask-Bid)/MarketInfo(Symbol(),MODE_POINT)*mult;           
    EntCost     = PipValue*BEMACSPREAD;
    
    BS          = DoubleToStr(BEMACSPREAD,1);
    PVal        = DoubleToStr(PV,2);
    Cost        = DoubleToStr(EntCost,2);
    
   Bemac        = "|---------------Bemac Entry Calcs---------------|";
   if(BEMACSPREAD<10.0)
   InfoSpread   = "|Full Pip Spread___________:     P "      + BS + "     |";
      else
      InfoSpread   = "|Full Pip Spread___________:   P"      + BS + "    |";
      
   InfoCost     = "|Cost to Enter     __"+This_Pair+"__:US $"+ Cost + "  |";

   if(PipValue<10.0)  
    InfoValue    = "|Full Pip $Value___________:US $ " + PVal + "  |";
      else 
    InfoValue    = "|Full Pip $Value___________:US $"  + PVal + "   |";

   ObjectSetText("Bemacs Spread"   , Bemac     , FontSize, Font, FontColor);
   ObjectSetText("Full Pip Spread" , InfoSpread, FontSize, Font, FontColor);
   ObjectSetText("Full Pip Value"  , InfoValue , FontSize, Font, FontColor);
   ObjectSetText("Cost to Enter"   , InfoCost  , FontSize, Font, FontColor);
   ObjectSetText("Clock" , "|" + hr +" Hrs "+ mn + " minutes " + sc + " seconds till bar ends   |", FontSize, Font, FontColor);
//----
   return(0);
  }
int deinit()
{
ObjectDelete("Bemacs Spread"  );
ObjectDelete("Full Pip Spread");
ObjectDelete("Full Pip Value" );
ObjectDelete("Cost to Enter"  );
ObjectDelete("Clock"  );
return(0);
}  
//+------------------------------------------------------------------+