Lucky1.3.a





//+-----------------------------------------------------------------------------------+
//|                                                                 Lucky.v.1.2.1.mq4 |
//|                                              Copyright © 2007 Serg_ASV & ak97052d |
//|                                                  http://codebase.mql4.com/ru/1555 |
//|       http://www.forex-tsd.com/expert-advisors-metatrader-4/10366-lucky1-1-a.html |
//|                                                                                   |
//| 10.10.2007  v.1     by Serg_ASV (...)                                             |
//| 25.10.2007  v.1.1   by ak97052d (WeekEndStop/TradingTime/MM/MicroLot)             |   
//| 26.10.2007  v.1.2   by ak97052d (MagicNumber/Slippage/DiferentTradingTimeByChart) |
//|                                 [EURGBP][EURCHF][GBPCHF][USDCAD]                  |
//| 28.10.2007  v.1.2.1 by ak97052d (some correctrion/[GBPCHF][USDCAD]removed)        |
//| 29.10.2007  v.1.3.a by ak97052d (DetectBrokerGTM/GTM-TradingTime/PersoSetting)    |
//| --.--.----  v.1.3   by -------- (GTM-WeekEndStop)                                 |
//+-----------------------------------------------------------------------------------+ :p

#property copyright "Copyright © 2007, Serg_ASV & ak97052d"
#property link      "http://codebase.mql4.com/ru/1555"
#import "WebGet.dll"
   string forextsd_com_webget(string Url);
#import

extern bool    MM                = true;    // Money management
extern int     Risk              = 1;     // Percent(%). minimum '1' maximum '100' 
extern double  ManLot            = 0.1;     // Malual lot size (if 'MM=False')
extern string  AutoSetting       = "To use AutoSetting (EURGBP EURCHF), put \'UseAutoSetting=true\'";
extern bool    UseAutoSetting    = true; // if 'false', 'PersoMagic' 'PersoOpenHour' and 'PersoCloseHour' will be used. 
//------PersoSetting------
extern string  PersoSetting      = "To use PersoSetting put \'UseAutoSetting=false\'";
extern int     PersoShift        = 3;
extern int     PersoMagic        = 291007;
extern int     PersoOpenHour     = 19;
extern int     PersoCloseHour    = 7;
extern int     PersoLimit        = 18;
extern int     PersoTP           = 2;
//-------WeekEndStop------
int            WED1              = 5;    // Day of begin
int            WEH1              = 22;   // Hour of begin
int            WED2              = 1;    // Day of end
int            WEH2              = 2;    // hour of end
//----------------------------------------------------------------------------
bool first=true,fTime; int TradingTime,WE,OpenHour,CloseHour,Shift,Limit,TP,TimeZone,Slippage=3,LotsDigit=1,Magic=0; double a,b,TV,SP; 
int init()
   {
   if (UseAutoSetting==true)
      {
      if (Symbol()=="EURGBPm" || Symbol()=="EURGBP") { Magic=1001; OpenHour=18; CloseHour=6; Shift=3; Limit=18; TP=2; }
      if (Symbol()=="EURCHFm" || Symbol()=="EURCHF") { Magic=1010; OpenHour=18; CloseHour=6; Shift=4; Limit=17; TP=2; }
// add here other chart config
//    if (Symbol()=="EURUSDm" || Symbol()=="EURUSD") { Magic=1011; OpenHour=xx; CloseHour=x; Shift=x; Limit=xx; TP=x; }
      if (Magic==0) { Magic=1000; OpenHour=19; CloseHour=7; Shift=4; Limit=17; TP=2; } 
      }
   else 
      {
      Magic=PersoMagic; OpenHour=PersoOpenHour; CloseHour=PersoCloseHour; Shift=PersoShift; Limit=PersoLimit; TP=PersoTP;
      }
   fTime = true;
   return(0);
   }
