
//------------------------------------------------------------------
#property copyright "www.forex-tsd.com"
#property link      "www.forex-tsd.com"
//------------------------------------------------------------------

//
//
//
//
//

#include <stdlib.mqh>

//
//
//
//
//  

#import "kernel32.dll"
int  GetTimeZoneInformation(int& TZInfoArray[]);
#import

//
//
//
//
//

#define TIME_ZONE_ID_UNKNOWN   0
#define TIME_ZONE_ID_STANDARD  1
#define TIME_ZONE_ID_DAYLIGHT  2

//
//
//
//
//

extern string ExpertName             = "XO Ea";
extern string Version                = "v2";
extern string _gen                   = "General Settings";
extern bool   EcnBroker              = true;
extern bool   UseAutoMagic           = true;
extern int    ManualMagic            = 82828282;  
extern double lStopLoss              = 100;
extern double sStopLoss              = 100;
extern double lTakeProfit            = 100;
extern double sTakeProfit            = 100;
extern double lTrailingStop          = 10;
extern double sTrailingStop          = 10;
extern int    Slippage               = 4;
extern double Lots                   = 0.1;
extern double MaximumRisk            = 0;
extern double DecreaseFactor         = 3;

extern double BoxSize                = 34;
extern int    xoBars                 = 1;

extern bool   UseXOClose             = false;
extern double clBoxSize              = 34;
extern int    clxoBars               = 1;

extern string tf                     = "Time Filter";
extern bool   UseHourTrade           = true;
extern int    StartHour              = 3;
extern int    StartMinute            = 0;
extern int    EndHour                = 22;
extern int    EndMinute              = 0;

extern string __                     = "Setting for friday positions close";
extern bool   CloseOnFriday          = false;
extern int    FridayCloseHour        = 21; 
extern int    FridayCloseMinute      = 59; 

extern string os                     = "Other Stuff";
extern bool   ShowAlerts             = false;
extern bool   ShowComments           = true;   
extern color  clOpenBuy              = Blue;
extern color  clCloseBuy             = Aqua;
extern color  clOpenSell             = Red;
extern color  clCloseSell            = Violet;

//
//
//
//
//

double   pipMultiplier = 1;
double   pPoint;

string   s_symbol;

bool     dummyResult;

int      MAGIC;
int      digit;
int      TZInfoArray[43];

//
//
//
//
//

int init() 
{
   s_symbol = Symbol();
   pPoint   = MarketInfo(s_symbol,MODE_POINT);
   digit    = MarketInfo(s_symbol,MODE_DIGITS);
   if (digit==2 || digit==4) pipMultiplier = 1;
   if (digit==3 || digit==5) pipMultiplier = 10;
   if (digit==6)             pipMultiplier = 100;
   
   //
   //
   //
   //
   //
   
   if (UseAutoMagic) MAGIC = GetMagic();
               else  MAGIC = ManualMagic;    
                 
return(0);
}

//
//
//
//
//

int deinit() 
{ 
   Comment("");
   
return(0); 
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//

int start()
{
   if (lTrailingStop > 0) TrailingPositionsBuy();
   if (sTrailingStop > 0) TrailingPositionsSell();
   if (UseXOClose)        CheckForClose();
   if (ShowComments)      ChartComment();    
   
   //
   //
   //
   //
   //
   
   if (CloseOnFriday && TimeDayOfWeek(TimeCurrent())==5)
   {
     if (TimeHour(TimeCurrent()) > FridayCloseHour ||
        (TimeHour(TimeCurrent())== FridayCloseHour && TimeMinute(TimeCurrent())>= FridayCloseMinute))
     {
       for(int i=OrdersTotal()-1; i>=0; i--)
  	    { 
     	   dummyResult = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
            if(OrderSymbol()     != s_symbol)    continue;
            if(OrderMagicNumber()!= MAGIC)       continue;

            if(OrderType()==OP_BUY)  { dummyResult = OrderClose(OrderTicket(),OrderLots(),MarketInfo(s_symbol,MODE_ASK),0,CLR_NONE); continue; }
            if(OrderType()==OP_SELL) { dummyResult = OrderClose(OrderTicket(),OrderLots(),MarketInfo(s_symbol,MODE_BID),0,CLR_NONE); continue; }
       }
       return(0);
     }
   }
   
   //
   //
   //
   //
   //
   
   int openedOrders = 0;
   for (i=OrdersTotal()-1; i>=0; i--)
   { 
      dummyResult = OrderSelect(i, SELECT_BY_POS,MODE_TRADES);
         if (OrderSymbol()      != s_symbol) continue;
         if (OrderMagicNumber() != MAGIC)    continue;
           openedOrders++;
   }
   
   //
   //
   //
   //
   //
   
   if (openedOrders <= 0)
   {
     int trendCurr = iCustom(s_symbol,0,"XO",BoxSize,4,xoBars  );
     int trendPrev = iCustom(s_symbol,0,"XO",BoxSize,4,xoBars+1);
     
     if (trendCurr > 0 && trendPrev < 0)
     {
        OpenBuy();
        return(0);
     }
     
     if (trendCurr < 0 && trendPrev > 0)
     {
        OpenSell();
        return(0);
     }
      
   
   }
   
  //
  //
  //
  //
  //
  
  if (UseHourTrade)
  {
    if(!checkTimeLimits(StartHour,StartMinute,0,EndHour,EndMinute,0,TimeCurrent())) {  return(0);  }
  }
return (0);
}

//
//
//
//
//

bool checkTimeLimits(uint startHour, uint startMinute, uint startSecond, uint endHour, uint endMinute, uint endSecond, datetime timeToCheck)
{
   bool answer = false;
   MqlDateTime tempTime; TimeToStruct(timeToCheck,tempTime);
      datetime startTime,endTime,checkTime;
               startTime = _ctMinMax(startHour,0,24)    *3600+_ctMinMax(startMinute,0,60) *60+_ctMinMax(startSecond,0,60);
               endTime   = _ctMinMax(endHour,0,24)      *3600+_ctMinMax(endMinute,0,60)   *60+_ctMinMax(endSecond,0,60);
               checkTime = _ctMinMax(tempTime.hour,0,24)*3600+_ctMinMax(tempTime.min,0,60)*60+_ctMinMax(tempTime.sec,0,60);
               
   if (startTime>endTime)
          answer = (checkTime>=startTime || checkTime<=endTime);
   else   answer = (checkTime>=startTime && checkTime<=endTime);
   return(answer);
}
uint _ctMinMax(uint value, uint min, uint max) { return((uint)MathMax(MathMin(value,max),min)); }

//
//
//
//
//

void TrailingPositionsBuy() { 
   double pBid = Bid; 
   for (int i = OrdersTotal()-1; i >=0 ; i--) { 
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { 
         if (OrderSymbol() == s_symbol && OrderMagicNumber() == MAGIC) { 
            if (OrderType() == OP_BUY) { 
                if (pBid - OrderOpenPrice()   > lTrailingStop * pPoint * pipMultiplier) { 
                  if (OrderStopLoss() < pBid  - lTrailingStop * pPoint * pipMultiplier) 
                      ModifyStopLoss(   pBid  - lTrailingStop * pPoint * pipMultiplier); 
               } 
            } 
         } 
      } 
   } 
}

//
//
//
//
//
 
void TrailingPositionsSell() { 
   double pAsk = Ask; 
   for (int i = 0; i < OrdersTotal(); i++) { 
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { 
         if (OrderSymbol() == s_symbol && OrderMagicNumber() == MAGIC) { 
            if (OrderType() == OP_SELL) { 
                if (OrderOpenPrice()  - pAsk > sTrailingStop * pPoint * pipMultiplier) { 
                  if (OrderStopLoss() > pAsk + sTrailingStop * pPoint * pipMultiplier || OrderStopLoss() == 0)  
                      ModifyStopLoss(   pAsk + sTrailingStop * pPoint * pipMultiplier); 
               } 
            } 
         } 
      } 
   } 
}

//
//
//
//
//
 
void ModifyStopLoss(double ldStopLoss) 
{ 
   bool fm;
   double minStop = 0;
   double pBid    = Bid;
   double pAsk    = Ask;
   double sl      = MarketInfo(s_symbol,MODE_STOPLEVEL);   
   bool   canGo   = false;
      if (OrderType()==OP_BUY)
            { minStop = pBid-sl*pPoint; canGo = ldStopLoss<=minStop; }
      else  { minStop = pAsk+sl*pPoint; canGo = ldStopLoss>=minStop; }
      if (canGo)
      {
        fm = OrderModify(OrderTicket(),NormalizeDouble(OrderOpenPrice(),digit),NormalizeDouble(ldStopLoss,digit),NormalizeDouble(OrderTakeProfit(),digit),0,CLR_NONE); 
        if (fm == false)
        {
	        int    ErrorCode = GetLastError();
	        string ErrDesc   = ErrorDescription(ErrorCode);
	        string ErrAlert  = StringConcatenate("Trailing Stop Modification - Error ",ErrorCode,": ",ErrDesc);
   	        if (ShowAlerts   == true) Alert(ErrAlert);
            	  string ErrLog = StringConcatenate("Ask: ",MarketInfo(s_symbol,MODE_ASK)," Ticket: ",OrderTicket()," Stop: ",OrderStopLoss()," Trail: ",ldStopLoss);
      	  Print(ErrLog);
      	}
      }      	
      else Print("Stop loss to close to current price");

}  

//
//
//
//
//

void OpenBuy() 
{ 
    
   double lbStop = 0; if (lStopLoss>0)   lbStop = NormalizeDouble(MarketInfo(s_symbol,MODE_ASK)-lStopLoss  *pPoint*pipMultiplier,digit);
   double lbTake = 0; if (lTakeProfit>0) lbTake = NormalizeDouble(MarketInfo(s_symbol,MODE_ASK)+lTakeProfit*pPoint*pipMultiplier,digit);
   
   if (AccountFreeMargin() < (100 * Lots)) { Print("We have no money. Free Margin = ", AccountFreeMargin()); return; }
   
   //
   //
   //
   //
   //
   
   if (!EcnBroker) 
         dummyResult = OrderSend(s_symbol,OP_BUY,LotsOptimized(),MarketInfo(s_symbol,MODE_ASK),Slippage*pipMultiplier,lbStop,lbTake,ExpertName,MAGIC,0,clOpenBuy); 
   else
   {
         int buyTicket    = OrderSend(s_symbol,OP_BUY,LotsOptimized(),MarketInfo(s_symbol,MODE_ASK),Slippage*pipMultiplier,0,0,ExpertName,MAGIC,0,clOpenBuy);		    		    
         if (buyTicket   >= 0)
         bool buyOrderMod = OrderModify(buyTicket,OrderOpenPrice(),lbStop,lbTake,0,CLR_NONE);
         
         if (buyOrderMod  == false)
         {
         
           int    ErrorCode = GetLastError();
           string ErrDesc   = ErrorDescription(ErrorCode);

           string ErrAlert  = StringConcatenate("Modify Buy Order - Error ",ErrorCode,": ",ErrDesc);
           if (ShowAlerts   == true) Alert(ErrAlert);

           string ErrLog    = StringConcatenate("Ask: ",MarketInfo(s_symbol,MODE_ASK)," Bid: ",MarketInfo(s_symbol,MODE_BID)," Ticket: ",buyTicket," Stop: ",lbStop," Profit: ",lbTake);
           Print(ErrLog);
         }
    }		       

}

//
//
//
//
//

void OpenSell() 
{ 

   double lsStop = 0; if (sStopLoss>0)   lsStop = NormalizeDouble(MarketInfo(s_symbol,MODE_BID)+sStopLoss  *pPoint*pipMultiplier,digit);
   double lsTake = 0; if (sTakeProfit>0) lsTake = NormalizeDouble(MarketInfo(s_symbol,MODE_BID)-sTakeProfit*pPoint*pipMultiplier,digit);
  
   if (AccountFreeMargin() < (100 * Lots)) { Print("We have no money. Free Margin = ", AccountFreeMargin()); return; }
   
   //
   //
   //
   //
   //
   
   if (!EcnBroker)
         dummyResult = OrderSend(s_symbol,OP_SELL,LotsOptimized(),MarketInfo(s_symbol,MODE_BID),Slippage*pipMultiplier,lsStop,lsTake,ExpertName,MAGIC,0,clOpenSell); 
   else
   {
         int sellTicket    = OrderSend(s_symbol,OP_SELL,LotsOptimized(),MarketInfo(s_symbol,MODE_BID),Slippage*pipMultiplier,0,0,ExpertName,MAGIC,0,clOpenSell);		    		    
         if (sellTicket    >= 0)
         bool sellOrderMod = OrderModify(sellTicket,OrderOpenPrice(),lsStop,lsTake,0,CLR_NONE);
         
         if (sellOrderMod  == false)
         {
           int    ErrorCode = GetLastError();
           string ErrDesc   = ErrorDescription(ErrorCode);

           string ErrAlert  = StringConcatenate("Modify Sell Order - Error ",ErrorCode,": ",ErrDesc);
           if (ShowAlerts   == true) Alert(ErrAlert);

           string ErrLog    = StringConcatenate("Ask: ",MarketInfo(s_symbol,MODE_ASK)," Bid: ",MarketInfo(s_symbol,MODE_BID)," Ticket: ",sellTicket," Stop: ",lsStop," Profit: ",lsTake);
           Print(ErrLog);
          }
    }		       
} 


//
//
//
//
//

void CheckForClose()  
{
   RefreshRates();
   int cltrendCurr = iCustom(s_symbol,0,"XO",clBoxSize,4,clxoBars  );
   int cltrendPrev = iCustom(s_symbol,0,"XO",clBoxSize,4,clxoBars+1);
   
   //
   //
   //
   //
   //
   
   for (int i = 0;i < OrdersTotal(); i++)
   {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false)  break;
      if (OrderMagicNumber()!= MAGIC)                         continue;
      if (OrderSymbol()     != s_symbol)                      continue;
      
      //
      //
      //
      //
      //
      
      if (OrderType() == OP_BUY)
      {
        if (cltrendCurr < 0 && cltrendPrev > 0) 
        {
           bool buyClose = OrderClose(OrderTicket(),OrderLots(),MarketInfo(s_symbol,MODE_BID),Slippage*pipMultiplier,clCloseBuy);
           if (buyClose == false)
           {
             int ErrorCode   = GetLastError();
             string ErrDesc  = ErrorDescription(ErrorCode);

             string ErrAlert = StringConcatenate("Close Buy Order - Error ",ErrorCode,": ",ErrDesc);
             if (ShowAlerts  == true) Alert(ErrAlert);

             string ErrLog   = StringConcatenate("Bid: ",MarketInfo(s_symbol,MODE_BID)," Lots: ",OrderLots(), " Ticket: ",OrderTicket());
             Print(ErrLog);
           }
        }
        break;
      }
      
      
      //
      //
      //
      //
      //
        
      if (OrderType() == OP_SELL)
      {
        if (cltrendCurr > 0 && cltrendPrev < 0) 
        {
          bool sellClose = OrderClose(OrderTicket(),OrderLots(),Ask,Slippage*pipMultiplier,clCloseSell); 
          if (sellClose  == false)
          {
             ErrorCode = GetLastError();
             ErrDesc   = ErrorDescription(ErrorCode);

             ErrAlert  = StringConcatenate("Close Sell Order - Error ",ErrorCode,": ",ErrDesc);
             if (ShowAlerts == true) Alert(ErrAlert);

             ErrLog   = StringConcatenate("Ask: ",Ask," Lots: ",OrderLots(), " Ticket: ",OrderTicket());
             Print(ErrLog);
          }
        }
        break;
      }
   }
}

