Close an open order with the new bars

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
13
espina88 2016.05.05 18:58 #
 

OMG i have found the error, i was declaring time out from Ordertime function and inside of the function so the programm was taking the out one making the value = 0 

 

3 hours to see the error i want to head shot :O 

avatar
13
espina88 2016.05.05 23:15 #
 

Well guys i have to write you again, now that case is insane because i have traced everything, the time is getting to the function correctly and i cant fix it anyways, im desesperate... The problem is with iBarShift.

 

I have try the function  in another program and is working fine, i paste the code:

 

input double NContratos=0.1;
int Ticket = 0;
int BarraEntrada = 0;
static datetime TiempoCompra;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   double avg7Buffer[];
   double avg19Buffer[];
   int Barras = iBars(0,PERIOD_M1);
   
   ArrayResize(avg7Buffer,Barras,0);
   ArrayResize(avg19Buffer,Barras,0);
   
   for( int i=0; i<Barras; i++ )
   {
      avg7Buffer[i] = iMA(NULL,0,7,0,MODE_SMMA,PRICE_CLOSE,i);
      avg19Buffer[i] = iMA(NULL,0,19,0,MODE_SMMA,PRICE_CLOSE,i);
   }

   if(  Movimientos() == 0  ){ Entrada(avg19Buffer,avg7Buffer);}
   
  }
//+------------------------------------------------------------------+

int Movimientos(){
  
  int NumTransacciones = OrdersTotal();
  return NumTransacciones;
   
   }
   void TipoMov(){
      int Tipo = OrderType();
   }
   
   void Entrada( double &avg19Buffer[],double &avg7Buffer[] ){
   
      if( (avg7Buffer[1] < avg19Buffer[1]) && (avg7Buffer[0] > avg19Buffer[0]) )
      {
       
         comprar();
         
      }
      if( (avg7Buffer[1] > avg19Buffer[1]) && (avg7Buffer[0] < avg19Buffer[0]) )
      {
         vender();
      }
     
   }
   
   void Salida(){
   
      OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
      Ticket = OrderTicket();
      OrderClose(Ticket,NContratos,Bid,10,clrYellow);
   }
  
  void comprar(){
   
   OrderSend(NULL,OP_BUY,NContratos,Ask,10,0,0,"C",0,0,clrGreen);
   
   
   ComprobarCierre();
   
  }
  
  void vender(){
  
      
   OrderSend(NULL,OP_SELL,NContratos,Bid,10,0,0,"V",0,0,clrRed);
   

   ComprobarCierre();
    
  }
  
  void ComprobarCierre(  ){
   
   //double PrecioCompra = Close[TiempoCompra];
       int Conta = 0;
       TiempoCompra = Time[0];
       int Indice = 0;
              
       
       do{
       Indice = iBarShift(Symbol(),0,TiempoCompra);
       Comment(iBarShift(Symbol(),0,TiempoCompra));
       }while( Indice<8);

       
 }

 

avatar
13
espina88 2016.05.07 18:50 #
 
Is so weird cus I'm trying the same function on tick() and working fine but not happens with the other function ... And I have trace all the parameters and are correct 
avatar
13
espina88 2016.05.09 17:16 #
 

Should I use another function?

Hello,

 

Im trying to make a function which wait running on a loop till the next 10 new bars are created, cus i need to analyze them:

 

int BarsCount =0;

OrderTime = Time[0]; 

while(BarsCount <10){

   BarsCount = iBarShift(Symbol(),PERIOD_CURRENT,OrderTime);

}

But always get crash at this point while the loop is running, am i doing anything wrong? I just want to wait for the next 10 bars, 

Moderator: Above text moved from a deteted thread
avatar
Moderator
3423
GumRai 2016.05.10 12:55 #
 

I have deleted your new topic which is basically just the same subject, so no need for a new topic.

You have already been given the answer that doesn't involve a loop running needlessly for the duration of 10 bars.

Back to topics list   | 1 2  

To add comments, please log in or register