My EA doesn't work at every Tick and stops.

To add comments, please log in or register
Thabet77
10
Thabet77  

Hi everybody,


I need some help with my EA,here is the problem I coded a simple EA which send order (Buylimit or Selllimit) when the price reach a certain level that I define, and I run different copies of my EA simultaneously on 17 forex pairs on M1 or M5 charts, But the problem is that my EA doesn't work on every tick it run only one times and on 1 pair despite that I am careful to run a different EA for each pairs, many times the price reach the level that I defined but the EA doesn't send order. I don't understand the problem and how can I make it run on every ticks ?. following you will find my code and Thanks for help.


extern double lots=0.1;

extern int stop=5;

extern int limite=10;

extern double R1=1.2255 ;

extern double S1=1.2055 ;

extern double spread=1.2 ;

extern int T = 0;

extern int magic = 3228;

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int init()

  {

//---

      Affichage("NiveauR1","NiveauS1");

     

      if (R1 - Ask <= 100*Point && T==0)

      {

      OrderSend(Symbol(),OP_SELLLIMIT,lots,R1+10*spread*Point,4,R1+(stop+spread)*10*Point,R1-(10*limite*Point),"vente",magic,0,Red);

      T++;

         for (int i = OrdersTotal(); i >=0; i--)

         {

            if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

            {

               if (OrderSymbol()==Symbol())

               {

                  if (OrderType()==OP_SELL && OrderMagicNumber()==magic)

                  {

                     if ( Bid >= R1-5*Point)

                     {

                        OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,CLR_NONE);

                     }

                   }

                }

             }

          }

        }

     

    //ACHAT 

     

      if (Ask - S1 <= 100*Point && T==0)

      {

      OrderSend(Symbol(),OP_BUYLIMIT,lots,S1+spread*10*Point,4,(S1-stop*10*Point)+(10*Point*spread),S1+(limite*10*Point),"ACHAT",magic,0,Red);

      T++;

         for (int i = OrdersTotal(); i >=0; i--)

         {

            if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

            {

               if (OrderSymbol()==Symbol())

               {

                  if (OrderType()==OP_BUY && OrderMagicNumber()==magic)

                  {

                     if ( Bid >= S1+5*Point)

                     {

                        OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,CLR_NONE);

                     }

                   }

                }

             }

          }         

      }

      

      if ( T==1)

      {

      return(0);

      } 

//---

   return(0);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

int deinit()

  {

//---


//---

   return(0);

  }

//+------------------------------------------------------------------+

//| Expert start function                                             |

//+------------------------------------------------------------------+

int start()

  {

//---


//---

   return(0);   

  }

//+------------------------------------------------------------------+

void Affichage(string NiveauR1, string NiveauS1)

  {

  ObjectCreate(NiveauR1,OBJ_HLINE,0,0,R1,0,0,0,0);

  ObjectCreate(NiveauS1,OBJ_HLINE,0,0,S1,0,0,0,0);

  } 

whroeder1
17939
whroeder1  
  1. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your (original) post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

To add comments, please log in or register