//
//
//
//
//

double LotsOptimized()
{
   double lot_min  = MarketInfo(s_symbol,MODE_MINLOT);
   double lot_max  = MarketInfo(s_symbol,MODE_MAXLOT);
   double lot_step = MarketInfo(s_symbol,MODE_LOTSTEP);
   double contract = MarketInfo(s_symbol,MODE_LOTSIZE);
   double lot      = Lots;
   int    orders   = HistoryTotal();     // history orders total
   int    losses   = 0;                  // number of losses orders without a break
   
   //
   //
   //
   //
   //
   
   if(lot_min < 0.0 || lot_max <= 0.0 || lot_step <= 0.0) 
   {
   Print("CalculateVolume: invalid MarketInfo() results [",lot_min,",",lot_max,",",lot_step,"]");
   return(0);
   }
   if(AccountLeverage()<=0)
   {
   Print("CalculateVolume: invalid AccountLeverage() [",AccountLeverage(),"]");
   return(0);
   }
   
   //
   //
   //
   //
   //
   
   if (MaximumRisk > 0)
   {
   lot = NormalizeDouble(AccountFreeMargin() * MaximumRisk * AccountLeverage()/contract,2);
   }
   
   if(DecreaseFactor>0)
   {
      for(int i=orders-1;i>=0;i--)
      {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; }
      if(OrderSymbol()!= s_symbol || OrderType() > OP_SELL) continue;
      
      //
      //
      //
      //
      //
      
      if(OrderProfit() > 0) break;
      if(OrderProfit() < 0) losses++;
      }
   if(losses>1) lot=NormalizeDouble(lot - lot * losses/DecreaseFactor,2);
   }
   
   //
   //
   //
   //
   //
   
   lot=NormalizeDouble(lot/lot_step,0)*lot_step;
   if(lot<lot_min) lot=lot_min;
   if(lot>lot_max) lot=lot_max;
   
return(lot);
} 

//
//
//
//
//

int GetMagic() 
{
   if (StringFind(s_symbol, "CADJPY") >= 0) return(9822221);
   if (StringFind(s_symbol, "CADCHF") >= 0) return(9822222);
   
   if (StringFind(s_symbol, "XAUUSD") >= 0) return(9822231);
   if (StringFind(s_symbol, "XAGUSD") >= 0) return(982232);
   
   if (StringFind(s_symbol, "NZDJPY") >= 0) return(9822241);
   if (StringFind(s_symbol, "NZDUSD") >= 0) return(9822242);
   
   if (StringFind(s_symbol, "CHFJPY") >= 0) return(9822251);
   
   if (StringFind(s_symbol, "EURAUD") >= 0) return(9822261);
   if (StringFind(s_symbol, "EURCAD") >= 0) return(9822262);
   if (StringFind(s_symbol, "EURUSD") >= 0) return(9822263);
   if (StringFind(s_symbol, "EURGBP") >= 0) return(9822264);
   if (StringFind(s_symbol, "EURCHF") >= 0) return(9822265);
   if (StringFind(s_symbol, "EURNZD") >= 0) return(9822266);
   if (StringFind(s_symbol, "EURJPY") >= 0) return(9822267);
   if (StringFind(s_symbol, "EURDKK") >= 0) return(9822268);
   
   if (StringFind(s_symbol, "GBPUSD") >= 0) return(9822271);
   if (StringFind(s_symbol, "GBPCHF") >= 0) return(9822272);
   if (StringFind(s_symbol, "GBPJPY") >= 0) return(9822273);
   if (StringFind(s_symbol, "GBPNZD") >= 0) return(9822274);
   if (StringFind(s_symbol, "GBPCAD") >= 0) return(9822275);
   
   if (StringFind(s_symbol, "USDCHF") >= 0) return(9822281);
   if (StringFind(s_symbol, "USDJPY") >= 0) return(9822282);
   if (StringFind(s_symbol, "USDCAD") >= 0) return(9822283);
   if (StringFind(s_symbol, "USDDKK") >= 0) return(9822284);

   if (StringFind(s_symbol, "AUDUSD") >= 0) return(9822291);
   if (StringFind(s_symbol, "AUDNZD") >= 0) return(9822292);
   if (StringFind(s_symbol, "AUDCAD") >= 0) return(9822293);
   if (StringFind(s_symbol, "AUDCHF") >= 0) return(9822294);
   if (StringFind(s_symbol, "AUDJPY") >= 0) return(9822295);
   
return(ManualMagic);
}

//
//
//
//
//

double TimeZoneLocal()
{     
	   switch(GetTimeZoneInformation(TZInfoArray))
	   {
	        case TIME_ZONE_ID_UNKNOWN: 
	        Print("Error obtaining PC timezone from GetTimeZoneInformation in kernel32.dll. Returning 0");
		     return(0);

	        case TIME_ZONE_ID_STANDARD:
		     return(TZInfoArray[0]/(-60.0));
	
	        case TIME_ZONE_ID_DAYLIGHT:
		     return((TZInfoArray[0]+TZInfoArray[42])/(-60.0));
		
 	        default:
		     Print("Unkown return value from GetTimeZoneInformation in kernel32.dll. Returning 0");
		     return(0);
	   }
}

// 
//
//
//
//

double TimeZoneServer()
{
	int ServerToLocalDiffMinutes = (TimeCurrent()-TimeLocal())/60;
	int nHalfHourDiff            = MathRound(ServerToLocalDiffMinutes/30.0);
	
	//
	//
	//
	//
	//
	
	ServerToLocalDiffMinutes = nHalfHourDiff*30;
	
return(TimeZoneLocal() + ServerToLocalDiffMinutes/60.0);
}

// 
//
//
//
//

datetime iTimeGMT()
{

	    datetime dtGmtFromLocal  = TimeLocal()   - TimeZoneLocal()*3600;
	    datetime dtGmtFromServer = TimeCurrent() - TimeZoneServer()*3600;

       if (dtGmtFromLocal > dtGmtFromServer + 300)
	    {
		   return(dtGmtFromLocal);
	    }
	    else
	    {
return(dtGmtFromServer);
	}	
}

//
//
//
//
//

void ChartComment()
{
   RefreshRates();
   if (IsTesting() && !IsVisualMode()) return;
   if (IsTesting()) return;
   
   string symbol   = Symbol(); if (StringSubstr(symbol,0,2)=="_t") symbol = StringSubstr(symbol,2);
  	double modifier = 1;
  	int    digits   = MarketInfo(symbol,MODE_DIGITS);
   if (digits==3 || digits==5) modifier = 10.0;
   
   //
  	//
  	//
  	//
  	//
   
   if(MarketInfo(symbol,MODE_SWAPLONG) > 0)                                string    swap="longs,";
                                                                           else      swap="shorts.";
   if(MarketInfo(symbol,MODE_SWAPLONG) < 0 && MarketInfo(symbol,MODE_SWAPSHORT) < 0) swap="your broker. ";
   
   //
   //
   //
   //
   //
   
   string strLocal  = TimeToStr(TimeLocal(),TIME_DATE|TIME_MINUTES|TIME_SECONDS);
	string strServer = TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES|TIME_SECONDS);
	string strGMT    = TimeToStr(TimeGMT(),TIME_DATE|TIME_MINUTES|TIME_SECONDS);
	
	string strLocalTimeZone;
	if (TimeZoneLocal() >  0)  strLocalTimeZone  = StringConcatenate("Local timezone: GMT plus  ", TimeZoneLocal()," hours");
	if (TimeZoneLocal() == 0)  strLocalTimeZone  = "Local timezone: GMT";
	if (TimeZoneLocal() <  0)  strLocalTimeZone  = StringConcatenate("Local timezone: GMT minus ",-TimeZoneLocal()," hours");
	
	string strServerTimeZone;
	if (TimeZoneServer() >  0) strServerTimeZone = StringConcatenate("Server timezone: GMT plus  ", TimeZoneServer()," hours");
	if (TimeZoneServer() == 0) strServerTimeZone = "Server timezone: GMT";
  	if (TimeZoneServer() <  0) strServerTimeZone = StringConcatenate("Server timezone: GMT minus ",-TimeZoneServer()," hours");
   
   //
   //
   //
   //
   //
   
   string sComment   = "";
   string sp         = "------------------------------------------------------------\n";
   string NL         = "\n";
   
   sComment = sComment + sp;
   sComment = sComment+ "Expert Name : "+ExpertName+NL;
   sComment = sComment+ "EA Version  : "+Version+NL;
   sComment = sComment+ sp;
   sComment = sComment+ "Market Analysis" + NL;
   sComment = sComment+ "Swap favors " + swap + NL; 
   sComment = sComment+ "Swap Long      = " + DoubleToStr(MarketInfo(symbol,MODE_SWAPLONG),2) + NL; 
   sComment = sComment+ "Swap Short     = " + DoubleToStr(MarketInfo(symbol,MODE_SWAPSHORT),2) + NL; 
   sComment = sComment+ "Current Spread = " + DoubleToStr(MarketInfo(symbol,MODE_SPREAD)/ modifier,2) + NL; 
   sComment = sComment+ sp;
   sComment = sComment+ "Time Information" + NL;
   sComment = sComment+ strLocalTimeZone  + NL;
   sComment = sComment+ strServerTimeZone + NL;
   sComment = sComment+ "PC Local Time = " +strLocal+ NL;
   sComment = sComment+ "Broker Server Time =  " +strServer+ NL;
   sComment = sComment+ "GMT Time =  " +strGMT+ NL;
   sComment = sComment+ sp;
   sComment = sComment+ "Have a great trading day" + NL;
   sComment = sComment+ sp; 
   
Comment(sComment);
}







