set previous existing buffers into an array

 

Hello

I need to check if each "new fractal" or "current price" is above/bellow "previous fractal"

But don't know how to find the "previous fractal" price.Tried to set existing buffers in to an array but was not success, for example tried following code but not success.


Declaration new array :

static double Fractals_UP [];

Then each time new fractal occurred :

if (bFound)

         {

            ExtUpFractalsBuffer[i]=dCurrent;

            for (int n=10 ; n>1 ; n--) Fractals_UP[n-1] = Fractals_UP[n]; // saving 10 last fractals in to array

            Fractals_UP[1]=ExtDownFractalsBuffer[i];

         }


Now I expect that Fractals_UP[1] should be previous fractal price value and Fractals_UP[2] should be 2 past fractal and ...

Guess I'm totally wrong because I'm new to programming. If possible please help me to find correct way.





Bellow is the indicator :

//+------------------------------------------------------------------+
//|                                               Fractals+Alert.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property strict  
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_width1 1
#property indicator_width2 1
//---- input parameters
//---- buffers
double ExtUpFractalsBuffer[];
double ExtDownFractalsBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int OnInit()
   {
//---- indicator buffers mapping  
    SetIndexBuffer(0,ExtUpFractalsBuffer);
    SetIndexBuffer(1,ExtDownFractalsBuffer);   
//---- drawing settings
    SetIndexStyle(0,DRAW_ARROW);
    SetIndexArrow(0,119);
    SetIndexStyle(1,DRAW_ARROW);
    SetIndexArrow(1,119);
//----
    SetIndexEmptyValue(0,0.0);
    SetIndexEmptyValue(1,0.0);
//---- name for DataWindow
    SetIndexLabel(0,"Fractal Up");
    SetIndexLabel(1,"Fractal Down");
//---- initialization done   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   Comment("");
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, // total bars
                const int prev_calculated, // calculated bars by indicator
                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+3;
int count=prev_calculated;
int    i;
bool   bFound;
double dCurrent;
   for( i=limit-count; i>=3;i--)  

     {
    if ((Bars-i)>=7)
    {
      //------------------------Fractals up - START
         dCurrent =   High[i];
         bFound=false;
         
         if                                  (dCurrent>High[i+1] && dCurrent>High[i+2] && dCurrent>High[i-1] && dCurrent>High[i-2] && Volume[i-3]>0) bFound=true; //----5 bars Fractal
         if (  (!bFound && (Bars-i-1)>=3) && (dCurrent==High[i+1] && dCurrent>High[i+2] && dCurrent>High[i+3] && dCurrent>High[i-1] && dCurrent>High[i-2] && Volume[i-3]>0)  ) bFound=true;    //----6 bars Fractal
         if (  (!bFound && (Bars-i-1)>=4) && (dCurrent>=High[i+1] && dCurrent==High[i+2] && dCurrent>High[i+3] && dCurrent>High[i+4] && dCurrent>High[i-1] && dCurrent>High[i-2] && Volume[i-3]>0) ) bFound=true;   //----7 bars Fractal
         if (  (!bFound && (Bars-i-1)>=5) && (dCurrent>=High[i+1] && dCurrent==High[i+2] && dCurrent==High[i+3] && dCurrent>High[i+4] && dCurrent>High[i+5] && dCurrent>High[i-1] && dCurrent>High[i-2] && Volume[i-3]>0)  ) bFound=true;   //----8 bars Fractal 
         if (  (!bFound && (Bars-i-1)>=6) && (dCurrent>=High[i+1] && dCurrent==High[i+2] && dCurrent>=High[i+3] && dCurrent==High[i+4] && dCurrent>High[i+5] && dCurrent>High[i+6] && dCurrent>High[i-1] && dCurrent>High[i-2] && Volume[i-3]>0)   ) bFound=true;   //----9 bars Fractal  

         if (bFound)
         {
            ExtUpFractalsBuffer[i]=dCurrent;
         }
      //------------------------Fractals down
          dCurrent=Low[i];
         bFound=false;
         if                                  (dCurrent<Low[i+1] && dCurrent<Low[i+2] && dCurrent<Low[i-1] && dCurrent<Low[i-2] && Volume[i-3]>0)  bFound=true; //----5 bars Fractal
         if (  (!bFound && (Bars-i-1)>=3) && (dCurrent==Low[i+1] && dCurrent<Low[i+2] && dCurrent<Low[i+3] && dCurrent<Low[i-1] && dCurrent<Low[i-2] && Volume[i-3]>0)  ) bFound=true;  //----6 bars Fractal
         if (  (!bFound && (Bars-i-1)>=4) && (dCurrent<=Low[i+1] && dCurrent==Low[i+2] && dCurrent<Low[i+3] && dCurrent<Low[i+4] && dCurrent<Low[i-1] && dCurrent<Low[i-2] && Volume[i-3]>0) ) bFound=true;  //----7 bars Fractal
         if (  (!bFound && (Bars-i-1)>=5) && (dCurrent<=Low[i+1] && dCurrent==Low[i+2] && dCurrent==Low[i+3] && dCurrent<Low[i+4] && dCurrent<Low[i+5] && dCurrent<Low[i-1] && dCurrent<Low[i-2] && Volume[i-3]>0)   )  bFound=true; //----8 bars Fractal
         if (  (!bFound && (Bars-i-1)>=6) && (dCurrent<=Low[i+1] && dCurrent==Low[i+2] && dCurrent<=Low[i+3] && dCurrent==Low[i+4] && dCurrent<Low[i+5] && dCurrent<Low[i+6] && dCurrent<Low[i-1] && dCurrent<Low[i-2] && Volume[i-3]>0)  )   bFound=true; //----9 bars Fractal

         if (bFound)
         {   
            ExtDownFractalsBuffer[i]=dCurrent;
         }
         
         
  
     }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+