///////////////////////////////////////////////////////////
int start()
   {
   if (IsTesting()) TimeZone = 0; else { datetime cTime = iTime(NULL,PERIOD_W1,0); string gmt = forextsd_com_webget("http://calendar.forex-tsd.com/gmt.php"); if(gmt!="") datetime gmtime = StrToTime(gmt); else return(0); int tz = NormalizeDouble((TimeCurrent() - gmtime)/3600.0,0); if ( tz < 24) TimeZone = tz; } int OHTZ=OpenHour+TimeZone,ohtz; int CHTZ=CloseHour+TimeZone,chtz; if (OHTZ>=24) ohtz=OHTZ-24; if (OHTZ<24 && OHTZ>=0) ohtz=OHTZ; if (OHTZ<0) ohtz=OHTZ+24; if (CHTZ>=24) chtz=CHTZ-24; if (CHTZ<24 && CHTZ>=0) chtz=CHTZ; if (CHTZ<0) chtz=CHTZ+24;
   if (WEstop()==0)
      {
      if ((ohtz>chtz && (TimeHour(TimeCurrent()) >= ohtz || TimeHour(TimeCurrent())< chtz)) || (ohtz<chtz && (TimeHour(TimeCurrent()) >= ohtz && TimeHour(TimeCurrent())< chtz)))
         {
         if (first) { a=Ask; b=Bid; first=false; return(0); }
         if (Ask-a>=Shift*Point) { OrderSend(Symbol(),OP_SELL,GetLots(),Bid,Slippage,0,0,"Lucky"+Symbol(),Magic,0,Red); }  
         if (b-Bid>=Shift*Point) { OrderSend(Symbol(),OP_BUY,GetLots(),Ask,Slippage,0,0,"Lucky"+Symbol(),Magic,0,Blue); } 
         }
      }
   a=Ask; b=Bid; 
   CloseAll(); 
   return(0);
   }
///////////////////////////////////////////////////////////
int WEstop() // need GTMdetect too (Lucky.1.3.b)
   {
   WE=0;
   if (TimeHour(TimeCurrent()) > WEH1 && DayOfWeek() == WED1) WE=1;
   if (TimeHour(TimeCurrent()) < WEH2 && DayOfWeek() == WED2) WE=2;
   return(WE);
   }
//-------------------------------------------------------------------------- 
void CloseAll() { for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber()==Magic) { int OHTZ=OpenHour+TimeZone,ohtz; int CHTZ=CloseHour+TimeZone,chtz; if (OHTZ>=24) ohtz=OHTZ-24; if (OHTZ<24 && OHTZ>=0) ohtz=OHTZ; if (OHTZ<0) ohtz=OHTZ+24; if (CHTZ>=24) chtz=CHTZ-24; if (CHTZ<24 && CHTZ>=0) chtz=CHTZ; if (CHTZ<0) chtz=CHTZ+24; if (SecurProfit()==1 || ((ohtz>chtz && (TimeHour(TimeCurrent()) < ohtz && TimeHour(TimeCurrent())>= chtz)) || (ohtz<chtz && (TimeHour(TimeCurrent()) < ohtz || TimeHour(TimeCurrent())>= chtz)))) { if(OrderType()==OP_BUY)  OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue); if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red); } else { if((OrderType()==OP_BUY) && (((OrderOpenPrice()-Ask)/Point) > Limit)) OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue); if((OrderType()==OP_SELL) && (((Bid-OrderOpenPrice())/Point) > Limit)) OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red); } } } } 
double GetLots() { double lots,MD,RM,FMM,MinLot,MaxLot; int lotsdigit; MD = NormalizeDouble(MarketInfo(Symbol(), MODE_LOTSTEP),2); RM = NormalizeDouble(MarketInfo(Symbol(), MODE_MARGINREQUIRED),4); FMM = (RM)*100; if (MD==0.01) lotsdigit=2; else lotsdigit=1; LotsDigit=lotsdigit; if (MM==true) lots = NormalizeDouble(AccountFreeMargin()/(FMM/Risk)-0.05,LotsDigit); else lots=ManLot; MinLot=NormalizeDouble(MarketInfo(Symbol(),MODE_MINLOT),2); MaxLot=NormalizeDouble(MarketInfo(Symbol(), MODE_MAXLOT),2); if (LotsDigit == 2) MinLot = 0.01; if (lots < MinLot) lots = MinLot; if (lots > MaxLot) lots = MaxLot; return (lots); }
double TickValue() { double tv; tv = NormalizeDouble(MarketInfo(Symbol(), MODE_TICKVALUE),4); return(tv); }
int SecurProfit() { int sp=0; if (OrderProfit()>(TickValue()*GetLots()*TP)) sp=1; return(sp); }
   
   
   
   
   
   
   



Sample





Analysis



Market Information Used:



Indicator Curves created:


Indicators Used:



Custom Indicators Used:
WebGet

Order Management characteristics:
It automatically opens orders when conditions are reached
It Closes Orders by itself

Checks for the total of open orders

Other Features: