Please help me, thank you

 

Rookie problem, write 5 consecutive closing prices in a loop, but it is not correct, please help me, thank you



//+------------------------------------------------------------------+
//|                                             continuity test2.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "hhv"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1



//--- indicator buffers
double         hhvbuffer[];


int count=0;
int signal=0;
bool var1;
bool var2;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,hhvbuffer);
   SetIndexBuffer(1,llvbuffer);
   SetIndexBuffer(2,signalbuffer);
  
  
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   ArraySetAsSeries(hhvbuffer,true);
	
   int bars=rates_total-5;
   if(prev_calculated>0) 
   bars=rates_total-prev_calculated;
   
   for(int i=bars; i>=0; i--)
   {
    
   
  for(count=1;count<=5;count++)
  {
  if(close[i]>close[i+1])
 
   if(count==5)
   {
  break;
  }
   hhvbuffer[i]=1;
   
  }
   
   }
  
   return(rates_total);
  }
//+------------------------------------------------------------------+

 
Please guide me thank you
 
  1. You edited your posted code, it is now unreadable.
  2. Please post only in English on this part of the forums. Use the automatic translation tool if needed. Use simple language structure when using mechanical translation. (2013)

  3. You wrote “5 consecutive closing prices” but your code seems to want “5 consecutive higher closing prices.”
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

  4. Your code starts with i=bars, but then accesses close[i] and close[i+1] which do not exist. See How to do your lookbacks correctly #9#14 & #19.

    Have you set both close and hhvbuffer to as-series? In MT5, you must set the direction.

    To define the indexing direction in the time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[] arrays, call the ArrayGetAsSeries() function. In order not to depend on defaults, call the ArraySetAsSeries() function for the arrays to work with.
              Event Handling / OnCalculate - Reference on algorithmic/automated trading language for MetaTrader 5
  5. I assume you actually want higher prices:

       ArraySetAsSeries(close,     true); 
       ArraySetAsSeries(hhvbuffer, true);
       #define LOOKBACK 5     // Test close[i] : close[i+1] through close[i+4] : close[i+5]
       for(int i=rates_total - 1 - MathMax(LOOKBACK, prev_calculated); i>=0; --i){
          for(int count=0;count<LOOKBACK;count++){   // Test bars.
            if(close[i+count] > close[i+1+count]){   // Found one.
               if(count+1==LOOKBACK} hhvbuffer[i]=1; // Found 5 consecutive higher closes.
                                                     // Keep looking.
            } else {                 hhvbuffer[i]=EMPTY_VALUE;  
                                     break;          // Not bar i.
            }
          }  // count
       }  // i
      
    //--- return value of prev_calculated for next call, minus one to retest bar zero on the next tick.
       return rates_total-1;
      }
 
Xiao Peng Liu # :

thank you for your reply! thank you very much! !

William Roeder # :
  1. You edited your posted code, it is now unreadable.
  2. Please post only in English on this part of the forums. Use the automatic translation tool if needed. Use simple language structure when using mechanical translation . (20 13 )

  3. You wrote “5 consecutive closing prices” but your code seems to want “5 consecutive higher closing prices.”
          How To Ask Questions The Smart Way . (20 04 )
               Be precise and informative about your problem

  4. Your code starts with i=bars , but then accesses close[i] and close[i+1] which do not exist. See How to do your lookbacks correctly #9#14 & #19 .

    Have you set both close and hhvbuffer to as-series? In MT5, you must set the direction.

  5. I assume you actually want higher prices:

thank you for your reply! thank you very much! ! !

 
Why don't I able to place my orders 
 
5003743042 #: Why don't I able to place my orders 
  1. Don't Hijack other threads for your off-topic post. Next time, make your own, new, thread.

  2. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file.
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

    We can't see your broken code.