iHighest error 4051 - page 2

 
fly7680: I fixed the code but I have the same problem ... this indicator has to read data to the historic but it does not properly.my problem is in this line, but I do not know why
  1. N = iHighest(NULL,0,MODE_CLOSE,6+i,4+i);        
    If I is 100, then you are looking at bars [104 .. 209] 106 bars. If I is 200 you are looking at bars [204 .. 409] 206 bars. Can you answer the question "What is your lookback?" No you can't.
  2. What should the second from the last parameter be?

  3. int limit = rates_total - prev_calculated;
    if(prev_calculated < 1) limit=MathMin(5000-1, rates_total-1-50);
    :
    return(rates_total);
  4. honest_knave #6 posted part of my post to do your look back correctly
    I linked #7 to my post to do your look back correctly.
    Once you fix #1, Fix look backs correctly.
 

Whroeder1 Thanks for your help, I do not understand how to write this code for the correct reading of the stroico.


//set all accessed arrays and buffers to ArraySetAsSeries(false) Not the Predefined Variables

   for(int iBar = MathMax(lookback, prev_calculated; iBar < Bars; ++iBar){
      // To access a Timeseries use index=Bars -1- iBar
      // and convert any results back index=Bars -1- result
   }
   return rates_total-1; // Recalculate current bar next tick.

//Always count up so you're not using future values.


int lookback = //I do not understand this
 
fly7680:
int lookback = //I do not understand this
First define your maximum lookback.
int lookback = ... // iMA(period) has look back of period.
                        // buffer[i+2] has look back of 2 (as TimeSeries)
                        // buffer[i-2] has look back of 2 (not TimeSeries)
                       // use maximum of all.
int lookback = ... // iMA(period) has look back of period.
                   // buffer[i+2] has look back of 2 (as TimeSeries)
                   // buffer[i-2] has look back of 2 (not TimeSeries)
                   // use maximum of all.

Your code has a maximum of: 

         bool Pattern = iOpen(Symbol(), PERIOD_CURRENT, 1+i)  > iClose(Symbol(), PERIOD_CURRENT, 1+i)  
                     && iOpen(Symbol(), PERIOD_CURRENT, 2+i)  > iClose(Symbol(), PERIOD_CURRENT, 2+i)
                     && iOpen(Symbol(), PERIOD_CURRENT, 3+i)  > iClose(Symbol(), PERIOD_CURRENT, 3+i)
                     && iOpen(Symbol(), PERIOD_CURRENT, 4+i)  < iClose(Symbol(), PERIOD_CURRENT, 4+i);
So your lookback would be...?
 

I updated the code but nothing has changed

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
   {
   int limit = rates_total - prev_calculated;
   int lookback= Buffer1[4];
  
   //--- initial zero
  
  
  
   //--- main loop
   //for(int i = limit-1; i >= 0; i--)
  
  
       for(int i = MathMax(lookback, prev_calculated); i < Bars; ++i)
      
       {  
      
    
         double val;
         int N;
    
         bool Pattern = Open [1+i]  > Close[ 1+i]  
                     && Open [2+i]  > Close[ 2+i]
                     && Open [3+i]  > Close[ 3+i]
                     && Open [4+i]  < Close[ 4+i];            
        
      
      //Indicator Buffer 1
        if( Pattern == true )
        
        
        
        {
         N = iHighest(NULL,0,MODE_CLOSE,6+i,4+i);        
         if(N!=-1) val = High[N];
         else PrintFormat("Error in call iHighest. Error code=%d. Bars=%i start=%i",GetLastError(),Bars,4+i);
         Buffer1[N] = val + 30*Point;
         Print("Numero Candela: "+IntegerToString(N));
        }

   return(rates_total-1);
}
//+------------------------------------------------------------------+
 
fly7680:

I updated the code but nothing has changed

   int lookback= Buffer1[4];

You need to be very precise when writing code.

WHRoeder's notes say: 

buffer[i+2] has look back of 2 (as TimeSeries)

It does not say:

buffer[i+2] has look back of buffer[2] (as TimeSeries)

___________________

fly7680:

I updated the code but nothing has changed

for(int i = MathMax(lookback, prev_calculated); i < Bars; ++i)

 You have chosen to use WHRoeder's final example:

New way, counting up, not aTimeSeries.
   set all accessed arrays and buffers to ArraySetAsSeries(false) Not the Predefined Variables

   for(int iBar = MathMax(lookback, prev_calculated; iBar < Bars; ++iBar){
      // To access a Timeseries use index=Bars -1- iBar
      // and convert any results back index=Bars -1- result
   }
   return rates_total-1; // Recalculate current bar next tick.

You cannot ignore the comments. WHRoeder rarely writes something without meaning.

 I suggest you use this example instead, to avoid more confusion:

for(int iBar = Bars-1-MathMax(lookback, prev_calculated); iBar >= 0; --iBar){

 _____________________

You still need to fix this. It is wrong, as WHRoeder explained above:

fly7680:

I updated the code but nothing has changed

N = iHighest(NULL,0,MODE_CLOSE,6+i,4+i);

 

 
really thanks to everyone for the help ... I am a beginner and some concepts can not understand them. I added this code, but still we did not.
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
   {
   int limit = rates_total - prev_calculated;
   int lookback = Buffer1[4];
  
   ArraySetAsSeries(Buffer1, false);  
  
  
  
       for(int i = Bars-1-MathMax(lookback, prev_calculated); i >= 0; --i){      
    
         double val;
         int N;
    
         bool Pattern = Open [1+i]  > Close[ 1+i]  
                     && Open [2+i]  > Close[ 2+i]
                     && Open [3+i]  > Close[ 3+i]
                     && Open [4+i]  < Close[ 4+i];            
        
      
      //Indicator Buffer 1
        if( Pattern == true )
        
        
        
        {
         N = iHighest(NULL,0,MODE_CLOSE,6+i,4+i);        
         if(N!=-1) val = High[N];
         else PrintFormat("Error in call iHighest. Error code=%d. Bars=%i start=%i",GetLastError(),Bars,4+i);
         Buffer1[N] = val + 30*Point;
         Print("Numero Candela: "+IntegerToString(N));
        }
        
        
    

   return rates_total-1;
  }
 

You have been told many times about

N = iHighest(NULL,0,MODE_CLOSE,6+i,4+i); 

but you still do nothing about it.

What are you trying to do?

break it down using some different values for i

What does it do?

 
fly7680:
really thanks to everyone for the help ... I am a beginner and some concepts can not understand them. I added this code, but still we did not.
   int lookback = Buffer1[4];
  
   ArraySetAsSeries(Buffer1, false);  
  
  N = iHighest(NULL,0,MODE_CLOSE,6+i,4+i);        

 

You seem to be ignoring most of the comment people give you. You can't do that. Your code will not work.

  • You haven't changed lookback.
  • You have added a line that makes the Pattern logic look into the future. If you don't understand what something does, stop and read the documentation.
  • You haven't fixed iHighest. 
 

Hello everyone and thank you again for your comments. I did not understand what is the difference if I use "i" in candles or "i" in iHighest. I found another soluzuone which is fine for me.


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
   {
   int limit = rates_total - prev_calculated;
   int lookback = Buffer1[4];
  
   ArraySetAsSeries(Buffer1, true);  
  
  
  
       for(int i = Bars-1-MathMax(lookback, prev_calculated); i >= 0; --i){  
            
    
         bool Pattern = Open [1+i]  > Close[ 1+i]  
                     && Open [2+i]  > Close[ 2+i]
                     && Open [3+i]  > Close[ 3+i]
                     && Open [4+i]  < Close[ 4+i];  
                    
         bool C4 = Close[4+i] > Close[5+i] && Close[4+i] > Close[6+i];
         bool C5 = Close[5+i] > Close[4+i] && Close[5+i] > Close[6+i];
         bool C6 = Close[6+i] > Close[4+i] && Close[6+i] > Close[5+i];
      
      //Indicator Buffer 1
        if( Pattern == true && C4 == true )          Buffer1[4+i] = High[4+i] + 30*Point;
        if( Pattern == true && C5 == true )          Buffer1[5+i] = High[5+i] + 30*Point;
        if( Pattern == true && C6 == true )          Buffer1[6+i] = High[6+i] + 30*Point;
    
      
      
      }  
    

   return rates_total-1;
  }
//+------------------------------------------------------------------+
 

There are still problems with your lookback, but if you're happy with how your code works, great!

I'd like to say I'm glad we helped, but I'm not entirely sure we did.