Request help to modify my code to draw lines only from the hi/lo and skip inbetween candles

 

Hi,

i am trying to code an indicator that draws lines between swing hi and lows but the code I have is connecting the hi/lo of the candles in between. In the diagram I would like 1 line between the H and L or L and H as shown in yellow in the diagram and not many segments for a single line.

Thanks for any help.

/**********************
Code the flowing next bar
**********************/

#property copyright ""
#property link      ""

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Magenta



//---- buffers
double upArrow[];

datetime lastBarTime ;
int numberOfWaitedTicks = 0;

double O, O1, O2, C, C1, C2, L, L1, L2, L3, L4, H, H1, H2, H3, H4;


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {

   SetIndexStyle(0,DRAW_SECTION, STYLE_SOLID, 1, Blue);
   SetIndexBuffer(0, upArrow);
   return(0);
  }


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectsDeleteAll(0, OBJ_TEXT);
   ObjectsDeleteAll(0, OBJ_ARROW);
   return(0);
  }


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {

   int shift, shift2,shift1;
   string pattern, period;
   int setPattern = 0;

   bool previousHi, previousLo = false;

  for(shift = 0; shift <=  Bars - IndicatorCounted(); shift++)

     {

      shift1 = shift + 1;
      shift2 = shift + 2;

      O = Open[shift1];
      O1 = Open[shift2];

      H = High[shift1];
      H1 = High[shift2];


      L = Low[shift1];
      L1 = Low[shift2];


      C = Close[shift1];
      C1 = Close[shift2];

      if(H > H1)
        {
         if(previousHi)
            upArrow[shift2] = EMPTY_VALUE;
         drawArrowsAndLine(true, upArrow, "lbot", shift1);
         previousHi = true;
         previousLo = false;
        }
      else
         if(L < L1)
           {

            if(previousLo)
               upArrow[shift2] = EMPTY_VALUE;
            drawArrowsAndLine(false, upArrow, "hbot", shift1);
            previousLo = true;
            previousHi = false;
           }
     }

   return(0);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void drawArrowsAndLine(bool upSwing, double &arrows[], string lineName, int shift1)
  {
   if(upSwing)
     {
      arrows[shift1] = High[shift1] ;

     }
   else
     {
      arrows[shift1] = Low[shift1] ;

     }
    ChartRedraw();
  }
//+------------------------------------------------------------------+
 
Please don't post randomly in any section. Your topic has been moved to the section: MQL4 e MetaTrader 4