[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 339

 
artmedia70:

I wasn't talking about external variables. I was talking about this.

Let's imagine a situation. A decision has to be made according to the last open position.


For the tester:

We create variables, in which we will store the necessary data of the last opened position.

As soon as a new position is opened, we will immediately add the required data into these variables.

When a signal to open a next position comes (for example, after 20 tester minutes), we need to check some criteria, by which we decide on the data of the position to be opened. These criteria, by convention, depend on the previous position opened. We read them from variables (we saved them at the previous opening) and use them as additional data for a new position.

When we open a position, we store the new data about the newly opened position in the variables.


For real:

Let's imagine the same situation, but ... Imagine that after the last position was opened and its data stored in variables, 10 minutes have passed (another 10 minutes have to pass before the next position is opened (we have just assumed this in a 'tester')). And in this interval of time, the Expert Advisor was restarted for some reason.

What happens after the restart of the EA with data of the last opened position, which was stored in variables? They will not exist.

So where do we need to get them? Right - search. This is why we need the function of searching for the necessary data. It is therefore better to find everything at once, when we need it, and not store it in variables, which is really much easier and faster.


Sorry for the late clarification - just got out into the world ... :))

You are right as always! I, too, use functions when I need fresh data. And I don't use the "variables" you mentioned, because they don't make sense, the information quickly becomes obsolete. And I advised Victor not to get hung up on functions that can be avoided, so as not to make the code heavier! Thanks for your attention!
 
Good afternoon. Is it possible to set profit limits in MetaTrader 4. Exactly in currency limits, not in pips. If so, how
 
   for(i=0;i<limit;i++) /*вопрос: еще использовал и такую последовательность for(i=Bars-1; i>=0; i--), есть ли разница с какой 
   "стороны" заполнять массив и рассматривать значения?*/
   
   RSI=iRSI(0,0,8,PRICE_CLOSE,i); 
   
   // задаем пустое значение буфера 
   RSIBuffer3[i]=0.0
   /* вроде так, мысль такая, что буфер должен быть пустым в цикле for(int i=0;i<limit;i++), до момента достижения 
   RSI заданных значений. Вопрос: так ли? и где он должен находится? */ 
   
   //ставим условие при котором пока RSI >= 70                     
   {
    while RSI>=70    
     {
       i++; //вопрос: где то видел эту часть кода в конце цикла, есть ли разница?
             
       // заполняем буфер значениями RSI
        
       RSIBuffer3[i]=iRSI(0,0,8,PRICE_CLOSE,i);
             
     }
        
     // определяем позицию максимального значения в массиве      
        
     int RSI_max = ArrayMaximum (RSIBuffer3[i], int count=WHOLE_ARRAY, int start=0); /* тут выдает ошибку на значениях count и start отсюда вопрос: нужно ли определять размер массива через ArraySize? и какое начальное значение должно быть, не i ли?*/
             
     //ищем бар со значением RSI равным максимальному значению RSI в массиве 
        
     if RSI=RSIBuffer3[RSI_max];
                
     // рисуем стрелку на этом значении
        
     ExtMapBuffer2[i]=High[i]+5*Point;
            
     else 
                
     ExtMapBuffer2[i]=0.0;
           
   }
      //ставим условие при котором пока RSI <= 30                     
   { 
    while RSI<=30
        {    
        i++;
        // заполняем буфер значениями RSI
        
        RSIBuffer3[i]=iRSI(0,0,8,PRICE_CLOSE,i);
        
        {        
                
        // определяем позицию минимального значения в массиве  
            
        int RSI_min = ArrayMinimum (RSIBuffer3[i], int count=WHOLE_ARRAY, int start=0);
        
                
        //ищем бар со значением RSI равным максимальному значению RSI в массиве 
        
        if RSI=RSIBuffer3[RSI_min];
                
        // рисуем стрелку на этом значении
             
        ExtMapBuffer1[i]=Low[i]-5*Point;
             
        else 
             
        ExtMapBuffer1[i]=0.0;            
          
        }
                   
   return(0);
   }

Help me deal with the logic, I can not somehow translate the simple logic into the program (can you recommend some literature)

The challenge: Calculate maximal (minimal) RSI at values above 70 (below 30) and draw a down (up) arrow above the bar

at these values.

Implementation (first part, the second part is similar):

1. calculate the RSI value for each bar

2. while RSI is greater than 70 fill the RSI buffer with its values

3. find the position of the maximal value in the array

4. look for the bar with the RSI value equal to the maximum RSI value in the array

5. draw an arrow above this bar.

Well, there is something like this, but while writing the code, I have a lot of questions, errors and am in a mess(((

And here is the implementation in the code.

 
mixed up the text and the code, sorry
 

Gentlemen, please advise how to encode the following algorithm using a loop.

if (iLow (Symbol (),0,1) > iLow (Symbol (),0,10))// if the MINIMUM of the first candle > MINIMUM of the tenth candle

OrderSend(Symbol(),OP_BUY,0.1,Ask,1,Bid-2950*Point,Bid+150*Point, "jfh",123 ); // open the order.

I HAVE TO

If Low 1 and simultaneously Low 2 and simultaneously Low 3...... . ...and simultaneously Low 9 candle> Low 10 candle ( i.e.Low candle from 1 to 9)

/ /open order.

Thank you.

 
solnce600:

Gentlemen, please advise how to encode the following algorithm using a loop.

if (iLow (Symbol (),0,1) > iLow (Symbol (),0,10))// if the MINIMUM of the first candle > MINIMUM of the tenth candle

OrderSend(Symbol(),OP_BUY,0.1,Ask,1,Bid-2950*Point,Bid+150*Point, "jfh",123 ); // open the order.

I HAVE TO

If Low 1 and simultaneously Low 2 and simultaneously Low 3...... . ...and simultaneously Low 9 candle> Low 10 candle ( i.e.Low candle from 1 to 9)

/ /open order.

Thank you.


We create a condition success flag, set it in tru, pass the required number of candles in the loop, if at any of them the condition is not met, set the flag in the false flag and exit the loop.
 
FAQ:

Create a condition success flag, set it in the pipe, pass the required number of candles in the loop, if at any of them the condition is not met, set the flag in the false flag and exit the loop.

Thank you very much.Sorry for God's sake.... I am still a bit slow in understanding what you have written.

I would be very grateful if you could write code..... and then I would understand everything.

 

bool have = true;

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

   if(Low[i]<=Low[i+1]){have=false; break;} 

if(have){

// действия если условие соблюдено 

}else{

 // действия если условие не соблюдено

}

 
FAQ:

bool have = true;

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

   if(Low[i]<=Low[i+1]){have=false; break;} 

if(have){

// действия если условие соблюдено 

}else{

 // действия если условие не соблюдено

}

Thank you very much. Thanks to you .... and people like you...I have made some more progress in learning the wisdom of programming....
 

people, how do you close a pending order in n, number of pips if it has not triggered?

Reason: