//+--------------------------------------------------------------------+ //| | //| Compiled by © Barry Hendriks - aka Forex-ID10T. | //|In no event will author be liable for any damages/losses whatsoever.| //| Use at your own risk! | //| | //+------------------- DO NOT REMOVE THIS HEADER ----------------------+ //#include #define SIGNAL_NONE 0 #define SIGNAL_BUY 1 #define SIGNAL_SELL 2 #define SIGNAL_CLOSEBUY 3 #define SIGNAL_CLOSESELL 4 #define copyright "© Barry Hendriks 2009 to 2025" #property link "http://forex-id10t.com" //+------------------------------------------------------------------+ // EA USER CONFIGURATION SETTINGS //+------------------------------------------------------------------+ extern string Order_Settings = "### EA Config & Settings ###"; extern string RobotName = "FOREX-ID10T"; extern int MagicNumber = 10810; extern int GMToffset =0; //Adjust if trade server time differs from GMT or Daylight Savings extern bool DisplayComment = true; extern double Deposit = 1000; extern bool EachTickMode = true; extern bool UseAutoLots = true; extern double Lots = 0.01; extern double MaxLots = 100; extern int Slippage = 3; extern double RiskPercent = 1; extern double SafeSpread = 36; //Spreads higher than this is not profitable extern int MaxOrders = 1; extern bool BUYtrades = true; extern bool SELtrades = true; extern bool RecoverLoss = false; extern double Recovery = 9; extern double StopLoss = 9999; extern double TakeProfit = 9999; //ADX indicator extern int ADXTrendMin = 15; extern int ADXTrendMax = 50; extern int ADXp = 10; //EMA extern int EMAp = 5; //BolingerBands extern int BBp = 20; extern double BBgap = 15; extern double rsGAP = 0.02; extern double Volitality = 1.6182; //Counter extern int Bar2Use = 1; //CCI extern int CCIp =14; //STOHASTICS extern int StohTop = 90; extern int StohBot = 10; //+------------------------------------------------------------------+ // GLOBAL VARIABLES //+------------------------------------------------------------------+ bool TickCheck = false; string Trans0 = "NONE"; string Trans1 = "NONE"; string Trans2 = "NONE"; string Trans3 = "NONE"; string Trans4 = "NONE"; int WIN = 0; int LOSE = 0; double Profit = 0; double Loss = 0; double Profits = 0; double Losses = 0; double Money0 = 0; double Money1 = 0; double LOST = 0; double RecoveryLots = 0; int SELL_ORDER = 0; int BUY_ORDER = 0; int Error = 0; int BarCount = 0; int Current = 0; double Points = 0; double PointDigits = 0; string DepositoString = ""; string TargetString = ""; int Multiplier = 0; int Divider = 0; double BuyStopLoss = 0; double SelStopLoss = 0; int AccntLvrge = 0; int Wintrades = 0; int Lostrades = 0; double BuyVal = 0; double SelVal = 0; int TimeTradeOpened= 0; //+------------------------------------------------------------------+ //EXPERT INITIALIZATION //+------------------------------------------------------------------+ int init() {//1 //Checking for unconventional PointDigits digits number Points=MarketInfo(Symbol(),MODE_POINT); if(Points == 0.01) {PointDigits = 0.01; Multiplier = 100; Divider = 10;}//2 digits if(Points == 0.001) {PointDigits = 0.001; Multiplier = 1000; Divider = 100;}//3 digits if(Points == 0.0001) {PointDigits = 0.0001; Multiplier = 10000; Divider = 1000;}//4 digits if(Points == 0.00001) {PointDigits = 0.00001; Multiplier = 100000; Divider = 10000;}//5 digits if(AccountLeverage()==50) {AccntLvrge=2500;} if(AccountLeverage()==100) {AccntLvrge=1250;} if(AccountLeverage()==200) {AccntLvrge=625;} if(AccountLeverage()==500) {AccntLvrge=250;} if(AccountLeverage()==1000){AccntLvrge=125;} BarCount=Bars; if(EachTickMode) {Current=0;} else {Current=1;} if(AccountBalance()>Deposit || AccountBalance()= ADXTrendMin && ADX <= ADXTrendMax) { Trend = ADX; } else { Trend = 0; } BBandTop = iBands("EURUSDf",NULL,BBp,2,0,PRICE_CLOSE,MODE_UPPER,i); BBandBot = iBands("EURUSDf",NULL,BBp,2,0,PRICE_CLOSE,MODE_LOWER,i); pBBandTop = iBands("EURUSDf",NULL,BBp,2,0,PRICE_CLOSE,MODE_UPPER,i+1); pBBandBot = iBands("EURUSDf",NULL,BBp,2,0,PRICE_CLOSE,MODE_LOWER,i+1); BBChanTop = iBands("EURUSDf",NULL,BBp,1,0,PRICE_WEIGHTED,MODE_UPPER,i); BBChanBot = iBands("EURUSDf",NULL,BBp,1,0,PRICE_WEIGHTED,MODE_LOWER,i); BBandMid = BBandTop - (BBandTop - BBandBot)/2; pBBandMid = pBBandTop - (pBBandTop - pBBandBot)/2; BBVolume = (BBandTop - BBandBot); if( BBVolume >= BBgap/Divider && BBandBot >= pBBandBot && BBandTop > pBBandTop && BBandMid > pBBandMid ) { Bolbuy = (BBandTop - BBandBot); } if( BBVolume >= BBgap/Divider && BBandBot < pBBandBot && BBandTop <= pBBandTop && BBandMid < pBBandMid ) { Bolsel = (BBandTop - BBandBot); } CCI0 = iCCI("EURUSDf",0,CCIp,PRICE_CLOSE,i); CCI1 = iCCI("EURUSDf",0,CCIp,PRICE_CLOSE,i+1); if(CCI0 > 0) { RSCCI0 = 50 + CCI0/2; RSCCI1 = 50 + CCI1/2; } if(CCI0 < 0) { RSCCI0 = 50 - (CCI0/2)*-1; RSCCI1 = 50 - (CCI1/2)*-1; } if(CCI0 == 0) {RSCCI0 = 50;} if(CCI1 == 0) {RSCCI1 = 50;} if(RSCCI0 > RSCCI1 && CCI0>0) {CCIbuy = RSCCI0 - RSCCI1;} if(RSCCI0 < RSCCI1 && CCI0<0) {CCIsel = RSCCI1 - RSCCI0;} STOH_K_0 = iStochastic("EURUSDf",NULL,5,3,3,MODE_SMA,0,MODE_MAIN,i); STOH_K_1 = iStochastic("EURUSDf",NULL,5,3,3,MODE_SMA,0,MODE_MAIN,i + 1); STOH_D_0 = iStochastic("EURUSDf",NULL,5,3,3,MODE_SMA,0,MODE_SIGNAL,i); STOH_D_1 = iStochastic("EURUSDf",NULL,5,3,3,MODE_SMA,0,MODE_SIGNAL,i + 1); if(STOH_D_0>STOH_D_1 && STOH_D_0>STOH_K_0 && STOH_D_0<=StohBot) { StohUP=(STOH_D_0-STOH_K_0); } if(STOH_D_0=StohTop) { StohDN=(STOH_K_0-STOH_D_0); } //BUY TRADE SIGNAL if( SPREAD*Multiplier<=SafeSpread && Trend > 0 && Bolbuy > Bolsel //&& StohUP > StohDN //&& Support == 1 //&& Bid > pBar_Close //&& (Bid - pBar_Close) >= Volitality/Divider && CCIbuy > CCIsel && BUYtrades == true && BUY_ORDER == 0 ) { BuyOrder=SIGNAL_BUY; break; } //SELL TRADE SIGNAL if( SPREAD*Multiplier<=SafeSpread && Trend > 0 && Bolbuy < Bolsel //&& StohUP < StohDN //&& Resistance == 1 //&& Bid < pBar_Closer //&& (pBar_Close - Bid) >= Volitality/Divider && CCIbuy < CCIsel && SELtrades==true && SELL_ORDER==0 ) { SellOrder=SIGNAL_SELL; break; } } //-------------------------------------------------------------------+ //DISPLAY INFORMATION & TRADE CONDITIONS //+------------------------------------------------------------------+ if(DisplayComment==true) {//2 if(Profits==0||Losses==0){WinLossRatio=0;} if(Profits>0 && Losses>0){WinLossRatio=Profits/Losses;} if(WIN==0||LOSE==0){TradeWinLossRatio=0;} if(WIN>0 && LOSE>0){TradeWinLossRatio=(WIN/(WIN+LOSE))*100;} if(SPREAD*Multiplier>SafeSpread) { SpreadWarning=DoubleToStr(SPREAD*Multiplier,0)+" > SafeSpread "+DoubleToStr(SafeSpread,0)+" = Current spread too high to trade! "; } else { SpreadWarning=DoubleToStr(SPREAD*Multiplier,0)+" <= SafeSpread "+DoubleToStr(SafeSpread,0)+" = Current spread low enough to trade "; } comment_line=(" © Barry Hendriks (aka Forex-ID10T) January 2012 "+"\n" +"======================================"+"\n" +" FOREX ACCOUNT INFORMATION:"+"\n" +"======================================"+"\n" +" Svr Time "+DOTW()+" "+Hour()+":"+Minute()+":"+Seconds()+"\n" //+" FX Broker "+AccountCompany()+"\n" +" Accnt Balance "+AccountCurrency()+DoubleToStr(AccountBalance(),2)+"\n" +" Accnt Equity "+AccountCurrency()+DoubleToStr(AccountEquity(),2)+"\n" +" DrawDown: "+DoubleToStr((1-(AccountEquity()/AccountBalance()))*100,2)+"%"+"\n" +" Leverage "+DoubleToStr(AccountLeverage(),0)+":1"+"\n" +" Spread "+SpreadWarning+"\n" +" Risk "+DoubleToStr(RiskPercent,2)+"%"+"\n" +" MaxLots "+DoubleToStr(MaxLots,2)+"\n" +" MaxLotSize "+DoubleToStr((AccountFreeMargin()/AccntLvrge),2)+"\n" +" NextTradeLots "+DoubleToStr(CalcLotsVolume(),2)+" = "+DoubleToStr(AccountMargin(),2)+"\n" +" Recovery $"+DoubleToStr(LOST,2)+" Lots "+DoubleToStr(RecoveryLots,2)+"\n" +"======================================"+"\n" +" FOREX ID10T INFORMATION:"+"\n" +"======================================"+"\n" +" ADXTrend: "+DoubleToStr(Trend,Digits)+"\n" +" Bollingr: "+DoubleToStr((Bolbuy - Bolsel),Digits)+"\n" +" EMA: "+DoubleToStr((AboveEMA - BelowEMA),Digits)+"\n" +" Trades "+Trans0+", "+Trans1+", "+Trans2+", "+Trans3+", "+Trans4+"\n" +" Profits $"+DoubleToStr(Profits,2)+"\n" +" Losses $"+DoubleToStr(Losses,2)+"\n" +" Gain/Loss $"+DoubleToStr(Profits-Losses,2)+"\n" +" Win Ratio "+DoubleToStr(WinLossRatio,2)+"%"+"\n" +" NrOfTrades:"+DoubleToStr(WIN+LOSE,0)+" NrOfWins: "+DoubleToStr(WIN,0)+" NrOfLosses: "+DoubleToStr(LOSE,0)+"\n" +"======================================"); Comment(comment_line); }//2 //+------------------------------------------------------------------+ //CHECK TRADE POSITIONS //+------------------------------------------------------------------+ bool IsTrade=true; RefreshRates(); Total=OrdersTotal(); if(Total==0) {//2 SELL_ORDER= 0; BUY_ORDER = 0; }//2 //+------------------------------------------------------------------+ //MAIN CODE //+------------------------------------------------------------------+ for(i=0; i= 1800){BuyOrder=SIGNAL_CLOSEBUY;} //Close trade after 30 minutes if(BuyOrder==SIGNAL_CLOSEBUY && OrderMagicNumber()==MagicNumber && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars!=BarCount)))) {//5 Ticket=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slippage,MediumSeaGreen); Sleep(250); IsTrade=false; BUY_ORDER=0; BuyStopLoss=0; BuyTakeProfit=0; Total=OrdersTotal(); if(Ticket<1) {Print("Error: "+ErrorDescription(GetLastError()));} if(!EachTickMode) BarCount=Bars; continue; }//5 //CLOSE TRADE: SIGNAL_SELL if(TimeCurrent() - TimeTradeOpened >= 1800){SellOrder=SIGNAL_CLOSESELL;} //Close trade after 30 minutes if(SellOrder==SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars!=BarCount)))) {//5 Ticket=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slippage,DarkOrange); Sleep(250); IsTrade = false; SELL_ORDER = 0; SelStopLoss = 0; SelTakeProfit = 0; Total=OrdersTotal(); if(Ticket<1) {Print("Error: "+ErrorDescription(GetLastError()));} if(!EachTickMode) BarCount=Bars; continue; }//5 }//4 }//3 END IF OrderType }//2 END FOR LOOP //BUY TRADE: SIGNAL_BUY if(BuyOrder==SIGNAL_BUY && BUY_ORDER==0 && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars!=BarCount)))) {//2 if(Total0) {//4 TimeTradeOpened = OrderOpenTime(); if(OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES)) {//5 Print(RobotName+" BUY order opened : ",OrderOpenPrice()); Orders=StringConcatenate(Orders,RobotName+" BUY ",OrderSymbol(),": Profit= ",OrderProfit()); BUY_ORDER=1; Total=Total+1; } else { Print("Error: "+ErrorDescription(GetLastError())); }//5 }//4 if(EachTickMode) TickCheck=true; if(!EachTickMode) BarCount=Bars; return(0); }//3 }//2 //SELL TRADE: SIGNAL_SELL if(SellOrder==SIGNAL_SELL && SELL_ORDER==0 && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars!=BarCount)))) {//2 if(Total0) {//4 TimeTradeOpened = OrderOpenTime(); if(OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES)) {//5 Print(RobotName+" SELL order opened : ",OrderOpenPrice()); Orders=StringConcatenate(Orders,RobotName+" SELL ",OrderSymbol(),": Profit= ",OrderProfit()); SELL_ORDER=1; Total=Total+1; } else { Print("Error: "+ErrorDescription(GetLastError())); }//5 }//4 if(EachTickMode) TickCheck=true; if(!EachTickMode) BarCount=Bars; return(0); }//3 }//2 //-------------------------------------------------------------------+ //DETERMINE PROFIT LOSS VALUES //+------------------------------------------------------------------+ Money0=AccountBalance(); if(Money0>Money1) //PROFIT! {//2 WIN=WIN+1; if(NormalizeDouble(LOST,2)>0) {LOST=NormalizeDouble(LOST,2)-NormalizeDouble((Money0-Money1),2);} Profit=NormalizeDouble((Money0-Money1),2); Profits= Profits+Profit; Money1 = Money0; Trans4 = Trans3; Trans3 = Trans2; Trans2 = Trans1; Trans1 = Trans0; Trans0 = "PROFIT"; }//2 if(Money0=0) {LOST=NormalizeDouble(LOST,2)+NormalizeDouble((Money1-Money0)*1.034,2);} Loss=NormalizeDouble((Money1-Money0),2); Losses = Losses + Loss; Money1 = Money0; Trans4 = Trans3; Trans3 = Trans2; Trans2 = Trans1; Trans1 = Trans0; Trans0 = "LOSS"; }//2 if(!EachTickMode) BarCount=Bars; return(0); }//1 //+------------------------------------------------------------------+ //EXPERT END //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //Function: CalcLotsVolume //+------------------------------------------------------------------+ double CalcLotsVolume() {//1 double SendLots = 000.000; //The actual Lotsize that will be sent with the order double MinLot = 000.000; //Broker's Minimum permitted amount of a lot double MaxLot = 000.000; //Broker's Maximum permitted amount of a lot double LotStep = 000.000; //Broker's Step for changing lots, e.g 0.01 MinLot = MarketInfo(Symbol(),MODE_MINLOT); MaxLot = MarketInfo(Symbol(),MODE_MAXLOT); LotStep = MarketInfo(Symbol(),MODE_LOTSTEP); if(MinLot==0.000) MinLot=NormalizeDouble(Lots,Digits); //In case MarketInfo returns no info if(MaxLot==0.000) MaxLot=NormalizeDouble(AccountFreeMargin()/AccntLvrge,Digits);//In case MarketInfo returns no info if(UseAutoLots==true) {//2 SendLots=NormalizeDouble(MathFloor(AccountFreeMargin()*RiskyBusiness()/100/(MarketInfo(Symbol(),MODE_MARGINREQUIRED)*LotStep))*LotStep,Digits); } else { SendLots=NormalizeDouble(Lots,Digits); }//2 if(LOST<=0.00) {LOST=0.00;} if(NormalizeDouble(LOST,2)>0.00 && RecoverLoss==true) { RecoveryLots=SendLots+(SendLots*Recovery); SendLots=NormalizeDouble(RecoveryLots,2); } if(NormalizeDouble(SendLots,2)NormalizeDouble((AccountFreeMargin()/AccntLvrge),2)) {SendLots=NormalizeDouble((AccountFreeMargin()*89/AccntLvrge),2);} //Maximum Lot the account can do if(NormalizeDouble(SendLots,2) > NormalizeDouble(MaxLots,2)) {SendLots = NormalizeDouble(MaxLots,2);} //Never exceed our manualy set limit if(NormalizeDouble(SendLots,2) > NormalizeDouble(MaxLot,2)) {SendLots = NormalizeDouble(MaxLot,2);} //Broker's absolute maximum Lot return (SendLots); }//1 //+------------------------------------------------------------------+ //Function: As equity builds - decrease RiskPercent //+------------------------------------------------------------------+ double RiskyBusiness() {//1 double NewRiskPercent=NormalizeDouble(RiskPercent,2); if(AccountFreeMargin() <= Deposit) { NewRiskPercent=NormalizeDouble(RiskPercent,2); } if(AccountFreeMargin() > Deposit) { NewRiskPercent=NormalizeDouble(RiskPercent - (AccountFreeMargin()/Deposit),2); } return(NewRiskPercent); }//1 //+------------------------------------------------------------------+ //Function: Get DAY OF THE WEEK //+------------------------------------------------------------------+ string DOTW() {//1 int WeekDay; string DayOfTheWeek; WeekDay=DayOfWeek(); switch(WeekDay) {//2 case 0: DayOfTheWeek="Sunday"; break; case 1: DayOfTheWeek="Monday"; break; case 2: DayOfTheWeek="Tuesday"; break; case 3: DayOfTheWeek="Wednesday";break; case 4: DayOfTheWeek="Thursday"; break; case 5: DayOfTheWeek="Friday"; break; case 6: DayOfTheWeek="Saturday"; break; }//2 return(DayOfTheWeek); }//1 //+------------------------------------------------------------------+ //Function: Get Last Error //+------------------------------------------------------------------+ string ErrorDescription(int error_code) {//1 string error_string; Error=GetLastError(); switch(Error) {//2 //---- codes returned from trade server case 0: error_string="no error"; break; case 1: error_string="no error"; break; case 2: error_string="common error"; break; case 3: error_string="invalid trade parameters"; break; case 4: error_string="trade server is busy"; break; case 5: error_string="old version of the client terminal"; break; case 6: error_string="no connection with trade server"; break; case 7: error_string="not enough rights"; break; case 8: error_string="too frequent requests"; break; case 9: error_string="malfunctional trade operation"; break; case 64: error_string="account disabled"; break; case 65: error_string="invalid account"; break; case 128: error_string="trade timeout"; break; case 129: error_string="invalid price"; break; case 130: error_string="invalid stops"; break; case 131: error_string="invalid trade volume"; break; case 132: error_string="market is closed"; break; case 133: error_string="trade is disabled"; break; case 134: error_string="not enough money"; break; case 135: error_string="price changed"; break; case 136: error_string="off quotes"; break; case 137: error_string="broker is busy"; break; case 138: error_string="requote"; break; case 139: error_string="order is locked"; break; case 140: error_string="only long positions allowed"; break; case 141: error_string="too many requests"; break; case 145: error_string="modification denied because order too close to market"; break; case 146: error_string="trade context is busy"; break; //---- mql4 errors case 4000: error_string="no error"; break; case 4001: error_string="wrong function pointer"; break; case 4002: error_string="array index is out of range"; break; case 4003: error_string="no memory for function call stack"; break; case 4004: error_string="recursive stack overflow"; break; case 4005: error_string="not enough stack for parameter"; break; case 4006: error_string="no memory for parameter string"; break; case 4007: error_string="no memory for temp string"; break; case 4008: error_string="string not initialized"; break; case 4009: error_string="string in array not initialized"; break; case 4010: error_string="no memory for array\' string"; break; case 4011: error_string="string too long"; break; case 4012: error_string="remainder from zero divide"; break; case 4013: error_string="zero divide"; break; case 4014: error_string="unknown command"; break; case 4015: error_string="wrong jump (never generated error)"; break; case 4016: error_string="array not initialized"; break; case 4017: error_string="dll calls are not allowed"; break; case 4018: error_string="cannot load library"; break; case 4019: error_string="cannot call function"; break; case 4020: error_string="expert function calls are not allowed"; break; case 4021: error_string="not enough memory for temp string returned from function"; break; case 4022: error_string="system is busy (never generated error)"; break; case 4050: error_string="invalid function parameters count"; break; case 4051: error_string="invalid function parameter value"; break; case 4052: error_string="string function internal error"; break; case 4053: error_string="some array error"; break; case 4054: error_string="incorrect series array"; break; case 4055: error_string="custom indicator error"; break; case 4056: error_string="arrays are incompatible"; break; case 4057: error_string="global variables processing error"; break; case 4058: error_string="global variable not found"; break; case 4059: error_string="function is not allowed in testing mode"; break; case 4060: error_string="function is not confirmed"; break; case 4061: error_string="send mail error"; break; case 4062: error_string="string parameter expected"; break; case 4063: error_string="integer parameter expected"; break; case 4064: error_string="double parameter expected"; break; case 4065: error_string="array as parameter expected"; break; case 4066: error_string="requested history data in update state"; break; case 4099: error_string="end of file"; break; case 4100: error_string="some file error"; break; case 4101: error_string="wrong file name"; break; case 4102: error_string="too many opened files"; break; case 4103: error_string="cannot open file"; break; case 4104: error_string="incompatible access to a file"; break; case 4105: error_string="no order selected"; break; case 4106: error_string="unknown symbol"; break; case 4107: error_string="invalid price parameter for trade function"; break; case 4108: error_string="invalid ticket"; break; case 4109: error_string="trade is not allowed"; break; case 4110: error_string="longs are not allowed"; break; case 4111: error_string="shorts are not allowed"; break; case 4200: error_string="object already exist"; break; case 4201: error_string="unknown object property"; break; case 4202: error_string="object do not exist"; break; case 4203: error_string="unknown object type"; break; case 4204: error_string="no object name"; break; case 4205: error_string="object coordinates error"; break; case 4206: error_string="no specified subwindow"; break; default: error_string="unknown error"; }//2 return(error_string); }//1 End of error search