How to wait for the for loop to finish to execute an action?

 
Hello, I am making an EA that draws some levels, I need the levels to be drawn at the end of the FOR cycle, but the execution is not sequential, even if I place the instruction after the FOR cycle, it is executed before. Is there any way to do it? Thank you!
 
Patricio: Hello, I am making an EA that draws some levels, I need the levels to be drawn at the end of the FOR cycle, but the execution is not sequential, even if I place the instruction after the FOR cycle, it is executed before. Is there any way to do it? Thank you!

Your short question does not help explain much. Show your code, and explain in more detail.

 
fernando carrero # :

Su breve pregunta no ayuda a explicar mucho. Muestre su código y explíquelo con más detalle.

for(int i=Periodos; i>0; i--)
    {      
        
        if(iCustom(NULL,0,"..\\Indicators\\"+name_indicator,TF,Operacion,i) == 1)
        {
            
            RSICandleHigth=iHigh(NULL,0,i);
            RSICandleLow=iLow(NULL,0,i);
            RSINewCandle=i;
            RSI=true;
        }
        else 
        {
            
            if(RSI)
            {
                
                if(next_max(Operacion, i, RSICandleLow, RSICandleHigth))
                {
                     switch(Operacion){
                            case 0: 
                              RSICandleLow=iLow(NULL,0,i);
                              RSINewCandle=i;
                              break;
                            case 1: 
                              RSICandleHigth=iHigh(NULL,0,i);
                              RSINewCandle=i;
                              break;
                        }       
                }
                
                
                if(mark_level(Operacion,i,RSINewCandle))
                {                     
                    if(create_level(Operacion,line_max,RSINewCandle))
                    {
                        price_level=price_level(Operacion,RSINewCandle);
                        
                        switch(Operacion){
                            case 0: 
                              ColorLinea=Linea_Compra;
                              break;
                            case 1: 
                              ColorLinea=Linea_Venta;
                              break;
                        }

                        
                        
                        ObjectDelete(IntegerToString(line_max));

                        
                        
                        
                        RSI=false;
                        line_max=RSINewCandle;
                    }
                    
                }
                
                else{
                    switch(Operacion){
                            case 0: 
                              RSICandleHigth=iHigh(NULL,0,i);
                              break;
                            case 1: 
                              RSICandleLow=iLow(NULL,0,i);
                              break;
                        }
                    
                }
            }         
        }
    }
      ObjectCreate   (  
                        NULL,
                        IntegerToString(RSINewCandle),
                        OBJ_TREND,
                        0,
                        iTime(NULL,0,RSINewCandle),
                        price_level,
                        iTime(NULL,0,RSINewCandle)+((Period()*60)*Periodos),
                        price_level
                     );                        
      
      ObjectSetInteger(NULL,IntegerToString(RSINewCandle),OBJPROP_COLOR,ColorLinea);
      ObjectSetInteger(NULL,IntegerToString(RSINewCandle),OBJPROP_RAY_RIGHT,false);                        
      ObjectSetInteger(NULL,IntegerToString(RSINewCandle),OBJPROP_WIDTH,3);
Thanks for your help. As you can see, I am looking to draw a line after collecting the data and analyzing it through a FOR loop. To my surprise these levels are drawn while the for loop is running and I don't want that, I want the data to be analyzed first and then when I'm done drawing the lines. Thank you!
 
What gives you the impression that the object is created before the loop has run down?
Have you tried to use the debugger with stop points on every line?
 
Tobias Johannes Zimmer #:
¿Qué le da la impresión de que el objeto se crea antes de que se agote el ciclo?
¿Alguna vez intentó usar el depurador con puntos de parada en cada línea?
Hello Tobias, I run it on the graph and I see that it is drawing the lines. I have not verified what you tell me. Thank you
 
It draws the lines probably because the loop has already run.

But if you really want to verify that you need to have some system with print messages or do that thing with the debugger, see above.
 
Tobias Johannes Zimmer # : Dibuja las líneas probablemente porque el bucle ya se ha ejecutado.


Pero si realmente quiere verificar que necesita tener algún sistema con mensajes impresos o hacer eso con el depurador, vea arriba.
Tobias Johannes Zimmer # : Dibuja las líneas probablemente porque el bucle ya se ha ejecutado.


Pero si realmente quiere verificar que necesita tener algún sistema con mensajes impresos o hacer eso con el depurador, vea arriba.
I put a Print(i), inside the loop and I see the lines appear before the loop ends. Besides that I only want to show the last line, the previous one is deleted and I see the line move through the graph. Which makes it clear to me that the ObjectCreate is finishing before the loop finishes. Thank you
 
Have you tried the debugger?

If you run this in an EA in OnTick it runs all the time. After the loop comes the line and after the line comes the loop again. That is information that I don't have.

None can say from this half EA you posted. The code looks okay for a snippet but it doesn't even compile.

 
Tobias Johannes Zimmer #:
Have you tried the debugger?

If you run this in an EA in OnTick it runs all the time. After the loop comes the line and after the line comes the loop again. That is information that I don't have.

None can say from this half EA you posted. The code looks okay for a snippet but it doesn't even compile.

Thank you very much Tobias, with the debug I was able to find the problem, it was a logical problem that caused that RSI=false. Thank you very much!!
Reason: