Navigation:Home > Content >

MNS_V3.02(Mod_1.1.5a).mq4

Time: 2013-07-27 | Download file:MNS_V3.02(Mod_1.1.5a).mq4

////////////////////////////////////////////////////////
//     Momods_Night_Scalper_V3.02_Basic_MMfix         //
//     Coded by Momods @ worldwide-invest.org         //
////////////////////////////////////////////////////////
//        If you make money from this EA              //
//  please make donnation to my paypal Account        //
//              [email protected]                    //
////////////////////////////////////////////////////////
//=================================================================================================================================================//
#property copyright "Copyright © 2013, Momods"
#property link      "http://worldwide-invest.org/"

#import "Kernel32.dll"
void GetSystemTime(int& TimeArray[]);
#import
//=================================================================================================================================================//
extern bool UseVolatilityFilter = false;
extern double LimitVolatility = 10;
extern string S0="-------General Sets-------";
extern string EA_Comment="";     
extern string S_1="If MAGIC=0, a unique value will be generated by EA";  
extern bool   SendMailInfo        = false;   
extern int    MAGIC               = 0;
extern bool   New_Trade           = True;
extern int    Slippage            = 3;
extern string S1="-------Lot and Risk-------";
extern double lot                 = 0;
extern double Risk                = 7.5;
extern string S2="-------Spread Limits-------";
extern string C0=" If Max_Spread = 0, EA will use internal settings";
extern double Max_Spread_Open     = 0.0;
extern double Max_Spread_Close    = 0.0;
extern string S3="-------Times and Days-------";
extern int    GMT_Offset          = 99;
extern int    DelaySessionMinutes = 0;
extern bool   TradeOnFriday       = False;
extern int    Friday_Hour         =15;
extern string S4="-------ATR and PriceLevel Filter-------";
extern bool   UseATRfilter        = false;
extern int    Atr_Period          = 14;
extern string TypeATRfilterStr    = "1=Lower Level, 2=Higher Level";
extern int    Type_ATR_level      = 1;        
extern double AtrLevel            = 0.0006;
extern bool   UsePriceLevelFilter = true;
extern int    PrvHoursCheck1      = 6;
extern int    PrvHoursCheck2      = 7;
extern double LevelsDistance      = 2;
extern string S5="-------News Filter-------";
extern bool   AvoidNews           = False;
extern string NewsImpact          = "3=High; 2=Medium; 1=Low";
extern int    MinimumImpact       = 1;
extern int    MinsBeforeNews      = 30;
extern int    MinsAfterNews       = 30;
extern string S6="-------Manage Loss Trade-------";
extern bool   Trade_Pause_On_Loss = false;
extern string P="Puase type: 1=Use Minutes, 2=Use Pips";
extern int    Pause_Type          = 1;
extern int    Trade_Pause_Minutes = 60;
extern double Trade_Pause_Pips    = 20;
extern string S7="-------Second Trade-------";
extern bool   Allow_Second_Trade  = false;
extern double Distance            = 12;
extern double Lot_Factor          = 0.5;
extern string InfoSets="!!! Below this line works sets if UseAutoSets=false !!!";
extern bool   UseAutoSets         = true;
extern string S8="-------TakeProfit and StopLoss-------";
extern bool   Hide_SL_TP          = False;
extern double TakeProfit          = 60;
extern double StopLoss            = 50;
extern string S9="-------Hours Limits-------";
extern int    Open_Hour           = 20;
extern int    Close_Hour          = 23;
extern string S10="-------CCI Sets-------";
extern bool   Use_CCI             = False;
extern int    CCI_Period          = 10;
extern double CCI_Entry           = 200;
extern double CCI_Exit            = 140;
extern string S11="-------WPR Sets-------";
extern bool   Use_WPR             = true;
extern int    WPR_Period          = 10;
extern double WPR_Entry           = 91;
extern double WPR_Exit            = 40;
extern string S12="-------RSI Sets-------";
extern bool   Use_RSI             = false;
extern int    RSI_Period          = 70;
extern double RSI_Entry           = 50;
extern string S13="-------Fractals Sets-------";
extern bool   Use_Fractals        = true;
extern double MidFractalDist      = 5;
extern double OppositFractalDist  = 10;
extern bool   Show_Fractal_Levels = False;
extern string S14="-------MA Sets-------";
extern bool   Use_MA_Dist         = false;
extern double MA_Dist_Period      = 4;
extern string Mode="0= Simple, 1=Exponential, 2=Smoothed, 3=Linear Weighted";
extern double MA_Dist_Mode        = 1;
extern double Dist_to_MA          = 4;
extern string S15="-------MA1 Sets-------";
extern bool   Use_MA1             = False;
extern int    MA_Period1          = 75;
extern string Mode1="0= Simple, 1=Exponential, 2=Smoothed, 3=Linear Weighted";
extern int    MA_Mode1            = 2;
extern string S16="-------MA2 Sets-------";
extern bool   Use_MA2             = False;
extern int    MA_Period2          = 19;
extern string Mode2="0= Simple, 1=Exponential, 2=Smoothed, 3=Linear Weighted";
extern int    MA_Mode2            = 2;
extern string S17="-------MA2 Slope Sets-------";
extern bool   Use_MA2_Slope       = False;
extern double MA_Slope            = 1;
extern string S18="-------BB Sets-------";
extern bool   Use_BB              = False;
extern int    BB_Period           = 10;
extern int    BB_Dev              = 2;
extern int    BB_Range            = 12;
extern int    BB_Penetration      = 2;
extern bool   Use_BB_Direction    = False;
//=================================================================================================================================================//
bool Trade;
datetime Last_Time;
double Lot;
double LastUpFractal,LastDownFractal;
double midFractal;
int SpreadSampleSize = 10;  
double Spread[0];
string Session="";
int Magic;
int CCI_Buy_Sig;
int CCI_Sell_Sig;
int WPR_Buy_Sig;
int WPR_Sell_Sig;
int MA_Buy_Sig1;
int MA_Sell_Sig1;
int MA_Buy_Sig2;
int MA_Sell_Sig2;
int Fractals_Buy_Sig;
int Fractals_Sell_Sig;  
int CCI_Exit_Buy_Sig;
int CCI_Exit_Sell_Sig;
int WPR_Exit_Buy_Sig;
int WPR_Exit_Sell_Sig; 
int MA_Slope_Buy_Sig;               
int MA_Slope_Sell_Sig;
int BB_Buy_Sig;               
int BB_Sell_Sig;
int Trade_Pause_Buy_Sig;
int Trade_Pause_Sell_Sig;
int MA_Dist_Buy_Sig;               
int MA_Dist_Sell_Sig;
int RSI_Buy_Sig;
int RSI_Sell_Sig;
//--------------------------
double CCI_1,WPR_1, MA_1_1, MA_1_2,MA_2_1,MA_2_2,BB_U_1,BB_U_2,BB_U_3,BB_L_1,BB_L_2,BB_L_3,MA_3_1, RSI_1; 
//--------------------------
int FilterATR;
int TotalOpenOrders;
int LastOpenType;
int LastClosedType;
int LastClosedTime;
int MultiplierDigit;
double PointsDec;
double LastBuyPrice;
double LastSellPrice;
double SumProfit;
double NetProfit;
double HistoryProfits;
double LastClosedProfit;
double LastClosedPrice;
string EA_Name;
int DSTprv=0;
int DSTcur=0;
int DSTextern=0;
int StarHour=0;
int EndHour=0;
//=================================================================================================================================================//
int init()
{
  EA_Name=WindowExpertName();
  //-----------------------------------------------------------------
  //digits points
  PointsDec=Point;
  MultiplierDigit=1;
  if (MarketInfo(Symbol(), MODE_DIGITS) == 5.0 || MarketInfo(Symbol(), MODE_DIGITS) == 3.0) MultiplierDigit=10;
  PointsDec*=MultiplierDigit;
  Slippage*=MultiplierDigit;
  //-----------------------------------------------------------------
  //Background
  if(!IsTesting() && !IsOptimization())
  {
  if(ObjectFind("Background1")==-1)
  {
  ObjectCreate("Background1",OBJ_LABEL,0,0,0);
  ObjectSet("Background1",OBJPROP_CORNER,0);
  ObjectSet("Background1",OBJPROP_BACK,FALSE);
  ObjectSet("Background1",OBJPROP_YDISTANCE,18);
  ObjectSet("Background1",OBJPROP_XDISTANCE,0);
  ObjectSetText("Background1","g",125,"Webdings",Black);
  }
  //---
  if(ObjectFind("Background2")==-1)
  {
  ObjectCreate("Background2",OBJ_LABEL,0,0,0);
  ObjectSet("Background2",OBJPROP_CORNER,0);
  ObjectSet("Background2",OBJPROP_BACK,FALSE);
  ObjectSet("Background2",OBJPROP_YDISTANCE,180);
  ObjectSet("Background2",OBJPROP_XDISTANCE,0);
  ObjectSetText("Background2","g",125,"Webdings",Black);
  }
  }
  //-----------------------------------------------------------------
  //Set Magic Number
  if (MAGIC==0) MAGIC=MathFloor(AccountNumber()/57431)*100;
  if (MAGIC>0) MAGIC=MAGIC*100;
  //-----------------------------------------------------------------
  //Auto Sets
  if (StringSubstr(Symbol(),0,6)=="EURCAD")
  {
  if(Max_Spread_Open==0)Max_Spread_Open=6;if(Max_Spread_Close==0)Max_Spread_Close=6;
  if(UseAutoSets==true)
  {
  StopLoss= 60;Open_Hour= 20;Close_Hour=23;Use_CCI= true;CCI_Period=10;CCI_Entry=100;CCI_Exit=120;Use_WPR=true;WPR_Period=10;WPR_Entry=91;WPR_Exit=40;
  Use_Fractals=true;MidFractalDist=6;OppositFractalDist=11;Use_MA1=False;MA_Period1=25;Use_MA2_Slope=False;MA_Slope= 5;
  }
  }
  //---
  if (StringSubstr(Symbol(),0,6)=="EURGBP")
  {
  if(Max_Spread_Open==0)Max_Spread_Open=4;if(Max_Spread_Close==0)Max_Spread_Close=4;
  if(UseAutoSets==true)
  {
  StopLoss= 60;Open_Hour= 20;Close_Hour=23;Use_CCI= true;CCI_Period=10;CCI_Entry=100;CCI_Exit=120;Use_WPR=true;WPR_Period=11;WPR_Entry=90;WPR_Exit=40;
  Use_Fractals=true;MidFractalDist=5;OppositFractalDist=9;Use_MA1=False;MA_Period1=25;Use_MA2_Slope=False;MA_Slope= 5;
  }
  }
  //---
  if (StringSubstr(Symbol(),0,6)=="USDCAD")
  {
  if(Max_Spread_Open==0)Max_Spread_Open=4;if(Max_Spread_Close==0)Max_Spread_Close=4;
  if(UseAutoSets==true)
  {
  StopLoss= 60;Open_Hour= 20;Close_Hour=23;Use_CCI= true;CCI_Period=10;CCI_Entry=120;CCI_Exit=125;Use_WPR=true;WPR_Period=10;WPR_Entry=90;WPR_Exit=35;
  Use_Fractals=true;MidFractalDist=8;OppositFractalDist=11;Use_MA1=False;MA_Period1=25;Use_MA2_Slope=False;MA_Slope= 5;
  }
  }
  //---
  if (StringSubstr(Symbol(),0,6)=="EURCHF")
  { 
  if(Max_Spread_Open==0)Max_Spread_Open=5;if(Max_Spread_Close==0)Max_Spread_Close=5;
  if(UseAutoSets==true)
  {
  StopLoss= 40;Open_Hour= 20;Close_Hour=23;Use_CCI= true;CCI_Period=10;CCI_Entry=100;CCI_Exit=130;Use_WPR=true;WPR_Period=10;WPR_Entry=91;WPR_Exit=30;
  Use_Fractals=true;MidFractalDist=7;OppositFractalDist=9;Use_MA1=False;MA_Period1=25;Use_MA2_Slope=False;MA_Slope= 5;
  }
  }
  //---
  if (StringSubstr(Symbol(),0,6)=="USDCHF")
  { 
  if(Max_Spread_Open==0)Max_Spread_Open=4;if(Max_Spread_Close==0)Max_Spread_Close=4;
  if(UseAutoSets==true)
  {
  StopLoss= 40;Open_Hour= 20;Close_Hour=23;Use_CCI= true;CCI_Period=10;CCI_Entry=100;CCI_Exit=120;Use_WPR=true;WPR_Period=10;WPR_Entry=91;WPR_Exit=40;
  Use_Fractals=true;MidFractalDist=6;OppositFractalDist=9;Use_MA1=False;MA_Period1=25;Use_MA2_Slope=False;MA_Slope= 5;
  }
  }
  //---
  if (StringSubstr(Symbol(),0,6)=="GBPCHF")
  { 
  if(Max_Spread_Open==0)Max_Spread_Open=6;if(Max_Spread_Close==0)Max_Spread_Close=6;
  if(UseAutoSets==true)
  {
  StopLoss= 50;Open_Hour= 20;Close_Hour=23;Use_CCI= true;CCI_Period=10;CCI_Entry=100;CCI_Exit=130;Use_WPR=true;WPR_Period=10;WPR_Entry=91;WPR_Exit=30;
  Use_Fractals=true;MidFractalDist=9;OppositFractalDist=15;Use_MA1=False;MA_Period1=25;Use_MA2_Slope=False;MA_Slope= 5;
  }
  }
  //---
  if (StringSubstr(Symbol(),0,6)=="GBPCAD")
  {  
  if(Max_Spread_Open==0)Max_Spread_Open=6;if(Max_Spread_Close==0)Max_Spread_Close=6;
  if(UseAutoSets==true)
  {
  StopLoss= 50;Open_Hour= 20;Close_Hour=23;Use_CCI= true;CCI_Period=10;CCI_Entry=100;CCI_Exit=130;Use_WPR=true;WPR_Period=10;WPR_Entry=91;WPR_Exit=30;
  Use_Fractals=true;MidFractalDist=7;OppositFractalDist=13;Use_MA1=False;MA_Period1=25;Use_MA2_Slope=False;MA_Slope= 5;
  }
  }
  //---
  if (StringSubstr(Symbol(),0,6)=="EURUSD")
  {  
  if(Max_Spread_Open==0)Max_Spread_Open=4;if(Max_Spread_Close==0)Max_Spread_Close=4;
  if(UseAutoSets==true)
  {
  StopLoss= 40;Open_Hour= 20;Close_Hour=23;Use_CCI= true;CCI_Period=10;CCI_Entry=100;CCI_Exit=120;Use_WPR=true;WPR_Period=8;WPR_Entry=93;WPR_Exit=42;
  Use_Fractals=True;MidFractalDist=8;OppositFractalDist=15;Use_MA1=true;MA_Period1=75;Use_MA2=true;MA_Period2=20;Use_MA2_Slope=False;MA_Slope= 5;
  }
  }
  //---
  if (StringSubstr(Symbol(),0,6)=="CADCHF")
  {
  if(Max_Spread_Open==0)Max_Spread_Open=6;if(Max_Spread_Close==0)Max_Spread_Close=6;
  if(UseAutoSets==true)
  {
  StopLoss= 50;Open_Hour= 20;Close_Hour=23;Use_CCI= true;CCI_Period=10;CCI_Entry=100;CCI_Exit=130;Use_WPR=true;WPR_Period=10;WPR_Entry=91;WPR_Exit=30;
  Use_Fractals=true;MidFractalDist=7;OppositFractalDist=13;Use_MA1=False;MA_Period1=25;Use_MA2_Slope=False;MA_Slope= 5;
  }
  }
  //---
  if (StringSubstr(Symbol(),0,6)=="GBPUSD")
  {  
  if(Max_Spread_Open==0)Max_Spread_Open=4;if(Max_Spread_Close==0)Max_Spread_Close=4;
  if(UseAutoSets==true)
  {
  StopLoss= 40;Open_Hour= 20;Close_Hour=23;Use_CCI= true;CCI_Period=10;CCI_Entry=100;CCI_Exit=125;Use_WPR=true;WPR_Period=12;WPR_Entry=90;WPR_Exit=38;
  Use_Fractals=true;MidFractalDist=6;OppositFractalDist=11;Use_MA1=False;MA_Period1=25;Use_MA2_Slope=False;MA_Slope= 5;
  }
  }
  //-----------------------------------------------------------------
  //Confirm range
  if((DelaySessionMinutes<0)||(DelaySessionMinutes>59)) DelaySessionMinutes=0;
  if((Type_ATR_level<1)||(Type_ATR_level>2)) Type_ATR_level=1;
  //-----------------------------------------------------------------
  //Set Magic Number
  if (StringSubstr(Symbol(),0,6)=="EURCAD") Magic=MAGIC+1;
  if (StringSubstr(Symbol(),0,6)=="EURGBP") Magic=MAGIC+2;
  if (StringSubstr(Symbol(),0,6)=="USDCAD") Magic=MAGIC+3;
  if (StringSubstr(Symbol(),0,6)=="EURCHF") Magic=MAGIC+4;
  if (StringSubstr(Symbol(),0,6)=="USDCHF") Magic=MAGIC+5;
  if (StringSubstr(Symbol(),0,6)=="GBPCHF") Magic=MAGIC+6;
  if (StringSubstr(Symbol(),0,6)=="GBPCAD") Magic=MAGIC+7;
  if (StringSubstr(Symbol(),0,6)=="EURUSD") Magic=MAGIC+8;
  if (StringSubstr(Symbol(),0,6)=="CADJPY") Magic=MAGIC+9;
  if (StringSubstr(Symbol(),0,6)=="GBPJPY") Magic=MAGIC+10; 
  if (StringSubstr(Symbol(),0,6)=="CADCHF") Magic=MAGIC+11;
  if (StringSubstr(Symbol(),0,6)=="GBPUSD") Magic=MAGIC+12;
  if (StringSubstr(Symbol(),0,6)=="USDJPY") Magic=MAGIC+13;
  if (StringSubstr(Symbol(),0,6)=="AUDUSD") Magic=MAGIC+14;
  if (StringSubstr(Symbol(),0,6)=="AUDCAD") Magic=MAGIC+15; 
  if (StringSubstr(Symbol(),0,6)=="AUDJPY") Magic=MAGIC+16;
  if (StringSubstr(Symbol(),0,6)=="EURAUD") Magic=MAGIC+17;
  if (StringSubstr(Symbol(),0,6)=="GBPAUD") Magic=MAGIC+18;
  if (StringSubstr(Symbol(),0,6)=="EURNZD") Magic=MAGIC+19; 
  if (StringSubstr(Symbol(),0,6)=="GBPNZD") Magic=MAGIC+20;
  if (StringSubstr(Symbol(),0,6)=="EURNOK") Magic=MAGIC+21; 
  if (StringSubstr(Symbol(),0,6)=="EURSEK") Magic=MAGIC+22;
  if (StringSubstr(Symbol(),0,6)=="NZDUSD") Magic=MAGIC+23; 
  if (StringSubstr(Symbol(),0,6)=="NZDJPY") Magic=MAGIC+24;
  if (StringSubstr(Symbol(),0,6)=="EURJPY") Magic=MAGIC+25; 
  if (StringSubstr(Symbol(),0,6)=="AUDCHF") Magic=MAGIC+26; 
  if (StringSubstr(Symbol(),0,6)=="NZDCHF") Magic=MAGIC+27;
  if (StringSubstr(Symbol(),0,6)=="AUDNZD") Magic=MAGIC+28; 
  if (StringSubstr(Symbol(),0,6)=="CHFJPY") Magic=MAGIC+29;
  if (StringSubstr(Symbol(),0,6)=="NZDCAD") Magic=MAGIC+30; 
  if (StringSubstr(Symbol(),0,6)=="USDDKK") Magic=MAGIC+31;  
  if (StringSubstr(Symbol(),0,6)=="USDNOK") Magic=MAGIC+32; 
  if (StringSubstr(Symbol(),0,6)=="USDSEK") Magic=MAGIC+33;
  //-----------------------------------------------------------------
  //detect current DST
  if((IsTesting())||(IsOptimization()))
  {
  int GetMonth=Month();
  int GetDayOfMonth=Day();
  int GetDayOfWeek=DayOfWeek();
  if (GetDayOfWeek==0) GetDayOfWeek=7;
  //---
  if((GetMonth>3)&&(GetMonth<10)) DSTcur=1;
  if((GetMonth<3)&&(GetMonth>10)) DSTcur=0;
  if((GetMonth==3)&&(GetDayOfMonth<=24)) DSTcur=0;
  if((GetMonth==10)&&(GetDayOfMonth<=24)) DSTcur=1;
  //---
  if((GetMonth==3)&&(GetDayOfMonth>24))//detect last week
  {
  if((GetDayOfMonth==31)&&(GetDayOfWeek==7)) DSTcur=1;
  if((GetDayOfMonth==30)&&(GetDayOfWeek==7)) DSTcur=1;
  if((GetDayOfMonth==29)&&(GetDayOfWeek==7)) DSTcur=1;
  if((GetDayOfMonth==28)&&(GetDayOfWeek==7)) DSTcur=1;
  if((GetDayOfMonth==27)&&(GetDayOfWeek==7)) DSTcur=1;
  if((GetDayOfMonth==26)&&(GetDayOfWeek==7)) DSTcur=1;
  if((GetDayOfMonth==25)&&(GetDayOfWeek==7)) DSTcur=1;
  }
  if((GetMonth==10)&&(GetDayOfMonth>24))//detect last week
  {
  if((GetDayOfMonth==31)&&(GetDayOfWeek==7)) DSTcur=0;
  if((GetDayOfMonth==30)&&(GetDayOfWeek==7)) DSTcur=0;
  if((GetDayOfMonth==29)&&(GetDayOfWeek==7)) DSTcur=0;
  if((GetDayOfMonth==28)&&(GetDayOfWeek==7)) DSTcur=0;
  if((GetDayOfMonth==27)&&(GetDayOfWeek==7)) DSTcur=0;
  if((GetDayOfMonth==26)&&(GetDayOfWeek==7)) DSTcur=0;
  if((GetDayOfMonth==25)&&(GetDayOfWeek==7)) DSTcur=0;
  }
  }
  //-----------------------------------------------------------------
  start();
  return (0);
}
//=================================================================================================================================================//
int deinit()
{
  ObjectDelete("Background1");
  ObjectDelete("Background2");
  Comment("");//clear comments
  return (0);
}
//=================================================================================================================================================//
int start()
{ 
  //-----------------------------------------------------------------
  //Time Offset
  if((IsTesting())||(IsOptimization()))
  {
  if(GMT_Offset==99) {Alert("Please set GMT Offset in the EA inputs"); Sleep(60000);return(0);}
  DST();
  if((DSTcur==1)&&(DSTprv==0)) DSTextern=-1;
  if((DSTcur==1)&&(DSTprv==1)) DSTextern=0;
  if((DSTcur==0)&&(DSTprv==0)) DSTextern=0;
  if((DSTcur==0)&&(DSTprv==1)) DSTextern=1;
  }
  else DSTextern=0;
  //---
  if((!IsTesting())&&(!IsOptimization())) GMT_Offset=GMTOffset();
  //---
  StarHour=Open_Hour+GMT_Offset+DSTextern;
  EndHour=Close_Hour+GMT_Offset+DSTextern;
  Friday_Hour=Friday_Hour+GMT_Offset+DSTextern;
  if(StarHour>=24) StarHour=StarHour-24;
  if(EndHour>=24) EndHour=EndHour-24;
  //-----------------------------------------------------------------
  if(((IsTesting())||(IsOptimization()))&&((PrvHoursCheck1==PrvHoursCheck2)||(PrvHoursCheck1>PrvHoursCheck2))) return(0);//optimization confirm
  if(Trade_Pause_On_Loss==true) CountHistoryOrders();
  CountCurrentOrders();
  //-----------------------------------------------------------------
  //confirm use indicators
  if (!Use_CCI  && !Use_WPR && !Use_Fractals) {Print("You must use at least one signal (CCI, WPR, or Fractals"); return(0);} 
  //-----------------------------------------------------------------
  //trade time
  Trade = true;
  if (!TradeOnFriday && TimeDayOfWeek(TimeCurrent()-GMT_Offset*3600) == 5) Trade = FALSE;
  if (TradeOnFriday && DayOfWeek() == 5 && TimeHour(TimeCurrent()) > (Friday_Hour)) Trade = FALSE;
  
  if (StarHour < EndHour && TimeHour(TimeCurrent())=EndHour) Trade = FALSE;
  if (StarHour > EndHour && TimeHour(TimeCurrent())= EndHour) Trade = FALSE;
  if((TimeHour(TimeCurrent())==StarHour)&&(TimeMinute(TimeCurrent())0)) Trade = FALSE;
  if (Month()==12 && Day()>22)  Trade = FALSE; 
  if (Month()==1 && Day()<5)  Trade = FALSE; 
  //+-----------------------------------------------------------------------------------------------------+
  //Volatility filter
  if((UseVolatilityFilter==true)&&(LimitVolatility>0))
  {
  if((iHigh(NULL,PERIOD_M15,1)-iLow(NULL,PERIOD_M15,1)>=LimitVolatility*PointsDec)) Trade=false;
  if((iHigh(NULL,PERIOD_M15,2)-iLow(NULL,PERIOD_M15,2)>=LimitVolatility*PointsDec)) Trade=false;
  }
  //-----------------------------------------------------------------
  //check spread
  if (!IsTesting() && !IsOptimization()) 
  {
  if (Trade && TotalOpenOrders==0 && !Allow_Second_Trade && Spread()Max_Spread_Open*PointsDec|| (Ask-Bid)>Max_Spread_Open*PointsDec)) Session="Trade Session Open .. Spread is High .. Trading Halted";
  if (Trade && TotalOpenOrders>0 && (Spread()>Max_Spread_Close*PointsDec|| (Ask-Bid)>Max_Spread_Close*PointsDec)) Session="Trade Session Open..Waiting to exit trades..Trading Halted"; 
  if (Trade && TotalOpenOrders>0 && (Spread()0) Session="Trade Session Closed .. Waiting to exit trades"; 
  //+-----------------------------------------------------------------------------------------------------+
  //News filter
  if(AvoidNews==true)
  {
  static int PrevMinute=-1;  
  int MinSinceNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,1,0);
  int MinToNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,1,1);
  int ImpactSinceNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,2,0);
  int ImpactToNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,2,1);
  if(Minute()!=PrevMinute)
  {
  PrevMinute=Minute();
  if((MinToNews<=MinsBeforeNews&&ImpactToNews>=MinimumImpact)||(MinSinceNews<=MinsAfterNews&&ImpactSinceNews>=MinimumImpact)) Trade=false;
  }
  }
  //-----------------------------------------------------------------
  Display(); //Add Disply
  if (Show_Fractal_Levels) iCustom(NULL,0,"Fractal_Levels",MidFractalDist,OppositFractalDist,0,0);
  Spread(Ask-Bid); //get spread
  if(!Hide_SL_TP && TotalOpenOrders>0) ModifyAll(); // Double check to make sure all trades have TP and SL 
  }//end if (!IsTesting() && !IsOptimization()) 
  //-----------------------------------------------------------------
  //filter atr
  if (Trade || OrdersTotal()>0)
  {
  FilterATR=0;
  if(UseATRfilter==true )
  {
  switch(Type_ATR_level)
  {
  case 1: if(iATR(NULL, 0, Atr_Period, 0) > AtrLevel) FilterATR=1; break;
  case 2: if(iATR(NULL, 0, Atr_Period, 0) < AtrLevel) FilterATR=1; break;
  }
  }
  if(UseATRfilter==false) FilterATR=1;
  //-----------------------------------------------------------------
  //indicators
  if (Use_CCI) CCI_1 = iCCI(NULL, 0, CCI_Period, PRICE_CLOSE, 0);  
  if (Use_WPR) WPR_1 = iWPR(NULL, 0, WPR_Period, 0);
  //---
  if(Trade==true)
  {
  if (Use_MA1) MA_1_1  = iMA(NULL,0,MA_Period1,0,MA_Mode1,PRICE_CLOSE,1);
  if (Use_MA1) MA_1_2  = iMA(NULL,0,MA_Period1,0,MA_Mode1,PRICE_CLOSE,2);    
  if (Use_MA2 || Use_MA2_Slope) MA_2_1  = iMA(NULL,0,MA_Period2,0,MA_Mode2,PRICE_CLOSE,1);
  if (Use_MA2 || Use_MA2_Slope) MA_2_2  = iMA(NULL,0,MA_Period2,0,MA_Mode2,PRICE_CLOSE,2);
  if (Use_MA_Dist) MA_3_1  = iMA(NULL,0,MA_Dist_Period,0,MA_Dist_Mode,PRICE_CLOSE,1);
  if (Use_BB) BB_L_1  = iBands(NULL,0,BB_Period,BB_Dev,0,PRICE_CLOSE,MODE_LOWER,0);
  if (Use_BB) BB_L_2  = iBands(NULL,0,BB_Period,BB_Dev,0,PRICE_CLOSE,MODE_LOWER,1); 
  if (Use_BB) BB_L_3  = iBands(NULL,0,BB_Period,BB_Dev,0,PRICE_CLOSE,MODE_LOWER,2);    
  if (Use_BB) BB_U_1  = iBands(NULL,0,BB_Period,BB_Dev,0,PRICE_CLOSE,MODE_UPPER,0);    
  if (Use_BB) BB_U_2  = iBands(NULL,0,BB_Period,BB_Dev,0,PRICE_CLOSE,MODE_UPPER,1);
  if (Use_BB) BB_U_3  = iBands(NULL,0,BB_Period,BB_Dev,0,PRICE_CLOSE,MODE_UPPER,2);    
  if (Use_RSI) RSI_1  = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, 0);
  }
  //-----------------------------------------------------------------
  //trade signals
  CCI_Buy_Sig=0;
  CCI_Sell_Sig=0;  
  WPR_Buy_Sig=0;
  WPR_Sell_Sig=0;
  MA_Buy_Sig1=0;
  MA_Sell_Sig1=0;
  MA_Buy_Sig2=0;
  MA_Sell_Sig2=0;  
  MA_Slope_Buy_Sig=0;
  MA_Slope_Sell_Sig=0;  
  Fractals_Buy_Sig=0;
  Fractals_Sell_Sig=0;
  BB_Buy_Sig=0;
  BB_Sell_Sig=0;
  Trade_Pause_Buy_Sig=1;
  Trade_Pause_Sell_Sig=1; 
  MA_Dist_Buy_Sig=0;
  MA_Dist_Sell_Sig=0;   
  RSI_Buy_Sig=0;
  RSI_Sell_Sig=0;    
  //---
  if((Trade)&&(FilterATR==1))
  {
  if (!Use_CCI) {CCI_Buy_Sig=1;CCI_Sell_Sig=1;}
  if (!Use_WPR) {WPR_Buy_Sig=1;WPR_Sell_Sig=1;}  
  if (!Use_MA1) {MA_Buy_Sig1=1; MA_Sell_Sig1=1;} 
  if (!Use_MA2) {MA_Buy_Sig2=1; MA_Sell_Sig2=1;}  
  if (!Use_MA2_Slope) {MA_Slope_Buy_Sig=1; MA_Slope_Sell_Sig=1;}  
  if (!Use_Fractals) {Fractals_Buy_Sig=1; Fractals_Sell_Sig=1;}
  if (!Use_BB) {BB_Buy_Sig=1; BB_Sell_Sig=1;}
  if (!Use_MA_Dist) {MA_Dist_Buy_Sig=1; MA_Dist_Sell_Sig=1;} 
  if (!Use_RSI) {RSI_Buy_Sig=1; RSI_Sell_Sig=1;}  
  if (Use_CCI && CCI_1<-CCI_Entry) CCI_Buy_Sig=1;
  if (Use_CCI && CCI_1>CCI_Entry) CCI_Sell_Sig=1;  
  if (Use_WPR && WPR_1<-WPR_Entry) WPR_Buy_Sig=1;  
  if (Use_WPR && WPR_1>-(100-WPR_Entry)) WPR_Sell_Sig=1;  
  if (Use_MA1 && MA_1_1>MA_1_2)  MA_Buy_Sig1=1;  
  if (Use_MA1 && MA_1_1MA_2_2)  MA_Buy_Sig2=1;  
  if (Use_MA2 && MA_2_1=MA_Slope*PointsDec)  MA_Slope_Buy_Sig=1;  
  if (Use_MA2_Slope && (MA_2_2-MA_2_1)>=MA_Slope*PointsDec)  MA_Slope_Sell_Sig=1;    
  if (Use_BB && !Use_BB_Direction && AskBB_Range*PointsDec && BB_L_1-Ask>=BB_Penetration*PointsDec) BB_Buy_Sig=1;
  if (Use_BB && !Use_BB_Direction && Bid>BB_U_1 && (BB_U_1-BB_L_1)>BB_Range*PointsDec && Bid-BB_U_1>=BB_Penetration*PointsDec) BB_Sell_Sig=1;  
  if (Use_BB && Use_BB_Direction && AskBB_Range*PointsDec && BB_L_1-Ask>=BB_Penetration*PointsDec && BB_L_1>BB_L_2) BB_Buy_Sig=1;
  if (Use_BB && Use_BB_Direction && Bid>BB_U_1 && (BB_U_1-BB_L_1)>BB_Range*PointsDec && Bid-BB_U_1>=BB_Penetration*PointsDec && BB_U_1=Dist_to_MA*PointsDec)  MA_Dist_Sell_Sig=1;   
  if (Use_RSI && RSI_1>=RSI_Entry)  RSI_Buy_Sig=1;  
  if (Use_RSI && RSI_1<=(100-RSI_Entry))  RSI_Sell_Sig=1;
  //---------------------------------------------------------
  //count fractals  
  if ((Use_Fractals)&&(TotalOpenOrders==0)&&(New_Trade))
  {
  if((Spread()(midFractal+MidFractalDist*PointsDec) && Bid>(LastDownFractal+OppositFractalDist*PointsDec)) Fractals_Sell_Sig=1;
  }// end if((Trade)&&(FilterATR==1))
  //-----------------------------------------------------------------
  //exit signals
  if(TotalOpenOrders>0)
  {
  CCI_Exit_Buy_Sig=0;
  CCI_Exit_Sell_Sig=0;  
  WPR_Exit_Buy_Sig=0;
  WPR_Exit_Sell_Sig=0;  
  //---   
  if (Use_CCI && CCI_1>CCI_Exit) CCI_Exit_Buy_Sig=1;
  if (Use_CCI && CCI_1<-CCI_Exit) CCI_Exit_Sell_Sig=1;  
  if (Use_WPR && WPR_1>-WPR_Exit) WPR_Exit_Buy_Sig=1;  
  if (Use_WPR && WPR_1<(-100+WPR_Exit)) WPR_Exit_Sell_Sig=1; 
  //-----------------------------------------------------------------
  //close trades
  if((CCI_Exit_Buy_Sig==1 || WPR_Exit_Buy_Sig==1) && Spread()0)
  //-----------------------------------------------------------------
  //open trades
  //---First buy trade
  if(Trade)
  {
  if(FilterATR==1)
  {
  if((TotalOpenOrders==0)&&(New_Trade==true))
  {
  //---Hourly level
  int CheckHourBuy=0;
  int CheckHourSell=0;
  if(UsePriceLevelFilter==true)
  {
  if(iClose(NULL,PERIOD_H1,PrvHoursCheck1)-iClose(NULL,PERIOD_H1,PrvHoursCheck2)>=LevelsDistance*PointsDec) CheckHourBuy=1;
  if(iClose(NULL,PERIOD_H1,PrvHoursCheck2)-iClose(NULL,PERIOD_H1,PrvHoursCheck1)>=LevelsDistance*PointsDec) CheckHourSell=1;
  }
  if((UsePriceLevelFilter==false)||(LevelsDistance==0))
  {
  CheckHourBuy=1;
  CheckHourSell=1;
  }  
//---
  if (Spread()0)
  {
  Last_Time=iTime(NULL,0,0);
  if (!Hide_SL_TP) ModifyAll();
  if(SendMailInfo==true)  SendMail("Open Buy","No Of Ticket: "+Ticket_1+"  Order Open Price: "+Ask);
  }
  //---
  }
  //---First sell trade   
  if (Spread()0)
  {
  Last_Time=iTime(NULL,0,0);
  if (!Hide_SL_TP) ModifyAll();
  if(SendMailInfo==true)  SendMail("Open Sell","No Of Ticket: "+Ticket_1+"  Order Open Price: "+Bid);
  }
  //---
  }
  }  //end if(TotalOpenOrders==0)
  //---Second buy trade
  if((TotalOpenOrders==1)&&(Allow_Second_Trade==true))
  {
  if(Time[0]!=Last_Time && Trade_Pause_Buy_Sig==1 && Trade_Pause_Buy_Sig==1 && LastOpenType==0 && Ask<=(LastBuyPrice-Distance*PointsDec))
  {
  Lot=CalculateLots(Risk*Lot_Factor);
  Ticket_1=0;
  //---
  Ticket_1 = OrderSend(Symbol(), OP_BUY, Lot, Ask, Slippage, 0, 0, EA_Comment, Magic, 0, Lime);
  if (Ticket_1>0)
  {
  Last_Time=iTime(NULL,0,0);
  if (!Hide_SL_TP) ModifyAll();
  if(SendMailInfo==true)  SendMail("Open Buy","No Of Ticket: "+Ticket_1+"  Order Open Price: "+Ask);
  }
  //---
  }
  //---Second sell trade   
  if(Time[0]!=Last_Time && Trade_Pause_Sell_Sig==1 && Trade_Pause_Sell_Sig==1 && LastOpenType==1 && Bid>=(LastSellPrice+Distance*PointsDec))
  {
  Lot=CalculateLots(Risk*Lot_Factor);
  Ticket_2=0;
  //---
  Ticket_2 = OrderSend(Symbol(), OP_SELL, Lot, Bid, Slippage, 0, 0, EA_Comment, Magic, 0, Red);
  if (Ticket_2>0)
  {
  Last_Time=iTime(NULL,0,0);
  if (!Hide_SL_TP) ModifyAll();
  if(SendMailInfo==true)  SendMail("Open Sell","No Of Ticket: "+Ticket_1+"  Order Open Price: "+Bid);
  }
  //---
  }
  }//end (TotalOpenOrders==1)
  //---
  }// end if(Trade)
  }// end if(FilterATR==1)
  } //end if (Trade || OrdersTotal()>0)  
  return (0);
}
//=================================================================================================================================================//
void CountCurrentOrders()
{
  int total=OrdersTotal();
  TotalOpenOrders=0;
  LastBuyPrice=0;
  LastSellPrice=0;
  LastOpenType=-1;
  SumProfit=0;
  NetProfit=0;
  //-----------------------------------------------------------------
  for(int cnt=0; cnt=TakeProfit*PointsDec)||(OrderOpenPrice()-Ask>=StopLoss*PointsDec))
  {
  CloseAll(OrderTicket(),OrderType());
  RefreshRates();
  }
  }
  if(OrderType()==OP_SELL)
  {
  LastSellPrice=OrderOpenPrice();
  LastOpenType=OP_SELL;
  if((Hide_SL_TP==true)&&(OrderOpenPrice()-Bid>=TakeProfit*PointsDec)||(Bid-OrderOpenPrice()>=StopLoss*PointsDec))
  {
  CloseAll(OrderTicket(),OrderType());
  RefreshRates();
  }
  }
  TotalOpenOrders++;
  SumProfit+=OrderProfit()+OrderCommission()+OrderSwap();
  NetProfit+=OrderProfit();
  }
  }
  }
  //-----------------------------------------------------------------
  return(0);
}
//=================================================================================================================================================//
void CountHistoryOrders()
{
  int total=OrdersHistoryTotal();
  HistoryProfits=0;
  LastClosedProfit=0;
  LastClosedPrice=0;
  LastClosedType=-1;
  LastClosedTime=0;
  //-----------------------------------------------------------------
  for(int cnt=0; cnt= 0; cnt--) 
  { 
  if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
  {
  if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderCloseTime()==0) 
  {
  //--- close buy
  if((OrderType()==OP_BUY)&&(OrderType()==OrdrType)&&((OrderTicket()==OrdrTicket)||(OrdrTicket==0)))
  {
  WasOrderClosed=false;
  WasOrderClosed=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue);
  if(WasOrderClosed>0) if(SendMailInfo==true)  SendMail("Close Buy","No Of Ticket: "+OrderTicket()+"  Order Close Price: "+Bid+"  Profit Order: "+OrderProfit());
  }
  //--- close sell
  if((OrderType()==OP_SELL)&&(OrderType()==OrdrType)&&((OrderTicket()==OrdrTicket)||(OrdrTicket==0)))
  {
  WasOrderClosed=false;
  WasOrderClosed=OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red);
  if(WasOrderClosed>0) if(SendMailInfo==true)  SendMail("Close Sell","No Of Ticket: "+OrderTicket()+"  Order Close Price: "+Ask+"  Profit Order: "+OrderProfit());
  }
  //---
  } 
  }
  }
  return(0); 
}
//=================================================================================================================================================//
double CalculateLots(double r) 
{
  int SL = 1000;
  double ls, minl, maxl, rval;
  ls = MarketInfo(Symbol(),MODE_LOTSTEP);
  minl = MarketInfo(Symbol(),MODE_MINLOT);
  maxl = MarketInfo(Symbol(),MODE_MAXLOT);
  //---
  if(lot>0.0)	rval = lot;
  else
  rval = AccountBalance()*(r/100.0)/(SL*MarketInfo(Symbol(),MODE_TICKVALUE)*Point/MarketInfo(Symbol(),MODE_TICKSIZE));
  //---
  return(MathMin(MathMax(minl,MathRound(rval/ls)*ls),maxl));
}
//=================================================================================================================================================//
void ModifyAll() 
{ 
  for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--) 
  { 
  if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==false) continue;
  if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
  { 
  if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic ) 
  { 
  if (OrderStopLoss()==0 || OrderTakeProfit()==0)
  {
  if((OrderType()==OP_BUY)) 
  OrderModify(OrderTicket(),OrderOpenPrice(),ND(OrderOpenPrice()-PointsDec*StopLoss), ND(OrderOpenPrice()+TakeProfit*PointsDec),0,Green); 
  if((OrderType()==OP_SELL)) 
  OrderModify(OrderTicket(),OrderOpenPrice(),ND(OrderOpenPrice()+PointsDec*StopLoss), ND(OrderOpenPrice()-TakeProfit*PointsDec),0,Red);
  }  
  } 
  }
  }
  return(0);
}
//=================================================================================================================================================//
double Spread(double AddValue=0)
{
  double LastValue;
  static double ArrayTotal=0;
  //--- 
  if (AddValue == 0 && SpreadSampleSize <= 0) return(Ask-Bid);
  if (AddValue == 0 && ArrayTotal == 0) return(Ask-Bid);
  if (AddValue == 0 ) return(ArrayTotal/ArraySize(Spread));
  //--- 
  ArrayTotal = ArrayTotal + AddValue;
  ArraySetAsSeries(Spread, true); 
  if (ArraySize(Spread) == SpreadSampleSize)
  {
  LastValue = Spread[0];
  ArrayTotal = ArrayTotal - LastValue;
  ArraySetAsSeries(Spread, false);
  ArrayResize(Spread, ArraySize(Spread)-1 );
  ArraySetAsSeries(Spread, true);
  ArrayResize(Spread, ArraySize(Spread)+1 ); 
  }
  else ArrayResize(Spread, ArraySize(Spread)+1 ); 
  ArraySetAsSeries(Spread, false);
  Spread[0] = AddValue;
  //---
  return(NormalizeDouble(ArrayTotal/ArraySize(Spread), Digits));
}
//=================================================================================================================================================//
double ND(double Price)
{
  return(NormalizeDouble(Price,Digits));
} 
//=================================================================================================================================================//
void Display()
{
  string DelayCom="00";
  if(DelaySessionMinutes<10) DelayCom="0"+DelaySessionMinutes;
  if(DelaySessionMinutes>9) DelayCom=DelaySessionMinutes;
  Comment( 
          "\n*=====================*",   
          "\n    "+EA_Name,
          "\n*=====================*",
          "\n   "+Session,
          "\n*=====================*",
          "\n    Broker Time          =  ", TimeToStr(TimeCurrent(), TIME_MINUTES),
          "\n    Start Hour             =  "+DoubleToStr(StarHour,0)+":"+DelayCom,          
          "\n    End Hour              =  "+DoubleToStr(EndHour,0)+":00", 
          "\n*=====================*",                                                            
          "\n    Magic Number       = "+Magic,
          "\n    Max Spread Open  = "+DoubleToStr(Max_Spread_Open,1),
          "\n    Max Spread Close  = "+DoubleToStr(Max_Spread_Close,1),
          "\n    Average Spread    = "+DoubleToStr(Spread()/PointsDec,1),
          "\n    Lot size                 =  " +DoubleToStr(CalculateLots(Risk),2),
          "\n    Stop Loss              = "+DoubleToStr(StopLoss,0), 
          "\n*=====================*",                                                            
          "\n    TotalProfit (Loss)    =  " +DoubleToStr(SumProfit,2),
          "\n    NetProfit (Loss)      = "+DoubleToStr(NetProfit,2), 
          "\n*=====================*",                                                            
          "\n    History Profit (Loss) = "+DoubleToStr(HistoryProfits+SumProfit,2), 
          "\n*=====================*",
          "\n    B A L A N C E       =  " + DoubleToStr(AccountBalance(),2),
          "\n    E Q U I T Y          =  " + DoubleToStr(AccountEquity(),2),
          "\n    L E V E R A G E    =  " + DoubleToStr(AccountLeverage(),2),            
          "\n*=====================*"
         );
  return(0);       
} 
//=================================================================================================================================================//
int DST()
{
  int GetMonth=Month();
  int GetDayOfMonth=Day();
  int GetDayOfWeek=DayOfWeek();
  if (GetDayOfWeek==0) GetDayOfWeek=7;
  //---
  if((GetMonth>3)&&(GetMonth<10)) DSTprv=1;
  if((GetMonth<3)&&(GetMonth>10)) DSTprv=0;
  if((GetMonth==3)&&(GetDayOfMonth<=24)) DSTprv=0;
  if((GetMonth==10)&&(GetDayOfMonth<=24)) DSTprv=1;
  //---
  if((GetMonth==3)&&(GetDayOfMonth>24))//detect last week
  {
  if((GetDayOfMonth==31)&&(GetDayOfWeek==7)) DSTprv=1;
  if((GetDayOfMonth==30)&&(GetDayOfWeek==7)) DSTprv=1;
  if((GetDayOfMonth==29)&&(GetDayOfWeek==7)) DSTprv=1;
  if((GetDayOfMonth==28)&&(GetDayOfWeek==7)) DSTprv=1;
  if((GetDayOfMonth==27)&&(GetDayOfWeek==7)) DSTprv=1;
  if((GetDayOfMonth==26)&&(GetDayOfWeek==7)) DSTprv=1;
  if((GetDayOfMonth==25)&&(GetDayOfWeek==7)) DSTprv=1;
  }
  if((GetMonth==10)&&(GetDayOfMonth>24))//detect last week
  {
  if((GetDayOfMonth==31)&&(GetDayOfWeek==7)) DSTprv=0;
  if((GetDayOfMonth==30)&&(GetDayOfWeek==7)) DSTprv=0;
  if((GetDayOfMonth==29)&&(GetDayOfWeek==7)) DSTprv=0;
  if((GetDayOfMonth==28)&&(GetDayOfWeek==7)) DSTprv=0;
  if((GetDayOfMonth==27)&&(GetDayOfWeek==7)) DSTprv=0;
  if((GetDayOfMonth==26)&&(GetDayOfWeek==7)) DSTprv=0;
  if((GetDayOfMonth==25)&&(GetDayOfWeek==7)) DSTprv=0;
  }
  //---
  return(0);
} 
//=================================================================================================================================================//
  int GMTOffset()
  {
  int TimeArray[4];
  int TZInfoArray[43];
  int nYear,nMonth,nDay,nHour,nMin,nSec,nMilliSec;
  string sMilliSec;
  GetSystemTime(TimeArray);
  nYear=TimeArray[0]&0x0000FFFF;
  nMonth=TimeArray[0]>>16;
  nDay=TimeArray[1]>>16;
  nHour=TimeArray[2]&0x0000FFFF;
  nMin=TimeArray[2]>>16;
  nSec=TimeArray[3]&0x0000FFFF;
  nMilliSec=TimeArray[3]>>16;
  string LocalTimeS=FormatDateTime(nYear,nMonth,nDay,nHour,nMin,nSec);
  double GMTdiff=TimeCurrent()-StrToTime(LocalTimeS);
  return(MathRound(GMTdiff/3600.0));
  }
//=================================================================================================================================================//
  string FormatDateTime(int nYear,int nMonth,int nDay,int nHour,int nMin,int nSec)
  {
  string sMonth,sDay,sHour,sMin,sSec;
  sMonth=100+nMonth;
  sMonth=StringSubstr(sMonth,1);
  sDay=100+nDay;
  sDay=StringSubstr(sDay,1);
  sHour=100+nHour;
  sHour=StringSubstr(sHour,1);
  sMin=100+nMin;
  sMin=StringSubstr(sMin,1);
  sSec=100+nSec;
  sSec=StringSubstr(sSec,1);
  return(StringConcatenate(nYear,".",sMonth,".",sDay," ",sHour,":",sMin,":",sSec));
  }
//=================================================================================================================================================//
      

Recommend