Navigation:Home > Content >

MNS_V3.02(Mode_1.1.0).mq4

Time: 2011-12-26 | Download file:MNS_V3.02(Mode_1.1.0).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  "Wininet.dll"
   int InternetOpenA(string, int, string, string, int);
   int InternetConnectA(int, string, int, string, string, int, int, int); 
   int HttpOpenRequestA(int, string, string, int, string, int, string, int); 
   int InternetOpenUrlA(int, string, string, int, int, int);
   int InternetReadFile(int, string, int, int& OneInt[]);
   int InternetCloseHandle(int); 
#import
//=================================================================================================================================================//
extern string C_1="Please Enter your own EA Comment below"; 
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 string S0="----------------------";
extern double lot           = 0;
extern double Risk          = 7.5;
extern bool   Hide_SL_TP    = False;
extern int    Slippage      = 3;
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 S1="----------------------";
extern bool   Use_Auto_Time = False;
extern int    GMT_Offset     = 3;
extern bool   UseDST = FALSE;
extern int    DelaySessionMinutes=0;
extern bool   TradeOnFriday  = False;
extern int    Friday_Hour    =15;
extern bool   UseATRfilter=false;
extern int    Atr_Period=14;
extern double AtrLevel=0.0006;
extern string S2="----------------------";
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 S3="----------------------";
extern bool   Allow_Second_Open_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 OrdersSet="----------------------";
extern double TakeProfit    = 60;
extern double StopLoss      = 50;
extern int    Open_Hour      = 20;
extern int    Close_Hour     = 23;
extern string S4="----------------------";
extern bool   Use_CCI        = False;
extern int    CCI_Period     = 10;
extern double CCI_Entry      = 200;
extern double CCI_Exit       = 140;
extern string S5="----------------------";
extern bool   Use_WPR        = true;
extern int    WPR_Period     = 10;
extern double WPR_Entry      = 91;
extern double WPR_Exit       = 40;
extern string S6="----------------------";
extern bool   Use_RSI        = false;
extern int    RSI_Period     = 70;
extern double RSI_Entry      = 50;
extern string S7="----------------------";
extern bool   Use_Fractals   = true;
extern double MidFractalDist = 5;
extern double OppositFractalDist=10;
extern bool   Show_Fractal_Levels=False;
extern string S8="----------------------";
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 S9="----------------------";
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 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 bool   Use_MA2_Slope   = False;
extern double MA_Slope       = 1;
extern string S10="----------------------";
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;
string S11="---------Global Variables---------------";
//=================================================================================================================================================//
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; 
string site1 = "http://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?tz=America/New_York";
//string site2 = "http://http://localtimes.info/North_America/United_States/New_York/New_York/";
string site2 = "http://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?tz=";
int NY_Diff,GMT_Diff;
//--------------------------
int ReCheck=0;
int ReCheckTicks=3;
int FilterATR;
int TotalOpenOrders;
int LastOpenType;
int LastClosedType;
double PointsDec;
double LastBuyPrice;
double LastSellPrice;
double SumProfit;
double NetProfit;
double HistoryProfits;
double LastClosedProfit;
double LastClosedPrice;
int LastClosedTime;
string EA_Name;
//=================================================================================================================================================//
int init()
{
  EA_Name=WindowExpertName();
  //-----------------------------------------------------------------
  //digits points
  PointsDec=Point;
  if (MarketInfo(Symbol(), MODE_DIGITS) == 5.0 || MarketInfo(Symbol(), MODE_DIGITS) == 3.0) PointsDec*=10;
  //-----------------------------------------------------------------
  //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);
  }
  }
  //-----------------------------------------------------------------
  //Time Offset
  if (Use_Auto_Time && IsTesting() || IsOptimization()) {Alert("You can not use Auto Timing in back test.  Please use manual GMT Offset.");return(0);}
  //---
  if (Use_Auto_Time && !IsTesting() && !IsOptimization())
  {
  if (Minute() ==59 || Minute() ==0 )  
  {
  Comment("Hour is changing.  Please wait few minutes");
  if (Minute()==59) Sleep(120000);
  if (Minute()==0) Sleep(60000);
  }
  //---
  if (Minute() !=59 && Minute() !=0 )
  {
  NY_Diff= Time_Offset(site1,83);
  if (NY_Diff==100)
  {
  Alert("Cant Get Auto Timing.  Please use Manual GMT Offset");
  return(0);
  }
  }
  //-----------------------------------------------------------------
  if((DelaySessionMinutes<0)||(DelaySessionMinutes>59)) DelaySessionMinutes=0;
  if (DST()==0) GMT_Offset=NY_Diff-4;
  if (DST()==1) GMT_Offset=NY_Diff-5;
  Print("NY_Diff = ",NY_Diff); 
  Alert("Your Broker GMT_Offset = ",GMT_Offset);
  }
  //-----------------------------------------------------------------
  //Set Magic Number
  if (MAGIC==0) MAGIC=MathFloor(AccountNumber()/57431)*100;
  if (MAGIC>0) MAGIC=MAGIC*100;
  //-----------------------------------------------------------------
  //Auto Sets
  if(UseAutoSets==true)
  {
  if (StringSubstr(Symbol(),0,6)=="EURCAD")
  {
  if(Max_Spread_Open==0)Max_Spread_Open=6;if(Max_Spread_Close==0)Max_Spread_Close=6;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;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;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;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;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;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;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;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;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;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;
  }
  }
  //-----------------------------------------------------------------
  //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;
  //-----------------------------------------------------------------
  //Set pm am
  if (UseDST && DST()==1)  GMT_Offset=GMT_Offset+1;
  Open_Hour=Open_Hour+GMT_Offset;
  Close_Hour=Close_Hour+GMT_Offset;
  Friday_Hour=Friday_Hour+GMT_Offset;
  if (Open_Hour>=24)Open_Hour=Open_Hour-24;
  if (Close_Hour>=24)Close_Hour=Close_Hour-24;
  //-----------------------------------------------------------------
  start();
  return (0);
}
//=================================================================================================================================================//
int deinit()
{
  ObjectDelete("Background1");
  ObjectDelete("Background2");
  Comment("");//clear comments
  return (0);
}
//=================================================================================================================================================//
int start()
{
  //-----------------------------------------------------------------
  //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
  if (Use_Auto_Time==True) {Alert("Please set Use_Auto_Time=False.  Use GMT Offset below in the EA inputs"); Sleep(60000);return(0);}
  
  Trade = true;
  if (!TradeOnFriday && TimeDayOfWeek(TimeCurrent()-GMT_Offset*3600) == 5) Trade = FALSE;
  if (TradeOnFriday && DayOfWeek() == 5 && TimeHour(TimeCurrent()) > (Friday_Hour)) Trade = FALSE;
  
  if (Open_Hour < Close_Hour && TimeHour(TimeCurrent())=Close_Hour) Trade = FALSE;
  if (Open_Hour > Close_Hour && TimeHour(TimeCurrent())= Close_Hour) Trade = FALSE;
  if((TimeHour(TimeCurrent())==Open_Hour)&&(TimeMinute(TimeCurrent())0)) Trade = FALSE;
  if (Month()==12 && Day()>22)  Trade = FALSE; 
  if (Month()==1 && Day()<5)  Trade = FALSE; 
  //-----------------------------------------------------------------
  //check spread
  if (!IsTesting() && !IsOptimization()) 
  {
  if (Trade && TotalOpenOrders==0 && !Allow_Second_Open_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"; 
  //-----------------------------------------------------------------
  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 
  //-----------------------------------------------------------------
  if(Trade==false)//reset
  {
  ReCheck=0;
  return(0);
  }
  }//end if (!IsTesting() && !IsOptimization()) 
  //-----------------------------------------------------------------
  //filter atr
  if (Trade || OrdersTotal()>0)
  {
  FilterATR=0;
  if((UseATRfilter==true ) && (iATR(NULL, 0, Atr_Period, 0) > AtrLevel)) FilterATR=1;
  if(UseATRfilter==false) FilterATR=1;
  //-----------------------------------------------------------------
  //indicators
  if(Trade_Pause_On_Loss==true) CountHistoryOrders();
  CountCurrentOrders();
  //---
  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)
  //-----------------------------------------------------------------
  //recheck signals
  if((ReCheck0)
  {
  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);
  break;
  }
  else
  {
  Print(EA_Comment+": receives new data and try again open order");
  RefreshRates();
  }
  }//end while(true)
  //---
  }
  //---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);
  break;
  }
  else
  {
  Print(EA_Comment+": receives new data and try again open order");
  RefreshRates();
  }
  }//end while(true)
  //---
  }
  }  //end if(TotalOpenOrders==0)
  //---Second buy trade
  if((TotalOpenOrders==1)&&(Allow_Second_Open_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;
  //---
  while(true)
  {
  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);
  break;
  }
  else
  {
  Print(EA_Comment+": receives new data and try again open order");
  RefreshRates();
  }
  }//end while(true)
  //---
  }
  //---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;
  //---
  while(true)
  {
  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);
  break;
  }
  else
  {
  Print(EA_Comment+": receives new data and try again open order");
  RefreshRates();
  }
  }//end while(true)
  //---
  }
  }//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());
  }
  if(OrderType()==OP_SELL)
  {
  LastSellPrice=OrderOpenPrice();
  LastOpenType=OP_SELL;
  if((OrderOpenPrice()-Bid>=TakeProfit*PointsDec)||(Bid-OrderOpenPrice()>=StopLoss*PointsDec)) CloseAll(OrderTicket(),OrderType());
  }
  }
  }
  }
  //-----------------------------------------------------------------
  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) 
  {
  //--- 
  if((OrderType()==OP_BUY)&&(OrderType()==OrdrType)&&((OrderTicket()==OrdrTicket)||(OrdrTicket==0)))
  {
  WasOrderClosed=false;
  //---
  while(true) 
  {
  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());
  break;
  }
  else
  {
  Print("Error: ",GetLastError()+" || "+EA_Comment+": receives new data and try again close order");
  RefreshRates();
  }
  }//end while(true)
  //---
  }
  //---
  if((OrderType()==OP_SELL)&&(OrderType()==OrdrType)&&((OrderTicket()==OrdrTicket)||(OrdrTicket==0)))
  {
  WasOrderClosed=false;
  //---
  while(true) 
  {
  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());
  break;
  }
  else
  {
  Print("Error: ",GetLastError()+" || "+EA_Comment+": receives new data and try again close order");
  RefreshRates();
  }
  }//end while(true)
  //---
  }
  } 
  }
  }
  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--) 
  { 
  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)
{
  double ND_Price=0;
  ND_Price = NormalizeDouble(Price,Digits);
  return(ND_Price);
} 
//=================================================================================================================================================//
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(Open_Hour,0)+":"+DelayCom,          
          "\n    End Hour              =  "+DoubleToStr(Close_Hour,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 month_0 = Month();
  int day_4 = Day();
  int day_of_week_8 = DayOfWeek();
  if (day_of_week_8 == 0) day_of_week_8 = 7;
  if (month_0 > 3 && month_0 < 10) return (0);
  if (month_0 > 10 || month_0 < 3) return (1);
  if (month_0 == 3 && 31 - day_4 + day_of_week_8 >= 7) return (1);
  if (month_0 == 10 && 31 - day_4 + day_of_week_8 < 7) return (1);
  return (0);
} 
//=================================================================================================================================================//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Major part of this code was done by maximo @ worldwide-invest.org
int Time_Offset(string site,int location)
{
  string msg1 = "";
  string msg2 = "";
  int HOUR=100;
  int Time_Diff;
  int HttpOpen    = InternetOpenA("HTTP_Test", 0, "", "", 0); 
  int HttpConnect = InternetConnectA(HttpOpen, "", 80, "", "", 3, 0, 1); 
  int HttpRequest = InternetOpenUrlA(HttpOpen, site, NULL, 0, 0, 0);
  Comment ("Looking Time Offset");
  //---
  int read[1];
  string Buffer = "          "; // 10 characters are read at a time 
  string page = "";             // join each 10 onto page string
  int Nchars = 16000; // how many bytes to read to find GMT in HTML source
  //---
  while (true)
  {
  InternetReadFile(HttpRequest, Buffer, StringLen(Buffer), read);
  if (read[0] > 0) page = page + StringSubstr(Buffer, 0, read[0]);
  else break;
  Nchars = Nchars - StringLen(Buffer);
  if (Nchars <= 0) break;  
  }
  //---
  int index=StringFind(page, "Current Date and Time in", 0);  
  if (index > 0) 
  {
  msg1 = StringSubstr(page,index+location,2);  
  msg2 = StringSubstr(page,index+location+6,4);      
  HOUR=StrToInteger(msg1);
  if (HOUR>=0 && HOUR<=11)
  { 
  if (msg2=="A.M.") HOUR=HOUR;
  if (msg2=="P.M.") HOUR=12+HOUR;
  }    
  }
  //---
  if (HttpRequest > 0) InternetCloseHandle(HttpRequest); 
  if (HttpConnect > 0) InternetCloseHandle(HttpConnect); 
  if (HttpOpen > 0) InternetCloseHandle(HttpOpen);
  if (HOUR==100) return (HOUR);
  if (Hour()>=HOUR) Time_Diff=Hour()-HOUR;
  if (Hour()        

Recommend