Help to create multiple conditions "or" in mq4

 
Hi all,

I am developing a forex robot, and I only have one question. I would like to establish a condition which can be given in six candles, previous. The objective is that if the high points of any of the 6 previous candles, is above the tenkansen (ichimoku) we enter the market. For this I know that the condition would be "or" that in code I understood that it would be "||", to establish the condition "o" -

This is the line of code in the case of entry in shorts, to which I would like to insert this condition:

&& Low [1] <iIchimoku (NULL, PERIOD_CURRENT, Tenkan_sen, Kijun_sen, Senkou_Span_B, MODE_TENKANSEN, 0)

I have made a modification but it does not work correctly:

&& (Low [1] || Low [2] || Low [3] || Low [4] || Low [5] || Low [6]) <iIchimoku (NULL, PERIOD_CURRENT, Tenkan_sen, Kijun_sen, Senkou_Span_B, MODE_TENKANSEN, 0)

Can you help me with this question?

Thanks in advance!
 

Hi, the condition should be like : 

(iLow(Null,0,1)<iIchimoku (NULL,PERIOD_CURRENT, Tenkan_sen, Kijun_sen, Senkou_Span_B, MODE_TENKANSEN, 0))|| (iLow(Null,0,2)<iIchimoku (NULL, PERIOD_CURRENT, Tenkan_sen, Kijun_sen, Senkou_Span_B, MODE_TENKANSEN, 0))

You can apply the same logic to the other candles.

 

Don't try to cram all of your logic into a one-line expression because you will find it nearly impossible to read and debug. Instead break you problem down into small and easy to process steps. 

   double lowest = DBL_MAX;
   for(int i=0; i<6; i++)
      if(Low[i] < lowest)
         lowest = Low[i];
         
   bool low_condition = lowest < iIchimoku(NULL, PERIOD_CURRENT, Tenkan_sen, Kijun_sen, Senkou_Span_B, MODE_TENKANSEN, 0);
   
   if(... && low_condition) 
 
nicholi shen:

Don't try to cram all of your logic into a one-line expression because you will find it nearly impossible to read and debug. Instead break you problem down into small and easy to process steps. 

Your remark is right, but your code example logic doesn't match the one asked by the OP.
double highestLow = 0;
   for(int i=0; i<6; i++)
      if(Low[i] > highestLow)
         highestLow = Low[i];
         
   bool low_condition = highestLow < iIchimoku(NULL, PERIOD_CURRENT, Tenkan_sen, Kijun_sen, Senkou_Span_B, MODE_TENKANSEN, 0);
   
   if(... && low_condition) 
 
Alain Verleyen:
Your remark is right, but your code example logic doesn't match the one asked by the OP.

I beg to disagree. OP made it confusing by defining a long condition, but had given a short condition example. Not your fault for thinking I was wrong, OP should have stayed consistent with his example. 

The objective is that if the high points of any of the 6 previous candles, is above the tenkansen (ichimoku) we enter the market.

...&& (Low [1] || Low [2] || Low [3] || Low [4] || Low [5] || Low [6]) <iIchimoku (NULL, PERIOD_CURRENT, Tenkan_sen, Kijun_sen, Senkou_Span_B, MODE_TENKANSEN, 0)

In other words, a sell condition exists if the lowest value of the past six bars is less than the ichimoku value. 
 
nicholi shen:

I beg to disagree. OP made it confusing by defining a long condition, but had given a short condition example. Not your fault for thinking I was wrong, OP should have stayed consistent with his example. 

In other words, a sell condition exists if the lowest value of the past six bars is less than the ichimoku value. 
I am not surprised you disagree. The "objective" of the OP is clearly stated (though he wrote the 'long' condition in plain English and the 'short' condition in the provided code) and the code I provided is the way to do it. I will not argue any more.
 

&& (Low [1] || Low [2] || Low [3] || Low [4] || Low [5] || Low [6]) <iIchimoku (NULL, PERIOD_CURRENT, Tenkan_sen, Kijun_sen, Senkou_Span_B, MODE_TENKANSEN, 0)

To me this means something like:

     Low[1] < iIchi..

|| Low[2] < Ichi..

|| ...

So if the max of all those Low[i] < iIchi.. it becomes true.

In this case this should do it:

  && ArrayMaximum(Low,1,6) < iIchi..
 
Carl Schreiber:

To me this means something like:

So if the max of all those Low[i] < iIchi.. it becomes true.

In this case this should do it:

I completely forgot that ArrayMin/Max has start & count params... This is the best answer -- except you've got the args backwards. 

int  ArrayMaximum( 
   const void&   array[],             // array for search 
   int           count=WHOLE_ARRAY,   // number of checked elements 
   int           start=0              // index to start checking with 
   );
 
Alain Verleyen:
I am not surprised you disagree. The "objective" of the OP is clearly stated (though he wrote the 'long' condition in plain English and the 'short' condition in the provided code) and the code I provided is the way to do it. I will not argue any more.

The objective is not clearly stated. If your assumption is correct then why did OP write (conditions < ichi) instead of (conditions > ichi)? The fact of the matter is that we are both drawing conclusions on a poorly formulated question/example. Neither of us is right or wrong, but like usual you think this is a competition...  🤡

 
nicholi shen:

The objective is not clearly stated. If your assumption is correct then why did OP write (conditions < ichi) instead of (conditions > ichi)? The fact of the matter is that we are both drawing conclusions on a poorly formulated question/example. Neither of us is right or wrong, but like usual you think this is a competition...  🤡

There is no competition between us, we don't play in the same category.

The fact is you are wrong and completely unable to admit it. Carl perfectly understood the OP and showed an other way to get the maximum, not the minimum like you did.

 
Alain Verleyen:

There is no competition between us, we don't play in the same category.

The fact is you are wrong and completely unable to admit it. Carl perfectly understood the OP and showed an other way to get the maximum, not the minimum like you did.

What don't you understand about it's open to interpretation? 

The objective is that if the high points of any of the 6 previous candles, is above the tenkansen (ichimoku) we enter the market.

Then OP produce this pseudo-code 

&& (Low [1] || Low [2] || Low [3] || Low [4] || Low [5] || Low [6]) <iIchimoku

Which is the equivalent to

if the low points of any of the 6 previous candles, is below the tenkansen


So we can put an end to this competition of yours... You assumed that OP used the wrong comparison operator in his psuedo-code and I assumed he used the correct operator but switched from his long description to a short example. The only one wrong here is you! You are wrong about this being a clear example. It is not. 🤣😂🤣

Reason: