simple problem helppppppp please

 

it is my first ea, it works on the back testing but does not work on live. why any suggestions? it's make money on the back teting i hope it will do the same at the reall market

thank yall

//+------------------------------------------------------------------+
//|                                                        SHAUL.mq4 |
//|                                                        |
//|                                                http://ftsa.co.il |
//+------------------------------------------------------------------+
#property link      ""
#include <stderror.mqh>
#include <stdlib.mqh>
#define IDLE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_TRBUY 3
#define SIGNAL_TRSELL 4
#define SIGNAL_P 5
#define SIGNAL_L 6
bool trade=false;
int tickets=0;
int ticketb=0;
int Order = IDLE;
int Barw;
int barc;

double BOLH;
double BOLL;

extern int TP=250;    //take profit
extern int SL=150;      //stop loss
extern double lotSize=0.1;
extern double DEV=3.0;
extern int Per=12;
extern int Bar_wait=5;
extern int MagicNumber=7272;



//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
//----
   if (OrdersTotal()==0)   
   { trade=false;
     Order = IDLE;
   }
   
   if (OrdersTotal()!=0)
   {
       for (int i=1; i<=OrdersTotal(); i++)       //Cycle for all orders..
      {                                        //displayed in the terminal
       if(OrderSelect(i-1,SELECT_BY_POS)==true)//If there is the next one
        {                                     
          if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
          {
           trade=true;
           
               break;
            }
          else {trade=false;}
          }
        } 
     
   } 
double division =DEV;
double spred; //fix the price so it will open order when it's really touching the bands
spred=(Ask-Bid);
int time_test= Period();// define what is the time period we are using 

//////////////////// INDICATORS\

BOLH=iCustom(NULL,0,"Bands",Per,0,DEV,MODE_UPPER,1);///the last zero its the shift   
BOLL= iCustom(NULL,0,"Bands",Per,0,DEV,MODE_LOWER,1);///the last zero its the shift 
Comment("bollh = " ,BOLH ,"bol LOW= ",BOLL, "\nbid= ", Bid ,"\nask= ", Ask, "\ngoods= ",spred, "\nDEV= ",division); // show the price of the boll high


//////////////////CHECK FOR BUY

if (trade==false && Order==IDLE)
{

if ( Open[0]>=BOLL && (Ask+spred)<BOLL/* Open[0]<=BOLL && Ask<BOLL */)

{Order=SIGNAL_BUY;}     
}
//////////////////////////////


//////////////////CHECK FOR SELL

if (trade==false && Order==IDLE)
{

if ( Open[0]<=BOLH && (Bid+spred)>BOLH/* Open[0]>=BOLH && Ask>BOLH*/ )

{Order=SIGNAL_SELL;}
     // Alert("sell_signal");
      
}

/////////////////////////BUY
if (trade==false)
{
  if (Order == SIGNAL_BUY  )
  {

  ticketb=OrderSend(Symbol(),OP_BUY,lotSize,Ask,3,Ask-(SL*Point), Ask+(TP *Point),"SHAUL",MagicNumber ,0 ,Green);   //open
   
   //if(OrderSelect( ticketb, SELECT_BY_TICKET )==true)
  // OrderModify(ticketb,OrderOpenPrice(),Ask- SL*Point,Ask+ (TP * Point) ,0,Green);   ///working on it
   
  

   
      if(OrderSelect( ticketb, SELECT_BY_TICKET )==true)
      {
       Alert("LONG ORDER OPENED IN SHAUL"," Symbol= ",Symbol()," Period=",Period(), " Ticket= ",ticketb);
      Order = SIGNAL_TRBUY;
      
       
        
      }
      else
      {
      Print("OrderSelect returned the error of ",GetLastError());
      Alert("EROR LONG ORDER IN SHAUL "," Symbol= ",Symbol()," Period=",Period()," EROR= ",GetLastError());
      Order= IDLE;
      }
   }
} 
/////////////////////////////////// END


/////////////////////////sell
if (trade==false)
{
  if (Order == SIGNAL_SELL  )
  {

  tickets=OrderSend(Symbol(),OP_SELL,lotSize,Bid,3,0,0,"SHAUL",MagicNumber,0,Green); // open sell 

   if(OrderSelect( tickets, SELECT_BY_TICKET )==true)
   OrderModify(tickets,OrderOpenPrice(),Ask+(SL*Point),Ask-(TP*Point),0,Green);


      if(OrderSelect( tickets, SELECT_BY_TICKET )==true)
      {
       Alert("SHORT ORDER OPENED IN SHAUL"," Symbol= ",Symbol()," Period=",Period(), " Ticket= ",ticketb);
      Order = SIGNAL_TRSELL;
      
        
      }
      else
      {
      Print("OrderSelect returned the error of ",GetLastError());
      Alert("EROR SHORT ORDER IN SHAUL "," Symbol= ",Symbol()," Period=",Period()," EROR= ",GetLastError());
      Order= IDLE;
      }
   }
} 
/////////////////////////////////// END
int how_much_to_wait= Bar_wait;
bool stopped =false;
/////////////////check order status buy

if (trade==false && Order==SIGNAL_TRBUY)
{
  if (OrderSelect( ticketb, SELECT_BY_TICKET,MODE_HISTORY )==true)
  { 
   if (OrderProfit()>0){Order=SIGNAL_P;}  //order made money
   if (OrderProfit()<0){Order=SIGNAL_L;}  //order lost money
   }
}
///////////////////////////////////


/////////////////check order status sell

if (trade==false && Order==SIGNAL_TRSELL)
{
  if (OrderSelect( ticketb, SELECT_BY_TICKET,MODE_HISTORY )==true)
  { 
   if (OrderProfit()>0){Order=SIGNAL_P;} //barc=Bars;}   made money
   if (OrderProfit()<0){Order=SIGNAL_L;}  // Barw=Bars;} lost money
   }
}
///////////////////////////////////
// if made profit change it back to idle
if (trade==false && Order==SIGNAL_P) 
      Order=IDLE;
/////////////////////////////////// 
//if lost wait
if (trade==false && Order==SIGNAL_L)
{
   
   //if (Bars>=Barw+Bar_wait) {Order=IDLE;}
   Sleep(time_test*60*1000*how_much_to_wait);
   stopped=true;
   if (stopped==true)
   {
      Alert("sleep work");
      Order=IDLE;
   }
   else
   Alert("sleep didnt work");
   
}
/////////////////////////////////// 


//////////////////////////////
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

Who is your broker?

This EA is written for a instant execution broker(market maker)......if your broker is an ECN/STP, then the EA will test but not work live.

 

What errors are in the Experts or Journal tab?

-BB-

 

You have a lot of courage to open an "Auto trading" company using your clients money to test your EA's, when you actually doesn't even know how to code.

 
first of all thank you. my broker is goforex, what do you think should I do in order to fix the problam? Can I just fix the code or I need to move to a new broker? Thanks again
 

kennyhubbard:

This EA is written for a instant execution broker(market maker)......if your broker is an ECN/STP, then the EA will test but not work live.

That and you don't adjust for five digit brokers. TP, SL, and SLIPPAGE
//++++ These are adjusted for 5 digit brokers.
double  pips2points,    // slippage  3 pips    3=points    30=points
        pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int init(){
    if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
 

I hate to say this, but these guys are right. Try this, go to the Code Base section of this forum and drill through 10 different existing programs, 3 scripts, 3 indicators, and 4 EAs. when you are done, note everything you have learned, then go to the Code Base section of this forum and drill through 10 different existing programs, 3 scripts, 3 indicators, and 4 EAs.

After you have done this a few times, you should have a fair hang of th codiong.

The suggestions that the others have made is the solution to your problem for your code. Here is a simple snippet that will help, but you first need to identify if your user is using ECN or not. For example, if they are ECN, the EURUSD will have a number like this 1.12345, but if it is not ECN, it will have a number like this: 1.1234, notice the difference in the decimal values? The coding that WHRoeder gave you will help you to iron that out. Anytime you need to make sure a value is in the right decimal value (is or is not ECN) you will have to use that code to adjust the values correctly.

Now if you are not getting trades in forward test, but you are getting them in back test, this is because back tester does not allow you to change ECN settings, thus it never trades ECN (the extra digit). So it does not pick up on that. I actually thought of writting a code snippet that will detext the users ECN, I just never got around to it.

Now how do you fix the code. Well, those who use ECN brokers also do not allow you to submit Stop losses and Take Profits in the same OrderSend statement, so you have to initialize the OrderSend with these values set to 0. Then perform a ModifyOrder command to add them in, in some cases, you have to submit a ModificationOrder for each the stop loss and the take profit. We force this to happen in the beginning loop of our code. The lazy pseudo code for this is similar to the following:

OrderSend(pass all valus, but SL and TP = 0)

OrderModify(TicketID of the above ticket and SL value)

OrderModify (TicketID of the above ticket and the TP value)

the end.

 

ECN and 5 digits are two separate problems, you must handle both independently. OrserSend with TP=0, SL=0) then one orderModify with both TP, SL.

Reason: