Errors, bugs, questions - page 3129

 
Alexey Viktorov #:

In your case this is not the case as both conditions must be met. But if you put this

then, yes. If condition "a" is satisfied, the second condition will not be checked. They have been fighting for it for many years and now you propose to return to the previous century...

Strangely enough, but with a=true not only at || but also at && there is no check of the rest. Otherwise how do you explain this (do not look for meaning in the operation of the indicator, we are talking about the code here):

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_type1   DRAW_ARROW
#property indicator_color1  Gray
#property indicator_label1  "Fractal Up"
//--- indicator buffers
double ExtUpperBuffer[];
//--- 10 pixels upper from high price
int    ExtArrowShift=-10;

void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtUpperBuffer,INDICATOR_DATA);
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_ARROW,217);
//--- arrow shifts when drawing
   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,ExtArrowShift);
//--- sets drawing line empty value--
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
  }

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   if(rates_total<5)
      return(0);

   int start;
//--- clean up arrays
   if(prev_calculated<7)
     {
      start=2;
      ArrayInitialize(ExtUpperBuffer,EMPTY_VALUE);
     }
   else
      start=rates_total-5;

   for(int i=start; i<rates_total-3 && !IsStopped(); i++)
     {
      //--- Upper Fractal
      if(high[i]>high[i+1] && high[i]>high[i+2] && high[i]>high[i+3] && high[i]>high[i+4])
         ExtUpperBuffer[i]=high[i];
      else
         ExtUpperBuffer[i]=EMPTY_VALUE;
     }

   return(rates_total);
  }

The terminal is silent. But if you change

if(high[i]>high[i+1] && high[i]>high[i+2] && high[i]>high[i+3] && high[i]>high[i+4])

to

if(high[i]>high[i+4] && high[i]>high[i+2] && high[i]>high[i+3] && high[i]>high[i+1])

the programmer changes it and the notorious message 'array out of range' appears because the programmer immediately stumbles upon an array with an excessive index unlike the first case.

 
x572intraday #:

I don't dare to call it a bug. So I'll just say that I've noticed one peculiarity of the if statement. I suspect this may apply to other languages as well.

If a turns out to be true, check skips to Array[over_index] and here the terminal starts crashing through the'array out of range' part, which is quite true. But if a turns out to be false, the terminal will not check for the Array[over_index] condition and hence for index redundancy, and if will skip further and the coder will not know that there is an array with a non-existing index in his program... or rather an existing but redundant one.

Maybe there should be a fix for it so that the check for 'array out of range' would be carried out to the very end of the if loop and the same message would be output? Or it will significantly reduce speed of the operator?


In what language is the syntax different? "Syntax literally means not only composing, but also arranging...".

If you want to check if there is an 'array out of range', change the ordering.

if(Array[over_index]>val && a) {...}
 
Lilita Bogachkova #:

In what language is the syntax different?"Syntax literally means not just composing, but also ordering...".

If you want to check if there is an 'array out of range', change the order.

The ordering is desirable as you need to check.

For example, if 'a' is changed more often, it is better to put it as the first argument.

 
Vitaly Muzichenko #:

The order is desirable as checks are necessary.

For example, if "a" changes more often, it is better to put it as the first argument.

No, the first depends on the main conditions, the others are just additional conditions.

For example, it is irrelevant to check the hour of the current working time if the working time has not yet started.
 

In fact, I came across this feature by accident. That's not what I wanted...

if(high[i]>high[i+1] && high[i]>high[i+2] && high[i]>high[i+3] && ... && high[i]>high[i+n])

or

if(high[i]>high[i+1])
   if(high[i]>high[i+2])
      if(high[i]>high[i+3])
         if(...)
            if(high[i]>high[i+n])

The trouble is that n can be quite large, so I wanted to wrap up this long chain of conditions into a compact for. I tried it this way:

for(int i=start; i<rates_total-3 && !IsStopped(); i++)
{
   bool h_plus=true; //false?
   for(int increment=1; increment<=n; increment++)
      h_plus&=high[i]>high[i+increment];
   if(h_plus) {...}
   ...
}

but it turned out to be a bit of a mess. Well at least because h_plus with this algorithm will have to take the whole sum of checked conditions, including the condition with redundant index array check, which didn't happen in first unwrapped if, without for. And other varnings spoil the picture.

Is this even worth considering? Is it possible to do this?

 
Lilita Bogachkova #:

In what language is the syntax different? "Syntax literally means not just composing, but also ordering...".

If you want to check if there is an 'array out of range', change the order.

You don't always know in advance what to put before and what to put after.

 
Lilita Bogachkova #:

No, the first one determines the basic conditions, the others are just additional conditions.

For example, it is irrelevant to check the hour of the current working time if the working time has not yet started.

Yes, first we check the signal conditions, go through the array and compare, check the current price, and then it turns out that the time is not right, but before that a lot of complicated actions are performed.

Right?

 
Vitaly Muzichenko #:

Yes, first we check the signal conditions, go through the array and compare, check the current price, and then it turns out that the time is not right, but a lot of complicated actions have been done before that.

Right?

Right, you shouldn't do that.
 
Vitaly Muzichenko #:

Check

Who told you that "a" from the condition above would always be false?

 
x572intraday #:

In fact, I came across this feature by accident. That's not what I wanted...

or

The trouble is that n can be quite large, so I wanted to wrap up this long chain of conditions into a compact for. I tried it this way:

but it turned out to be a bit of a mess. Well at least because h_plus with this algorithm will have to take the whole sum of checked conditions, including the condition with redundant index array check, which didn't happen in first unwrapped if, without for. And other varnings spoil the picture.

Is this even worth considering? Is it possible to over-for?

Here's this code I don't understand at all

for(int i=start; i<rates_total-3 && !IsStopped(); i++)
{
   bool h_plus=true; //false?
   for(int increment=1; increment<=n; increment++)
      h_plus&=high[i]>high[i+increment];
   if(h_plus) {...}
   ...
}

What does the marked & in this code mean? And in what loop should if(h_plus) be executed? Didn't you miss any curved brackets?

Reason: