Free EA Script <3

 

Hi Guys, How was your day or trade, hope its okay. Today i wanna share you my EA Script, hope you like it. :)

extern int MagicNumber=20170601;
extern double Lots =6.01;
extern double MinLots =6.01;
extern double FixLots =6.01;
extern double Risk=30.0;
extern double MaxLots =1000.0;
extern double Try3Profit=1.001;
extern double StopLoss=5.0;
extern double ProfitPercent=10.0;
extern double PipBeforeStopOrder=2.0;
extern double TrailingStop=1.5;
extern double MaxSpread=1.0;
extern int MaxOrders=1;
extern int Slippage=3;
//+------------------------------------------------------------------+
//    expert start function
//+------------------------------------------------------------------+
int start()
{
  double MyPoint=Point;
  if(Digits==3 || Digits==5) MyPoint=Point*10;
  
  double TheStopLoss=0;
  double TheTakeProfit=0;
  if( TotalOrdersCount()==0 ) 
  {
     int result=0;
     int MaxOrders=1;
     if((iMA(NULL,PERIOD_M15,3,0,MODE_LWMA,PRICE_LOW,0)>Ask)) // Here is your open buy rule
     {
        result=OrderSend(Symbol(),OP_BUYSTOP,AdvancedMM(),Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue);
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(ProfitPercent>0) TheTakeProfit=Ask+ProfitPercent*MyPoint;
         if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        return(0);
     }
     if((iMA(NULL,PERIOD_M15,3,0,MODE_LWMA,PRICE_HIGH,0)<Bid)) // Here is your open Sell rule
     {
        result=OrderSend(Symbol(),OP_SELLSTOP,AdvancedMM(),Bid,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Red);
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(ProfitPercent>0) TheTakeProfit=Bid-ProfitPercent*MyPoint;
         if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        return(0);
     }
  }
  
  for(int cnt=0;cnt<OrdersTotal();cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   
         OrderSymbol()==Symbol() &&
         OrderMagicNumber()==MagicNumber 
         )  
        {
         if(OrderType()==OP_BUY)  
           {
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else 
           {
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
}

int TotalOrdersCount()
{
  int result=0;
  for(int i=0;i<OrdersTotal();i++)
  {
     OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);
     if (OrderMagicNumber()==MagicNumber) result++;

   }
  return (result);
}
double AdvancedMM()
{
 int i;
 double AdvancedMMLots = 1;
 bool profit1=true;
 int SystemHistoryOrders=1;
  for( i=0;i<OrdersHistoryTotal();i++)
  {  OrderSelect(i,SELECT_BY_POS ,MODE_HISTORY);
     if (OrderMagicNumber()==MagicNumber) SystemHistoryOrders++;
  }
 bool profit2=true;
 int LO=0;
 if(SystemHistoryOrders<2) return(Lots);
 for( i=OrdersHistoryTotal()-1;i>=0;i--)
  {
     if(OrderSelect(i,SELECT_BY_POS ,MODE_HISTORY))
     if (OrderMagicNumber()==MagicNumber) 
     {
        if(OrderProfit()>=1 && profit1) return(Lots);
        if( LO==0)
        {  if(OrderProfit()>=1) profit1=true;
           if(OrderProfit()<1)  return(OrderLots());
           LO=1;
        }
        if(OrderProfit()>=1 && profit2) return(AdvancedMMLots);
        if(OrderProfit()>=1) profit2=true;
        if(OrderProfit()<1 ) 
        {   profit1=true;
            profit2=true;
            AdvancedMMLots+=OrderLots();
        }
     }
  }
 return(AdvancedMMLots);
}

if You wanna change the script please let me know and share it to in my thread. Sharing is Caring. :)

 
  1.   double MyPoint=Point;
      if(Digits==3 || Digits==5) MyPoint=Point*10;
    
    It's not a "MyPoint," it's the definition of a PIP. Should call it what it is. adjusting SL, TP, and slippage; for 4/5 digit brokers and for JPY pairs.
    double   pip          = StringFind(_Symbol,"JPY") < 00.010.0001;
    int      pipsToPoints = int(pip / _Point);
    int      pipDigits    = (int)MathLog10(pipsToPoints);
    int      slippage     = 3 * pipsToPoints;

  2. result=OrderSend(Symbol(),OP_BUYSTOP,AdvancedMM(),Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue);
    if(result>0)
    
    Check your return codes for errors. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  3. You can't move stops closer to the market than MODE_STOPLEVEL. Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial You can't put a Buy Stop at the market. That fails but you don''t know it because you never report it. #2
  4. Not adjusting slippage #1
    • We hate EA builder
    • You couldn't be bothered to learn mql4, therefor there is no common language for us to communicate.
    • There are only two choices: learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem, but we are not going to debug your hundreds lines of code.
    • EA builder makes bad code counting up while closing multiple orders.
    • EA builder makes bad code Bars is unreliable (max bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
    • EA builder makes bad code Not adjusting for 4/5 digit brokers, TP/SL and slippage:
      double   pip          = StringFind(_Symbol,"JPY") < 0 ? 0.01 : 0.0001;
      int      pipDigits    = (int)MathLog10(pip/_Point);
      int      pipsToPoints = int(pip / _Point);
      int      slippage     = 3 * pipsToPoints;
    • EA builder makes bad code not adjusting for ECN brokers.
    • EA builder makes bad code not checking return codes.
    • EATree uses objects on chart to save values - not persistent storage (files or GV+Flush.) No recovery (crash/reboot.)

  5. OrderSelect(result,SELECT_BY_TICKET);
    OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
    
    #2
  6. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
  7.   for(int cnt=0;cnt<OrdersTotal();cnt++)
         {
          OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
    
    #2
  8. In the presence of multiple orders (one EA multiple charts, multiple EA's, manual trading)
  9.   for(int i=0;i<OrdersTotal();i++)
      {
         OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);
         if (OrderMagicNumber()==MagicNumber) result++;
    
    
    Fails if you put it on other charts but don't change the MN. Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
  10.  for( i=OrdersHistoryTotal()-1;i>=0;i--){
         if(OrderSelect(i,SELECT_BY_POS ,MODE_HISTORY))
         if (OrderMagicNumber()==MagicNumber) 
         {
            if(OrderProfit()>=1 && profit1) return(Lots);
    You assume history is ordered by date, it's not. Could EA Really Live By Order_History Alone? (ubzen) - MQL4 forum