Download MetaTrader 5
To add comments, please log in or register
Millions of traders download codes from MQL5 library. Share your app with them!
douglas gardner
9
douglas gardner 2014.10.16 03:35 

Hi, I used an online EA builder to start to understand the coding but it will not place any trades when i backtest it. Can anyone tell me why please? what should the "EA Generator www.ForexEAdvisor.com" component on the result lines be?

 

Thanks

 

extern int MagicNumber=10001;

extern double Lots =5;

extern double StopLoss=12;

extern double TakeProfit=27;

extern int TrailingStop=0;

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;

     if((Hour()==0801)&&(Open[1]<Close[1])) // Here is your open buy rule

     {

        result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue);

        if(result>0)

        {

         TheStopLoss=0;

         TheTakeProfit=0;

         if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*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((Hour()==0801)&&(Open[1]>Close[1])) // Here is your open Sell rule

     {

        result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Red);

        if(result>0)

        {

         TheStopLoss=0;

         TheTakeProfit=0;

         if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*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((Hour()==1900)) //here is your close buy rule

              {

                   OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);

              }

            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((Hour()==1900)) // here is your close sell rule

                {

                   OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);

                }

            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);

} 

whroeder1
13641
whroeder1 2014.10.16 12:51  
DG_27: I used an online EA builder
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

    1. We hate EA builder
    2. You couldn't be bothered to learn mql4, therefor there is no common language for us to communicate.
    3. 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.
    4. EA builder makes bad code counting up while closing multiple orders.
    5. EA builder makes bad code Bars is unreliable (max bars on chart) volume is unreliable (miss ticks) Always use time
    6. EA builder makes bad code Not adjusting for 4/5 digit brokers
    7. EA builder makes bad code not adjusting for ECN brokers.
    8. EA builder makes bad code not checking return codes.
  2. 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. How many hours are in a day?
douglas gardner
9
douglas gardner 2014.10.16 17:30  

Hi WHRoeder,

 

Thanks for responding. You sound like you need a nap or a hug. Either way your points 2.2 and 2.3 were not helpful - i don't expect free coding from you. However now that you have shown me the common errors article i can learn what i need to know. Thank you for including that in your response. I hope that others can learn from your exquisitely framed input, as i have, and that the nap helps.

 

DG 

/
To add comments, please log in or register