加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

国外经典早盘EAMomods_Night_Scalper_V3.01_Basic.mq4源码及用法

(2015-06-15 11:29:45)
标签:

外汇交易系统

分类: MT4智能交易系统EA
国外经典早盘EAMomods_Night_Scalper_V3.01_Basic.mq4国内有人俗称午夜黄牛,
eurusd, eurgbp, eurcad, eurchf, gbpusd, gbpchf, gbpcad, usdcad, cadchf,  usdchf.

以上货币全部使用m15图表,GMT_Offset自己计算下自己平台的GMT差。

Fractal_Levels.mq4放入指标文件假,Momods_Night_Scalper_V3.01_Basic.mq4放入EA文件夹。
//-------------------------------
Momods_Night_Scalper_V3.01_Basic.mq4
//-----------------------
////////////////////////////////////////////////////////
//          Momods_Night_Scalper_V3.01_Basic          //
//     Coded by Momods @ worldwide-invest.org         //
//                  April 21, 2013                    //
////////////////////////////////////////////////////////
//        If you make money from this EA              //
//  please make donnation to my paypal Account        //
//              mohddisi@yahoo.com                    //
////////////////////////////////////////////////////////

//V1.3 (March 17, 2013) - Added second condition for Fractals signal
//                      - Added MA Slope filter
//                      - Added settings internally
//
//V1.4 (March 23, 2013) - Fixed a bug in displaying Open/Close hours
//                      - No need to add pair suffix
//                      - Added code to generate master magic number for all pairs based on account number
//                      - Faster back tests
//                      - hide EA name in comments from broker (enter your own)
//                      - Option to hide SL/TP from broker.  Highly dangerous if you are not using VPS.
//                      - Now you can see total profit (loss) for each pair on the display
//                      - Revised settings for several pairs based on optimization
//
//V2.0 (March 31, 2013) - Fixed a bug in calculating trading times for friday
//                      - Added BB to be used either as Signal or filter.
//                      - Added trade spacing time filter (When a trade closes in loss, EA will wait x minutes before opening a same type trade).
//                      - Modified settings for EURCAD, EURGBP, and USDCAD.
//V2.1 (March 31, 2013) - Fixed a bug in calculating trade pause
//V2.2 (April 2, 2013)  - Fixed another bug in session display.
//
//V2.21 (April 14, 2013) - Added Max Spread to externals
//                       - Fixed display bug 
//
//V3.0 (April 21, 2013)  - Added Auto-Timing (EA will determine your broker's GMT Offset automatically).
//                       - Added Daylight Saving Timing (DST) for back testing
//                       - Added maximo's Fractal Level indicator
//                       - Renamed several parameters to remove any confusion
//                       - Added second option to puase trades on loss based on pips from last loss (good for trading on price charts....renko...range..)
//                       - Added RSI indicator as signal/filter
//V3.01 (April 24, 2013) - Limited Auto timing just to get correct GMT Offset.  Use manual GMT offset for trading.


#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  EA_Name= "Momods_Night_Scalper_v3.01_Basic";
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 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;
double  TakeProfit    = 60;
double  StopLoss      = 50;
int     Slippage      = 3;
extern string  C0=" If Max_Spread = 0, EA will use internal settings";
extern double  Max_Spread    = 6.0;
extern string S1="----------------------";
extern bool   Use_Auto_Time = True;
extern int    GMT_Offset     = 0;
extern bool   UseDST = FALSE;
int    Open_Hour      = 20;
int    Close_Hour     = 23;
bool   TradeOnFriday  = False;
int    Friday_Hour    =15;
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;
string S4="----------------------";
bool   Use_CCI        = False;
int    CCI_Period     = 10;
double CCI_Entry      = 200;
double CCI_Exit       = 140;
string S5="----------------------";
bool   Use_WPR        = true;
int    WPR_Period     = 10;
double WPR_Entry      = 91;
double WPR_Exit       = 40;
string S6="----------------------";
bool   Use_RSI        = false;
int    RSI_Period     = 70;
double RSI_Entry      = 50;
string S7="----------------------";
bool   Use_Fractals   = true;
double MidFractalDist = 5;
double OppositFractalDist=10;
extern bool   Show_Fractal_Levels=False;
string S8="----------------------";
bool   Use_MA_Dist   = false;
double MA_Dist_Period = 4;
string Mode="0= Simple, 1= Exponential, 2= Smoothed, 3= Linear Weighted";
double MA_Dist_Mode=1;
double Dist_to_MA =4;
string S9="----------------------";
bool   Use_MA1         = False;
int    MA_Period1      = 75;
string Mode1="0= Simple, 1= Exponential, 2= Smoothed, 3= Linear Weighted";
int    MA_Mode1        = 3;
bool   Use_MA2         = False;
int    MA_Period2      = 19;
string Mode2="0= Simple, 1= Exponential, 2= Smoothed, 3= Linear Weighted";
int    MA_Mode2        = 3;
bool   Use_MA2_Slope   = False;
double MA_Slope       = 1;
string S10="----------------------";
bool   Use_BB         = False;
int    BB_Period      = 10;
int    BB_Dev         = 2;
int    BB_Range       = 12;
int    BB_Penetration = 2;
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[];
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 init() {


//-----------------------------------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);
      //GMT_Diff= Time_Offset(site2,70);
      //if (NY_Diff==100 || GMT_Diff==100)     
      if (NY_Diff==100)
      {
      Alert("Cant Get Auto Timing.  Please use Manual GMT Offset");
      return(0);
      }
   }
 
   if (DST()==0) GMT_Offset=NY_Diff-4;
   if (DST()==1) GMT_Offset=NY_Diff-5;  
   //Print("GMT_Diff = ",GMT_Diff);
   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;
 if (StringSubstr(Symbol(),0,6)=="EURCAD")  {
 Magic=MAGIC+1;if(Max_Spread==0)Max_Spread=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")  {
 Magic=MAGIC+2;if(Max_Spread==0)Max_Spread=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")  {
 Magic=MAGIC+3;if(Max_Spread==0)Max_Spread=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")  {
 Magic=MAGIC+4;if(Max_Spread==0)Max_Spread=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")  {
 Magic=MAGIC+5;if(Max_Spread==0)Max_Spread=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")  {
 Magic=MAGIC+6;if(Max_Spread==0)Max_Spread=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") 
 Magic=MAGIC+7;if(Max_Spread==0)Max_Spread=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") 
 Magic=MAGIC+8;if(Max_Spread==0)Max_Spread=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)=="CADJPY") Magic=MAGIC+9;
 
 if (StringSubstr(Symbol(),0,6)=="GBPJPY") Magic=MAGIC+10;
 
 if (StringSubstr(Symbol(),0,6)=="CADCHF") {
 Magic=MAGIC+11;if(Max_Spread==0)Max_Spread=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") { 
 Magic=MAGIC+12;if(Max_Spread==0)Max_Spread=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;}
 
 
 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;
 
   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;   
 
   return (0);
}


int deinit() {
   return (0);
}

// EA Start

int start() {



//////////////////////////////////// Trade Timing ///////////////////////////////////////////////    

   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 (Month()==12 && Day()>22)  Trade = FALSE;
   if (Month()==1 && Day()<5)  Trade = FALSE;
  
   if (Trade && MyRealOrdersTotal(Magic)==0 && !Allow_Second_Open_Trade && Spread()
   if (Trade && MyRealOrdersTotal(Magic)==0 && Spread()
   if (Trade && MyRealOrdersTotal(Magic)==0 && (Spread()>Max_Spread*PointValue()|| (Ask-Bid)>Max_Spread*PointValue())) Session="Trade Session Open .. Spread is High .. Trading Halted";
   if (Trade && MyRealOrdersTotal(Magic)>0 && (Spread()>Max_Spread*PointValue()|| (Ask-Bid)>Max_Spread*PointValue())) Session="Trade Session Open..Waiting to exit trades..Trading Halted";
   if (Trade && MyRealOrdersTotal(Magic)>0 && (Spread()
   if (!Trade && MyRealOrdersTotal(Magic)==0) Session="Trade Session Closed";
   if (!Trade && MyRealOrdersTotal(Magic)>0) Session="Trade Session Closed .. Waiting to exit trades";
  
////////////////////////////  Add Disply /////////////////////////////

   if (!IsTesting() && !IsOptimization())
   {
      Display();
      if (Show_Fractal_Levels) iCustom(NULL,0,"Fractal_Levels",MidFractalDist,OppositFractalDist,0,0);
   }
  
////////////////////   Calculate Average Spread  /////////////////////
 
    if (!IsTesting() && !IsOptimization()) Spread(Ask-Bid);
   
/////////////////////////////  Indicator(s) /////////////////////////
    
  if (Trade || OrdersTotal()>0)
  {
     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 (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);        

     if (Use_Fractals)
      
        for(int a=1;a
         if(iFractals(NULL, 0, MODE_UPPER,a)!=0){
            LastUpFractal=iFractals(NULL, 0, MODE_UPPER,a);
            break;
            }
         }
        for(int s=1;s
         if(iFractals(NULL, 0, MODE_LOWER,s)!=0){
            LastDownFractal=iFractals(NULL, 0, MODE_LOWER,s);
            break;
            }
         }

        midFractal=(LastUpFractal+LastDownFractal)/2;
     }
  
    

//////////////////////////////////// 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 (!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_1
   if (Use_MA2 && MA_2_1>MA_2_2)  MA_Buy_Sig2=1;  
   if (Use_MA2 && MA_2_1
   if (Use_MA2_Slope && (MA_2_1-MA_2_2)>=MA_Slope*PointValue())  MA_Slope_Buy_Sig=1;  
   if (Use_MA2_Slope && (MA_2_2-MA_2_1)>=MA_Slope*PointValue())  MA_Slope_Sell_Sig=1;         
   if (Use_Fractals && Ask<(midFractal-MidFractalDist*PointValue()) && Ask<(LastUpFractal-OppositFractalDist*PointValue())) Fractals_Buy_Sig=1;   
   if (Use_Fractals && Bid>(midFractal+MidFractalDist*PointValue()) && Bid>(LastDownFractal+OppositFractalDist*PointValue())) Fractals_Sell_Sig=1;
   if (Use_BB && !Use_BB_Direction && AskBB_Range*PointValue() && BB_L_1-Ask>=BB_Penetration*PointValue()) BB_Buy_Sig=1;
   if (Use_BB && !Use_BB_Direction && Bid>BB_U_1 && (BB_U_1-BB_L_1)>BB_Range*PointValue() && Bid-BB_U_1>=BB_Penetration*PointValue()) BB_Sell_Sig=1;     
   if (Use_BB && Use_BB_Direction && AskBB_Range*PointValue() && BB_L_1-Ask>=BB_Penetration*PointValue() && 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*PointValue() && Bid-BB_U_1>=BB_Penetration*PointValue() && BB_U_1
   if (Trade_Pause_On_Loss && Pause_Type==1 && LastClosedType(Magic)==0 && LastClosedProfit(Magic)<0 && (Time[0]-LastClosedTime(Magic))
   if (Trade_Pause_On_Loss && Pause_Type==1 && LastClosedType(Magic)==1 && LastClosedProfit(Magic)<0 && (Time[0]-LastClosedTime(Magic))
   if (Trade_Pause_On_Loss && Pause_Type==2 && LastClosedType(Magic)==0 && LastClosedPrice(Magic)-Ask
   if (Trade_Pause_On_Loss && Pause_Type==2 && LastClosedType(Magic)==1 && Bid-LastClosedPrice(Magic)
   if (Use_MA_Dist && Bid-MA_3_1>=Dist_to_MA*PointValue())  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;         
  
   if (!Use_CCI  && !Use_WPR && !Use_Fractals) {Print("You must use at least one signal (CCI, WPR, or Fractals"); return(0);}
  
//////////////////////////////////// Exit Signals ///////////////////////////////////////////////     

   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 (OrdersTotal()>0)
  {
    for(int k=0; k
       
       bool cg = OrderSelect(k, SELECT_BY_POS, MODE_TRADES);     
       if(OrderType()==OP_BUY &&   OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && (CCI_Exit_Buy_Sig==1 || WPR_Exit_Buy_Sig==1)
           && Spread()
                     
         //OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
         CloseAll(Magic);
                                 
       }
      
       if(OrderType()==OP_SELL &&   OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && (CCI_Exit_Sell_Sig==1 || WPR_Exit_Sell_Sig==1)
           && Spread()
                     
          //OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
          CloseAll(Magic);                
                        
       }
   

    for(k=0; k
       
       cg = OrderSelect(k, SELECT_BY_POS, MODE_TRADES);     
       if(OrderType()==OP_BUY &&   OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && ((Ask-OrderOpenPrice())>=TakeProfit*PointValue()  || (OrderOpenPrice()-Ask)>=StopLoss*PointValue()))
                     
         cg = OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
         //CloseAll(Magic);
                                 
       }
      
       if(OrderType()==OP_SELL &&   OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && ((OrderOpenPrice()-Bid)>=TakeProfit*PointValue()  || (Bid-OrderOpenPrice())>=StopLoss*PointValue()))
                     
          cg = OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
          //CloseAll(Magic);                
                        
       }
    }
   
 

//////////////////////////////////// Open Trade ///////////////////////////////////////////////   
      
   if (New_Trade && Spread()
       && CCI_Buy_Sig==1 && WPR_Buy_Sig==1 && MA_Buy_Sig1==1 && MA_Buy_Sig2==1&& MA_Slope_Buy_Sig==1 && Fractals_Buy_Sig==1 && BB_Buy_Sig==1 && Trade_Pause_Buy_Sig==1
       && MA_Dist_Buy_Sig==1 && RSI_Buy_Sig==1)
   {

        Lot=CalculateLots(Risk);


        int 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 (New_Trade && Spread()
       && CCI_Sell_Sig==1 && WPR_Sell_Sig==1 && MA_Sell_Sig1==1 && MA_Sell_Sig2==1&& MA_Slope_Sell_Sig && Fractals_Sell_Sig==1 && BB_Sell_Sig==1 && Trade_Pause_Sell_Sig==1
       && MA_Dist_Sell_Sig==1 && RSI_Sell_Sig==1)
   {

        Lot=CalculateLots(Risk);


        int 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();
         }
   
           

//////////////////////////////////// Second Trade ///////////////////////////////////////////////   
      
   if (MyRealOrdersTotal(Magic)==1  && Allow_Second_Open_Trade && Time[0]!=Last_Time && Trade_Pause_Buy_Sig==1 && Trade_Pause_Buy_Sig==1 && LastOpenType()==0 && Ask<=(LastBuyPrice()-Distance*PointValue()))
 
   {
        Lot=CalculateLots(Risk*Lot_Factor);

        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 (MyRealOrdersTotal(Magic)==1  && Allow_Second_Open_Trade && Time[0]!=Last_Time && Trade_Pause_Sell_Sig==1 && Trade_Pause_Sell_Sig==1 && LastOpenType()==1 && Bid>=(LastSellPrice()+Distance*PointValue()))
   {

        Lot=CalculateLots(Risk*Lot_Factor);

        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   (!Hide_SL_TP && MyRealOrdersTotal(Magic)>0) ModifyAll();    // Double check to make sure all trades have TP and SL         
  
   return (0);
}

// EA End

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

int MyRealOrdersTotal(int)
{
  int c=0;
  int total  = OrdersTotal();
 
  for (int cnt = 0 ; cnt < total ; cnt++)
  {
    bool cg = OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol() && OrderType()<=OP_SELL)
    {
      c++;
    }
  }
  return(c);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

double LastSellPrice()
{
   double l_ord_open_price_8=0;
   int l_ticket_24;
   double ld_unused_0 = 0;
   int l_ticket_20 = 0;
   for (int l_pos_16 = OrdersTotal() - 1; l_pos_16 >= 0; l_pos_16--) {
      bool cg = OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL) {
         l_ticket_24 = OrderTicket();
         if (l_ticket_24 > l_ticket_20) {
            l_ord_open_price_8 = OrderOpenPrice();
            ld_unused_0 = l_ord_open_price_8;
            l_ticket_20 = l_ticket_24;
         }
      }
   }
   return (l_ord_open_price_8);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////

double LastBuyPrice()
{
   double l_ord_open_price_8=0;
   int l_ticket_24=0;
   double ld_unused_0 = 0;
   int l_ticket_20 = 0;
   for (int l_pos_16 = OrdersTotal() - 1; l_pos_16 >= 0; l_pos_16--) {
      bool cg = OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY ) {
         l_ticket_24 = OrderTicket();
         if (l_ticket_24 > l_ticket_20) {
            l_ord_open_price_8 = OrderOpenPrice();
            ld_unused_0 = l_ord_open_price_8;
            l_ticket_20 = l_ticket_24;
         }
      }
   }
   return (l_ord_open_price_8);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int LastOpenType()
{
   int l_ord_type=-1;
   int l_ticket_24=0;
   double ld_unused_0 = 0;
   int l_ticket_20 = 0;
   for (int l_pos_16 = OrdersTotal() - 1; l_pos_16 >= 0; l_pos_16--) {
      bool cg = OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() <= OP_SELL) {
         l_ticket_24 = OrderTicket();
         if (l_ticket_24 > l_ticket_20) {
            l_ord_type = OrderType();
            ld_unused_0 = l_ord_type;
            l_ticket_20 = l_ticket_24;
         }
      }
   }
   return (l_ord_type);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////

int CloseAll(int)
{
   for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--)
   {
      bool cg = OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderCloseTime()==0)
      {
            if(OrderType()==OP_BUY)  cg = OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue);
            if(OrderType()==OP_SELL) cg = OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red);
      }
   }
   return(0);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

double CalculateLots(double RISK)
{
   int Lot_Dec;
   double l_minlot_0 = MarketInfo(Symbol(), MODE_MINLOT);
   double l_maxlot_8 = MarketInfo(Symbol(), MODE_MAXLOT);
   double ld_ret_16 = 0.0;
   if (MarketInfo(Symbol(), MODE_MINLOT) < 1.0) Lot_Dec = 1;
   if (MarketInfo(Symbol(), MODE_MINLOT) < 0.1) Lot_Dec = 2;
   if (MarketInfo(Symbol(), MODE_MINLOT) < 0.01) Lot_Dec = 3;
   if (MarketInfo(Symbol(), MODE_MINLOT) < 0.001) Lot_Dec = 4;
   if (MarketInfo(Symbol(), MODE_MINLOT) < 0.0001) Lot_Dec = 5;
   if (lot > 0.0) {ld_ret_16 = lot;return (ld_ret_16);}
   if (ld_ret_16 == 0.0)
   {
      ld_ret_16=NormalizeDouble(AccountBalance() / 100000.0 * RISK, Lot_Dec);
      if (ld_ret_16 < l_minlot_0) ld_ret_16 = l_minlot_0;
      if (ld_ret_16 > l_maxlot_8) ld_ret_16 = l_maxlot_8;
   }
         return (ld_ret_16);
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

double PointValue() {
   if (MarketInfo(Symbol(), MODE_DIGITS) == 5.0 || MarketInfo(Symbol(), MODE_DIGITS) == 3.0) return (10.0 * Point);
   return (Point);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void ModifyAll()
{
   for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--)
   {
      bool cg = OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic )
      {
         if (OrderStopLoss()==0 || OrderTakeProfit()==0)
        
            {
               if((OrderType()==OP_BUY))
               cg = OrderModify(OrderTicket(),OrderOpenPrice(),ND(OrderOpenPrice()-PointValue()*StopLoss), ND(OrderOpenPrice()+TakeProfit*PointValue()),0,Green);
               if((OrderType()==OP_SELL))
               cg = OrderModify(OrderTicket(),OrderOpenPrice(),ND(OrderOpenPrice()+PointValue()*StopLoss), ND(OrderOpenPrice()-TakeProfit*PointValue()),0,Red);
            
      }
   }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

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 );
//   Print("ArraySize = ",ArraySize(lSpread)," AddedNo. = ",AddValue);
   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()
{

  
   Comment(
            "\n*=====================*",  
            "\n    "+EA_Name,
            "\n*=====================*",
            "\n   "+Session,
            "\n*=====================*",
            "\n    Broker Time          ", TimeToStr(TimeCurrent(), TIME_MINUTES),
            "\n    Start Hour             "+DoubleToStr(Open_Hour,2),         
            "\n    End Hour              "+DoubleToStr(Close_Hour,2),
            "\n",                       
            "\n    Magic Number       = "+Magic,
            "\n    Maximum Spread   = "+DoubleToStr(Max_Spread,1),
            "\n    Average Spread    = "+DoubleToStr(Spread()/PointValue(),1),
            "\n    Lot size                 " +DoubleToStr(CalculateLots(Risk),2),
            "\n    Stop Loss              = "+DoubleToStr(StopLoss,0),

            "\n*=====================*",                                                           
            "\n    Total Profit (Loss)     = "+DoubleToStr(TotalProfit()+Profit(),2),
                                               
            "\n*=====================*",
            "\n    B A L A N C E        " + DoubleToStr(AccountBalance(),2),
            "\n    E Q U I T Y           " + DoubleToStr(AccountEquity(),2),
            "\n    Leverage                " + DoubleToStr(AccountLeverage(),2),           
            "\n*=====================*"
           
             );
            
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

double TotalProfit()
{
  double profit = 0;
 
  int cnt = OrdersHistoryTotal();
  for (int i=0; i < cnt; i++) {
    if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
 
    if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) profit += OrderProfit();
  }
 
  return (profit);
  

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

double Profit()
{
  int c=0;
  int total  = OrdersTotal();
  double Profit=0;
 
  for (int cnt = 0 ; cnt < total ; cnt++)
  {
    bool cg = OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if (OrderMagicNumber() == Magic && OrderType()<=OP_SELL)
    {
      Profit=Profit+OrderProfit();
    }
   
  }
  
  return(Profit);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int LastClosedType(int) {

   int xyz=OrdersHistoryTotal() - 2;
   if (!IsTesting() && !IsOptimization()) xyz=0;
   int l_ord_type=-1;
   int l_ticket_24=0;
   double ld_unused_0 = 0;
   int l_ticket_20 = 0;
   for (int l_pos_16 = OrdersHistoryTotal() - 1; l_pos_16 >= xyz; l_pos_16--) {
      bool cg = OrderSelect(l_pos_16, SELECT_BY_POS, MODE_HISTORY);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() <= OP_SELL) {
         l_ticket_24 = OrderTicket();
         if (l_ticket_24 > l_ticket_20) {
            l_ord_type = OrderType();
            ld_unused_0 = l_ord_type;
            l_ticket_20 = l_ticket_24;
         }
      }
   }
   return (l_ord_type);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

double LastClosedProfit(int) {

   int xyz=OrdersHistoryTotal() - 2;
   if (!IsTesting() && !IsOptimization()) xyz=0;
   double l_ord_profit=0;
   int l_ticket_24=0;
   double ld_unused_0 = 0;
   int l_ticket_20 = 0;
   for (int l_pos_16 = OrdersHistoryTotal() - 1; l_pos_16 >= xyz; l_pos_16--) {
      bool cg = OrderSelect(l_pos_16, SELECT_BY_POS, MODE_HISTORY);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() <= OP_SELL) {
         l_ticket_24 = OrderTicket();
         if (l_ticket_24 > l_ticket_20) {
            l_ord_profit = OrderProfit();
            ld_unused_0 = l_ord_profit;
            l_ticket_20 = l_ticket_24;
         }
      }
   }
   return (l_ord_profit);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

double LastClosedPrice(int) {

   int xyz=OrdersHistoryTotal() - 2;
   if (!IsTesting() && !IsOptimization()) xyz=0;
   double l_ord_price=0;
   int l_ticket_24=0;
   double ld_unused_0 = 0;
   int l_ticket_20 = 0;
   for (int l_pos_16 = OrdersHistoryTotal() - 1; l_pos_16 >= xyz; l_pos_16--) {
      bool cg = OrderSelect(l_pos_16, SELECT_BY_POS, MODE_HISTORY);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() <= OP_SELL) {
         l_ticket_24 = OrderTicket();
         if (l_ticket_24 > l_ticket_20) {
            l_ord_price = OrderClosePrice();
            ld_unused_0 = l_ord_price;
            l_ticket_20 = l_ticket_24;
         }
      }
   }
   return (l_ord_price);
}
  
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

datetime LastClosedTime(int) {

   int xyz=OrdersHistoryTotal() - 2;
   if (!IsTesting() && !IsOptimization()) xyz=0;
   datetime l_ord_time=0;
   int l_ticket_24=0;
   datetime ld_unused_0 = 0;
   int l_ticket_20 = 0;
   for (int l_pos_16 = OrdersHistoryTotal() - 1; l_pos_16 >= xyz; l_pos_16--) {
      bool cg = OrderSelect(l_pos_16, SELECT_BY_POS, MODE_HISTORY);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() <= OP_SELL) {
         l_ticket_24 = OrderTicket();
         if (l_ticket_24 > l_ticket_20) {
            l_ord_time = OrderCloseTime();
            ld_unused_0 = l_ord_time;
            l_ticket_20 = l_ticket_24;
         }
      }
   }
   return (l_ord_time);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

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,location+3,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()
  
   return (Time_Diff);
  
  
     

//-------------------------------------
用到的指标Fractal_Levels.mq4
//-----------------------
//+----------------------------------------------------------------+
//|                                             Fractal Levels.mq4 |
//|                                                         Maximo |
//+----------------------------------------------------------------+
#property copyright "Copyright ?2013"
#property link      "Maximo"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Gray
#property indicator_color2 Gray
#property indicator_width1 1
#property indicator_width2 1
double UpperFr[];
double LowerFr[];

extern double MidFractalDist = 6;
extern double OppFractalDist = 11;
extern color  Line1col = Green;
extern color  Line2col = Red;
extern color  Line3col = DarkGreen;
extern color  Line4col = DarkOrange;
double        PointValue;
int           refreshtime;

int init()
{
   if (Digits <= 3) PointValue = 0.01; else PointValue = 0.0001;
   SetIndexBuffer(0, UpperFr);
   SetIndexBuffer(1, LowerFr);
   SetIndexEmptyValue(0, 0);
   SetIndexEmptyValue(1, 0);
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexArrow(0, 217);
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(1, 218);
   return(0);
}

int deinit()
{
   for (int i = 1; i <= 4; i++) ObjectDelete("Line" + i);
   Comment("");
   return(0);
}

int start()
{
   int counted=IndicatorCounted();
   if (counted < 0) return(-1);
   if (counted > 0) counted--;
   int limit=Bars-counted;

   if (refreshtime != iTime(Symbol(),PERIOD_M15,0))
   {
      refreshtime = iTime(Symbol(),PERIOD_M15,0);
      for (int i = 1; i <= 4; i++) ObjectDelete("Line" + i);
   }
   else return(0);  

   double dy;
   for(i=1; i<=20; i++)
   {
      dy+=0.2*(High[i]-Low[i])/20;
      UpperFr[i]=0; LowerFr[i]=0;
   }
   for(int a=1; a
   {
      if(iFractals(NULL, 0, MODE_UPPER,a)!=0)
      {
         double LastUpFractal=iFractals(NULL, 0, MODE_UPPER,a);
         datetime FracUpTime =iTime(Symbol(),PERIOD_M15,a);
         UpperFr[a]=High[a] + dy;
         break;
      }
   }
   for(int s=1; s
   {
      if(iFractals(NULL, 0, MODE_LOWER,s)!=0)
      {
         double LastDownFractal=iFractals(NULL, 0, MODE_LOWER,s);
         datetime FracDownTime =iTime(Symbol(),PERIOD_M15,s);
         LowerFr[s]=Low[s] - dy;
         break;
      }
   }
   datetime FracTime;
   if (FracUpTime < FracDownTime) FracTime = FracUpTime;
   else FracTime = FracDownTime;
  
   double midFractal=NormalizeDouble((LastUpFractal+LastDownFractal)/2,Digits);
   double price1 = LastUpFractal-OppFractalDist*PointValue;
   double price2 = LastDownFractal+OppFractalDist*PointValue;
   double price3 = midFractal-MidFractalDist*PointValue;
   double price4 = midFractal+MidFractalDist*PointValue;
  
   ObjectCreate("Line1", OBJ_TREND, 0, FracTime, price1, TimeCurrent(), price1);
   ObjectSet("Line1",OBJPROP_COLOR,Line1col);
   ObjectSet("Line1",OBJPROP_BACK,True);
   ObjectCreate("Line2", OBJ_TREND, 0, FracTime, price2, TimeCurrent(), price2);
   ObjectSet("Line2",OBJPROP_COLOR,Line2col);
   ObjectSet("Line2",OBJPROP_BACK,True);
   ObjectCreate("Line3", OBJ_TREND, 0, FracTime, price3, TimeCurrent(), price3);
   ObjectSet("Line3",OBJPROP_COLOR,Line3col);
   ObjectSet("Line3",OBJPROP_BACK,True);
   ObjectCreate("Line4", OBJ_TREND, 0, FracTime, price4, TimeCurrent(), price4);
   ObjectSet("Line4",OBJPROP_COLOR,Line4col);
   ObjectSet("Line4",OBJPROP_BACK,True);

   return(0);
}

//----------------------指标结束------------------

附言:官方附带英文说明如下:
Update April 21, 2013:

New release Momods_Night_Scalper_V3.0

I'm pleased to release new version of my Night Scalper EA.

Main Features/Modifications:

- Auto-Timing (EA will determine your broker's GMT Offset automatically). No need to enter your GMT_offset. The EA will get time at New York from a webpage and compare it with your broker's server time to determine GMT Offset. This option is True by default. Thanks to maximo for providing the code. You still need to enter your GMT offset manually during back test.

- Added Daylight Savings Time (DST). This option for back testing only. If your broker uses DST or you enabled DST when creating your FXT data file, please set this option to True during back test. No need to generate a new FXT file without DST to back test this EA. Please don't enable this option during live or demo trading.

- Added maximo's Fractal Level indicator. If you enable Show_Fractal_Levels, fractal levels will be displayed on your chart so you can watch entry levels. You need to download and add Fractal Levels indicator to your Indicators folder.

- Renamed some parameters to remove any confusion:
Trade_Spacing becomes Trade_Pause_On_Loss
Allow_Second_Trade becomes Allow_Second_Open_Trade


- Added another option for Trade Pause on Loss. Instead of pausing for a certain number of minutes, now you can pause trading based on price movement. To open another buy trade after loss, price must go lower for x pips. To open another Sell trade after loss, price must go higher by x pips. This is good option for those testing price charts ...renko.. range...) .

- Added RSI indicator as an extra filter in the Pro version. To open Buy trade, RSI must be higher than RSI_Entry and to open Sell trade, RSI must be lower than RSI_Entry.

Internal Settings for all pairs in the Basic Version are not changed. It is exactly the same as previous version.

As in any new release, please use on demo account only. It might contain bugs.

Update April 2, 2013

New modified version Momods_Night_Scalper_v2.2

This release contains the two usual versions : Basic and Pro.

- Fixed a bug in showing session status in the display.

Update March 31, 2013

"Momods_Night_Scalper_v2.1"

I'm pleased to release new version of my Night Scalper EA. As usual, we will have two versions: Basic and Pro. For more information about EA installation, pairs, TFs, ... etc, please refer to post #1 of this thread.

I spent the last few days coding and testing a new exit strategy based on decreasing profit with time. The aim was to decrease the number of trades that end with small loss and trying to exit with small profit or break-even instead. The results of my several tests were not encouraging at all. There were big difference in net profit compared to existing strategy. Using WPR and/or CCI for exit proved to be the best. Although you will have several small losses, but it will save you from many exits at full stop loss. Also, it allows you to follow trend for larger profit.

Main fixes/modifications:

- fixed the bug related to Thursday/Friday trading session.

- added Bollinger Bands as new signal/filter. BB can be used alone as primary entry signal or as a filter with other signals like WPR and CCI. I did not have enough time to test BB for different pairs. Therefore, the built-in settings in basic version don't use this filter yet.

- added trade pause after loss. If a trade ended in loss, the EA will not open a similar trade until x minutes has passed. This is to prevent multiple full SL as a result of sudden strong trend. This filter is set to false by default as if might reduce number of trades. It's up to the user to set it on/off.

- Modified built-in settings in Basic version for three pairs (EURCAD, EURGBP, and USDCAD). The modifications included increasing SL to 60 pips as it will improve both net profit and relative draw down (RDD).
//------安装说明-------------
Setup Procedure:

- Open 10 charts for the following pairs:
eurusd, eurgbp, eurcad, eurchf, gbpusd, gbpchf, gbpcad, usdcad, cadchf, and usdchf.
- change TF to M15 for all charts except EURUSD which should be M30.
- attach Momods_Night_Scalper_v3.0_Basic to each chart.
- make sure that DLL imports are allowed.
- the EA will automatically adjust to your broker's GMT offset.
- You are done and ready for trading.

For the Pro's, a Pro version is attached with all parameters in the externals. You need to put max spread for each pair, put your GMT offset, and for EURUSD you need to insert the attached set file.


Quick remarks:

- Second trade is disabled by default. If you enable this feature, you need to use proper money management. I recommend lowering risk to 5-7%. Enabling second trade might increase profit, but it will increase DD as well.

- I don't recommend trading any JPY, AUD, or NZD pair due to the opening of these markets.

- I don't recommend trading outside default trading hours (20-23 GMT). You might get good results for a short while, but it's not good in the long term.

- Please don't use on your live account. There were lots of changes and there might be some bugs. Let's demo test it first.


0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有