simple problem with my EA

 

its my first EA and i have a problem, im trying to buy or sell when ever the price is touching the bands, but when im doing back testing it doesnt show me they touched the bands, or it show me that it touched just one's, it doesnt make any sence.

let me know if u want the full code

thank you for your help

#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=120;
extern int SL=60;
extern double lotSize=0.1;
extern double DEV=2.0;
extern int Per=12;
extern int Bar_wait=10;
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;}

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



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

BOLH=iCustom(NULL,0,"Bands",Per,0,DEV,MODE_UPPER,0);////the lasr zero its shift 
BOLL= iCustom(NULL,0,"Bands",Per,0,DEV,MODE_LOWER,0);////the lasr zero its shift 



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

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

if (  Low[1]<=BOLL && Bid<=BOLL )

{Order=SIGNAL_BUY;
  Alert("buy_signal demo2");}

}
//////////////////////////////


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

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

if (  High[1]>=BOLH && Bid>=BOLH )

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

}


   return(0);
  }
//+---------------
 
I'm not sure I get the logic of your program. However you may want to try creating a template which you can load as soon as the back-tester starts in visual mode. You can slow down the tester in visual mode from the start of the test til you load the template. This should give you some visual help on if the ea is doing what you want. If not then review the buy and sell logic. Still having problem then submit the entire code and explain what you want it to be doing.
 
ubzen:
I'm not sure I get the logic of your program. However you may want to try creating a template which you can load as soon as the back-tester starts in visual mode. You can slow down the tester in visual mode from the start of the test til you load the template. This should give you some visual help on if the ea is doing what you want. If not then review the buy and sell logic. Still having problem then submit the entire code and explain what you want it to be doing.


i want it to buy when the price is touching the high band and sell when the price is touching the low band. i want to keep it simple because it's my first EA so i want to set it to take profit after 14 pips and stop loss after 8 pips,

here is the full code, thank u so much

#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=120;
extern int SL=60;
extern double lotSize=0.1;
extern double DEV=2.0;
extern int Per=12;
extern int Bar_wait=10;
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;}

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



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

BOLH=iCustom(NULL,0,"Bands",Per,0,DEV,MODE_UPPER,0);////the lasr zero its shift 
BOLL= iCustom(NULL,0,"Bands",Per,0,DEV,MODE_LOWER,0);////the lasr zero its shift 



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

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

if (  Open[0]>=BOLL && Bid<=BOLL )

{Order=SIGNAL_BUY;}

}
//////////////////////////////


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

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

if (  Open[0]<=BOLH && Bid>=BOLH )

{Order=SIGNAL_SELL;}

}


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

  ticketb=OrderSend(Symbol(),OP_BUY,lotSize,Ask,3,0, 0,"SHAUL",MagicNumber,Green);
  OrderModify(ticketb,0,Ask-(SL*Point),Ask+(TP*Point),0,Green);

      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


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

  tickets=OrderSend(Symbol(),OP_SELL,lotSize,Bid,3,0, 0,"SHAUL",MagicNumber,Green);
  OrderModify(tickets,0,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


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

Your code plays right into the in-efficiencies of the strategy tester. Instead of:

BOLH=iCustom(NULL,0,"Bands",Per,0,DEV,MODE_UPPER,0);
BOLL= iCustom(NULL,0,"Bands",Per,0,DEV,MODE_LOWER,0);
Instead Use
BOLH=iCustom(NULL,0,"Bands",Per,0,DEV,MODE_UPPER,1);
BOLL= iCustom(NULL,0,"Bands",Per,0,DEV,MODE_LOWER,1);

Also, IMO never use Bid and Ask and expect it to be back-tester friendly. The back-tester doe not simulate real ticks instead uses 1-minute data as Ticks. Your Algorithm:

if ( Open[0]>=BOLL && Bid<=BOLL )
Order=SIGNAL_BUY;

would be better served as:

if( Open[0] >= BOLL && Open[1] < BOLL )
Order=SIGNAL_BUY;

In other-words,  coding when price crosses or when indicator crosses a particular point or price is more back-tester friendly than asking for when Bid = Band. What do you think would happen in a gap. With your minute data, that would happen allot.

 
ubzen:

Your code plays right into the in-efficiencies of the strategy tester. Instead of:

Also, IMO never use Bid and Ask and expect it to be back-tester friendly. The back-tester doe not simulate real ticks instead uses 1-minute data as Ticks. Your Algorithm:

In other-words, coding when price crosses or when indicator crosses a particular point or price is more back-tester friendly than asking for when Bid = Band. What do you think would happen in a gap. With your minute data, that would happen allot.


first thank u for your help

I did as you told me and i fixed it but now i have infinity loop or something else . the EA need to alert when it is touching the bands but it keep alert all the time even if it didnt touch.

this is the code after i fixed as u said

//+------------------------------------------------------------------+
//|                                                        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=120;    //take profit
extern int SL=60;      //stop loss
extern double lotSize=0.1;
extern double DEV=3.0;
extern int Per=12;
extern int Bar_wait=10;
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;}

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



//////////////////// 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); // show us the price of the boll high


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

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

if (  Open[0]<=BOLL && Open[1]<BOLL )

{Order=SIGNAL_BUY;}
    Alert("buy_signal");
       
}
//////////////////////////////


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

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

if (  Open[0]>=BOLH && Open[1]>=BOLH )

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

}


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

  ticketb=OrderSend(Symbol(),OP_BUY,lotSize,Ask,3,0, 0,"SHAUL",MagicNumber,Green);   //open
  OrderModify(ticketb,0,Ask-(SL*Point),Ask+(TP*Point),0,Green);

      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,Green);
  OrderModify(tickets,0,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



//----
   return(0);
  }
//+------------------------------------------------------------------+
 
You need a time_stamp. That you can switch off when the alert is send the first time. Try using the search function in the Top right hand side of the side for Time_Stamp.
 
ubzen:
You need a time_stamp. That you can switch off when the alert is send the first time. Try using the search function in the Top right hand side of the side for Time_Stamp.


im not sure what u mean time_stamp i looked online and didnt find it or even in the forum, i will be really glad if u can give example or code. morethan it the EA doesnt open any orders do u have any idea way?

thanks again

 
ubzen:
You need a time_stamp. That you can switch off when the alert is send the first time. Try using the search function in the Top right hand side of the side for Time_Stamp.


moreover im geting this error message do know what is it mean?

2010.07.29 21:49:32 TestGenerator: unmatched data error (volume limit 206 at 2010.04.01 03:00 exceeded)

Reason: