Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 527

 
novichok2018: Thank you! I understand the conventions, I'll take them into account. But to understand the suggested script, alas, my knowledge of mcl4 is not enough. Sorry :( .

I do all my experiments with scripts. Run the script in your terminal. Change some lines or throw it away. See what happens

 

I want to find the Min Max of indicator data, I've done "everything according to the manual", but it feels like the indicator data is not written to an array. MQL pro tell me where I made a mistake.

     
int limit=40000;
     
      double ArrayGreen[];  
      ArrayResize(ArrayGreen,limit);
      for (int i=0;i>=limit;i++)
         {
            ArrayGreen[i] =iCustom(NULL,0,"Kolier_SuperTrend_Indi",ATR_Period,ATR_Multiplier,0,1);
         }
      int max=ArrayMaximum(ArrayGreen,Quant,0); 
      double iMaximum = ArrayGreen[max];
      Print("Max = ",ArrayGreen[max]," at index=",max); 

      
     
      double ArrayRad[];  
      ArrayResize(ArrayRad,limit);
      for (int i=0;i>=limit;i++)
         {
            ArrayRad[i] = iCustom(NULL,0,"Kolier_SuperTrend_Indi",ATR_Period,ATR_Multiplier,1,1);
         }
     int min=ArrayMinimum(ArrayRad,Quant_Bars,0); 
     double iMinimum = ArrayRad[min];
     Print("Min= ",ArrayRad[min]," at index=",min); 
 
Corvin85:

I want to find the Min Max of indicator data, I've done "everything according to the manual", but it feels like the indicator data is not written to an array. If you are an MQL pro, please advise me where I made a mistake.

The variable limit has a value greater than zero. Therefore, none of the loops will run. As a result, ArrayGreen and ArrayRad will remain unfilled.

If we set limit to zero or less, the program will loop back to the first loop.

Thus, we need to modify the loops condition. Most likely, it should be done like this:

 for (int i = 0; i < limit; i++)
 
Corvin85:

I want to find the Min Max of indicator data, I've done "everything according to the manual", but it feels like the indicator data is not written to an array. I have a good MQL pro, please advise me where I made a mistake.

Also, in iCustom(...........); the last passed parameter i

 for (int i=0;i<limit;i++)
         {
            ArrayGreen[i] =iCustom(NULL,0,"Kolier_SuperTrend_Indi",ATR_Period,ATR_Multiplier,0,i);
         }

something like this.

 
Thank you! It's working!
 

Good afternoon!


For the convenience of testing, I want to remove the button to enable and disable the condition, so that I don't have to go into the code every time and don't have to change this condition into text to make it ineffective.

In other words, right now I do it this way:

if ((Close[1]<=High[2])&&(Close[1]>=Low[2])&&(Open[1]<=High[2])&&(Open[1]>=Low[2]))
{

Turning it off like this:

//if ((Close[1]<=High[2])&&(Close[1]>=Low[2])&&(Open[1]<=High[2])&&(Open[1]>=Low[2]))
//{

I tried to pull the enable and disable into input bool Y=True; (Where Y is the condition), assign Y to the condition, and split branches if the condition is or is not in effect via else if. But something didn't work out.

Can you advise how to proceed in such cases?

 
YanSay:

Good afternoon!


For the convenience of testing, I want to remove the button to enable and disable the condition, so that I don't have to go into the code every time and don't have to change this condition into text to make it ineffective.

In other words, right now I do it this way:

Turning it off like this:

I tried to pull the enable and disable into input bool Y=True; (Where Y is the condition), assign Y to the condition, and split branches if the condition is or is not in effect via else if. But something didn't work out.

Please, advise what to do in such cases?

One could do the following

input bool FLAG =True;


if (FLAG && (Close[1]<=High[2])&&(Close[1]>=Low[2])&&(Open[1]<=High[2])&&(Open[1]>=Low[2]))
{
 
Vitaly Muzichenko:

You could do this.

The reason is that the algorithm ignores the False condition and proceeds to the next conditions.

input bool FLAG =False;

The algorithm will not go further, while it should ignore this condition when the code is False and go to the next conditions.

In my case, is it the only way to specify 2 branches?

input bool FLAG =True;

if (FLAG=True)
{(Close[1]<=High[2])&&(Close[1]>=Low[2])&&(Open[1]<=High[2])&&(Open[1]>=Low[2]))
 {//следующие условия
 }
}

if (FLAG=False)
 {//следующие условия
 }

Or is there an easier way?

 
YanSay:

In your version it turns out that if the value

The algorithm will not go further, while it should ignore this condition if it is False and go to the next conditions.

In my case, the only option is to write 2 branches?

Or is there an easier way?

//+------------------------------------------------------------------+
input bool FLAG =True;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
  if(FLAG) {
    if(Close[1]<=High[2]) && (Close[1]>=Low[2]) && (Open[1]<=High[2]) && (Open[1]>=Low[2])
    //...
  } else {
    //следующие условия
  }
//+------------------------------------------------------------------+
 
YanSay:

In your version it turns out that if the value

The algorithm will not go further, while it should ignore this condition if it is False and go to the next conditions.

In my case, the only option is to write 2 branches?

Or is there an easier way?

Only this way

if(!FLAG || (Close[1]<=High[2] && Close[1]>=Low[2] && Open[1]<=High[2] && Open[1]>=Low[2]))
Reason: