Download MetaTrader 5
To add comments, please log in or register
All MQL5.community events are grouped together. Have a look at the Wall!
fly7680
331
fly7680 2016.09.17 12:47 
I inserted a for loop, after a cross candle condition on Moving Average 50.
With the for loop, I have to try the first cross of the
Moving Average 5 on 50 by 9 candles and when the cross was found, I get out of the loop and finish with buffer 1
The code does not error but does not work as I have studied.

How could I solve?

Thank you all for your patience and help.

bool c= iMA(NULL, PERIOD_CURRENT, 5, 0, MODE_SMA, PRICE_CLOSE, 2+i) > iMA(NULL, PERIOD_CURRENT, 30, 0, MODE_SMA, PRICE_CLOSE, 2+i)
     && iMA(NULL, PERIOD_CURRENT, 5, 0, MODE_SMA, PRICE_CLOSE, 1+i) < iMA(NULL, PERIOD_CURRENT, 30, 0, MODE_SMA, PRICE_CLOSE, 1+i);
     
        
      //Indicator Buffer 1 
      if(Open [1+i] < iMA(NULL, PERIOD_CURRENT, 30, 0, MODE_SMA, PRICE_CLOSE, 1+i)
      && Close[1+i] > iMA(NULL, PERIOD_CURRENT, 30, 0, MODE_SMA, PRICE_CLOSE, 1+i)) 
      
      for (int b=2; b<=10; b++)
      {
      if (c) break;
      }    
      
        {          
         Buffer1[i] = High[i] + 1 * myPoint;         
        }
Keith Watford
Moderator
7909
Keith Watford 2016.09.17 12:58  

What is the point of this loop?

      for (int b=2; b<=10; b++)
      {
      if (c) break;
      }    

It does nothing!

fly7680
331
fly7680 2016.09.17 13:04  
for (int b=2; b<=10; b++) 
{
if (c) break;
}

/* 
b        begin number canldes 2
b<=10    is number max candles
b++      increase


if (c) break; condition to be searched 
*/
I thought I had understood the cycle could you give me a help please!
Keith Watford
Moderator
7909
Keith Watford 2016.09.17 14:01  
fly7680:
I thought I had understood the cycle could you give me a help please!

I can't help because I have no idea what you are hoping to achieve.

IF c is true, the for loop is broken and does nothing

If c is false the loop runs full cycle and does nothing.

2 possibilities and both possibilities means that it is code that executes and achieves nothing.

fly7680
331
fly7680 2016.09.17 14:29  
I entered "break" because when there is true it exits the loop and I visualize the buffer.
The first time that c is true, I go out of the loop and I visualize the buffer.

I do not understand my mistake ... I apologize.


bool c= iMA(NULL, PERIOD_CURRENT, 5, 0, MODE_SMA, PRICE_CLOSE, 2+i) > iMA(NULL, PERIOD_CURRENT, 30, 0, MODE_SMA, PRICE_CLOSE, 2+i)
     && iMA(NULL, PERIOD_CURRENT, 5, 0, MODE_SMA, PRICE_CLOSE, 1+i) < iMA(NULL, PERIOD_CURRENT, 30, 0, MODE_SMA, PRICE_CLOSE, 1+i);
     
        
      //Indicator Buffer 1 
      if(Open [1+i] < iMA(NULL, PERIOD_CURRENT, 30, 0, MODE_SMA, PRICE_CLOSE, 1+i)
      && Close[1+i] > iMA(NULL, PERIOD_CURRENT, 30, 0, MODE_SMA, PRICE_CLOSE, 1+i)) // 1° step, Cross Candle in the Moving average
      
      for (int b=2; b<=10; b++) // 2° step, count the candles up to 10 and if "c" is true I get out of the loop
      {
      if (c) break;
      }    
      
        {          
         Buffer1[i] = High[i] + 1 * myPoint;   // 3° step Display the buffer in the graph
fly7680
331
fly7680 2016.09.17 14:45  
The "break" function does not mean that if "c" is true I left the loop to go to the next code?
if I delete "break", the code return erro "empty controlled statement found"
fly7680
331
fly7680 2016.09.17 14:54  

Candle 1: cross the candle on the moving average 30

the next step is to search through the cycle for loop of the cross moving average  5 on the 30... end of the code that return buffer1 in the graph

fly7680
331
fly7680 2016.09.17 18:12  

I need to continue with the code when the "c" condition is true.

help me please

whroeder1
13617
whroeder1 2016.09.18 16:58  
for (int b=2; b<=10; b++) // 2° step, count the candles up to 10 and if "c" is true I get out of the loop
{
   if (c) break;
}   

You don't need to continue - the code does nothing. If c is true, then exit the loop. otherwise the for loop continues incrementing until b is 11 and the loop exits. Nothing.

Delete the for/if/break.

fly7680
331
fly7680 2016.09.19 18:58  
Thanks for your help, this step I'll have to study better!
/
To add comments, please log in or register