I want to put draw limit on trend line line for last 100 bar below is the code. Please Help

 

//+------------------------------------------------------------------+
//|                                     SwingMan HiLo Activator2.mq4 |
//|                                                         SwingMan |
//|                                               soc607@t-online.de |
//+------------------------------------------------------------------+
#property copyright "SwingMan"
#property link      "soc607@t-online.de"

#property indicator_chart_window

//---- indicator settings
#property  indicator_buffers 2
#property  indicator_color1  Red
#property  indicator_color2  Blue

//---- input parameters ----------------------------------------------
extern int Period_HiLo = 10;
//--------------------------------------------------------------------

double BufferHighs[];
double BufferLows[];
//-- Arrays
double dHighs[],dLows[];
//-- variables
int iTrend;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//-- Arrays
   ArraySetAsSeries(dHighs,true);
   ArraySetAsSeries(dLows,true);
//---- indicator buffers mapping
   SetIndexBuffer(0,BufferHighs);
   SetIndexBuffer(1,BufferLows);   
  
   //---- drawing settings   
   SetIndexStyle(0,DRAW_LINE,0,2);  // Highs
   SetIndexStyle(1,DRAW_LINE,0,2);  // Lows   

   IndicatorDigits(Digits);
   
   SetIndexDrawBegin(0,Period_HiLo);
   SetIndexDrawBegin(1,Period_HiLo);

//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("SwingMan HiLoActivator2");
   Comment("SwingMan HiLoActivator2 (" + Period_HiLo +") ");
   
   SetIndexLabel(0,"Highs");
   SetIndexLabel(1,"Lows");
//--
   iTrend = 0;
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   if (counted_bars<0) return(-1);
   if(Bars<=10) return(0);
   if (counted_bars>0) counted_bars--;   
   int limit = Bars - counted_bars;
   
   ArrayResize(dHighs,Bars);
   ArrayResize(dLows,Bars);
//----
   for (int i = 0; i <=limit-1; i++) 
   {
      dHighs[i] = iMA(NULL, 0, Period_HiLo, 0, MODE_SMA, PRICE_HIGH, i);
      dLows[i]  = iMA(NULL, 0, Period_HiLo, 0, MODE_SMA, PRICE_LOW, i);
   }
   
   for (i=limit-Period_HiLo; i >=0; i--) 
   {  
      BufferHighs[i] = EMPTY_VALUE;
      BufferLows[i] = EMPTY_VALUE;
      //-- first trend
      if (iTrend == 0) {
         if (Close[i] > dHighs[i]) iTrend = 1;
         else
         if (Close[i] < dLows[i]) iTrend = -1;
      }
      
      //-- up trend
      if (iTrend == 1) {
         if (Close[i] < dLows[i]) {
            BufferHighs[i] = dHighs[i];
            iTrend = -1;
         }
         else {
            BufferLows[i] = dLows[i];
         }   
      }
      else
      //-- down trend
      if (iTrend == -1) {
         if (Close[i] > dHighs[i]) {
            BufferLows[i] = dLows[i];
            iTrend = 1;
         }
         else {
            BufferHighs[i] = dHighs[i];
         }   
      }
   }   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. ArrayResize(dHighs,Bars);
    ArrayResize(dLows,Bars);
    :
    if (Close[i] > dHighs[i]) iTrend = 1;
    Those two must be buffers not arrays. Resizing arrays will not shift existing values, but the if statement assumes they are.
  3. Do not use separate a variable (iTrend.) After the first run, you must retrieve the trend for index one to be used on index 0. Either process bar zero never or only once.
  4. int limit = Bars - counted_bars;
    for (int i = 0; i <=limit-1; i++) 
       :
       dHighs[i] = iMA(NULL, 0, Period_HiLo, 0, MODE_SMA, PRICE_HIGH, i);
    
    The look back length for MA is Period_HiLo. The look back length for trend is that plus 1. Do your lookbacks correctly.
  5. Help you with what? You haven't stated a problem.