I need help with my ea, it doesnt trade.

 

Im coding an ea that sells but i dont know why it doesnt work. I upload you the image of the pattern that i want to code. Thanks


void OnTick()
  {
  
  bool trade = true;

   for (int i=0;i<OrdersTotal();i++) {

      int orden_seleccionada = OrderSelect (1,SELECT_BY_POS,MODE_TRADES);
      if (OrderSymbol()==Symbol() && OrderMagicNumber()==magic) {
         trade= false;
            break;
            }
         }

  
  
     if (trade==true ) {

        if (venta()==true){ //CONDICIONES JUNTAS

            int venta = OrderSend(NULL,OP_SELL,1,Bid,10,SL,TP,"Keltner inverso",magic,0, clrRed);
            }
            
         
         
         
         else
         {
         if( Hour()>=22 ) //A LAS 22H CIERRA TODAS LAS OPERACIONES
         {
         CloseTrades(-1);
            }
         }
       }
  
  }
//---
  bool venta(){ //PATRON QUE SIGUE PARA VENDER
        
        double cinco = 0;
        double cuatro = 0;
        double tres = 0;
        double dos = 0;
        double uno = 0;
       
        for(int i=2;i<250;i++){
        
         double ind = iCustom(NULL,0,"ZigZag.ex4",10,5,1,0,i); //STRUCTURA ZIGZAG
         
         if(ind!=0){
         
            if(cinco==0 && cuatro==0 && tres==0 && dos==0 && uno==0){
               cinco = ind;
            
            if(cinco!=0 && cuatro==0 && tres==0 && dos==0 && uno==0 && ind!=cinco){
               cuatro = ind;
            }
            if(cinco!=0 && cuatro!=0 && tres==0 && dos==0 && uno==0 && ind!=cinco && ind!=cuatro){
               tres = ind;
            }
            if(cinco!=0 && cuatro!=0 && tres!=0 && dos==0 && uno==0 && ind!=cinco && ind!=cuatro && ind!=tres){
               dos = ind;
            }
            if(cinco!=0 && cuatro!=0 && tres!=0 && dos!=0 && uno==0 && ind!=cinco && ind!=cuatro && ind!=tres && ind!=dos){
               uno = ind;
               
            }
            
            }
         }
        } 
        if( uno < dos && tres > uno && tres < cuatro && tres < dos && cuatro < dos && cinco < cuatro && cinco < uno && Close[1]>tres && Low[2]<tres)
        {
         return true;
        }else{
        return false;
        
        }
        
        }
Files:
patron_2.png  16 kb
 
Ruben Ortega:

Im coding an ea that sells but i dont know why it doesnt work. I upload you the image of the pattern that i want to code. Thanks


The first observation is this:

   for (int i=0;i<OrdersTotal();i++) {

If you have no orders in the system this loop will never execute - have you tested that?

After that it is a matter of debugging each step to make sure you reach and successfully execute the OrderSend()

 
Ruben Ortega:

Im coding an ea that sells but i dont know why it doesnt work. I upload you the image of the pattern that i want to code. Thanks

for (int i=0;i<OrdersTotal();i++) {

      int orden_seleccionada = OrderSelect (1,SELECT_BY_POS,MODE_TRADES);
      if (OrderSymbol()==Symbol() && OrderMagicNumber()==magic) {
         trade= false;
            break;
            }
         }
for (int i=0;i<OrdersTotal();i++) {

      int orden_seleccionada = OrderSelect (1,SELECT_BY_POS,MODE_TRADES);
      if (OrderSymbol()==Symbol() && OrderMagicNumber()==magic) {
         trade= false;
            break;
            }
         }
Reason: