//+------------------------------------------------------------------+
//|                                                      FF Test.mq4 |
//|                                          Copyright 2021, Shoumma |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright@2021 Shouma"
int handle_ind;
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 Red
#property indicator_chart_window
#property indicator_buffers 4
double CrossUp[];
double CrossDown[];
extern int Space = 20;
int TrendlineCounterLong = 0;
int TrendlineCounterShort = 100000;
int barstemp=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY,1);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY,1);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start() {

   if(barstemp!=Bars){
     
        barstemp = Bars;  

      double LastShortValueOne = iCustom(Symbol(),PERIOD_CURRENT,"MAbufferhist.ex4",14,0,0,5,0,2);
      double LastShortValueTwo = iCustom(Symbol(),PERIOD_CURRENT,"MAbufferhist.ex4",14,0,0,5,1,2);
      double NowShortValueOne = iCustom(Symbol(),PERIOD_CURRENT,"MAbufferhist.ex4",14,0,0,5,0,1);
      double NowShortValueTwo = iCustom(Symbol(),PERIOD_CURRENT,"MAbufferhist.ex4",14,0,0,5,1,1);    
       
      double LastLongValueOne = iCustom(Symbol(),PERIOD_CURRENT,"MAbufferhist.ex4",24,1,0,5,0,2);
      double LastLongValueTwo = iCustom(Symbol(),PERIOD_CURRENT,"MAbufferhist.ex4",24,1,0,5,1,2);
      double NowLongValueOne = iCustom(Symbol(),PERIOD_CURRENT,"MAbufferhist.ex4",24,1,0,5,0,1);
      double NowLongValueTwo = iCustom(Symbol(),PERIOD_CURRENT,"MAbufferhist.ex4",24,1,0,5,1,1);
      
            
      if (LastShortValueOne == 0 && LastLongValueOne == 0 && NowShortValueOne == 1 && NowLongValueOne == 1) {
         CrossUp[1] = Low[1];
         CreateObjects(); 
         TrendlineCounterLong++;
         TrendlineCounterShort++; 
      }
      else if (LastShortValueTwo == 0 && LastLongValueTwo == 0 && NowShortValueTwo == 1 && NowLongValueTwo == 1) {
          CrossDown[1] = High[1];
          CreateObjects();
          TrendlineCounterLong++;
          TrendlineCounterShort++; 
      }

 
   return(0);

 }
}
void CreateObjects(){
         double TrendlineLongPrice = High[1]+Space*Point;
         double TrendlineShortPrice = Low[1]-Space*Point;
         ObjectCreate(0,TrendlineCounterLong,OBJ_TREND,0,iTime(NULL,PERIOD_CURRENT,1),TrendlineLongPrice,iTime(NULL,PERIOD_CURRENT,10),TrendlineLongPrice);
         ObjectSetInteger(0,TrendlineCounterLong,OBJPROP_RAY_RIGHT, false); 
         ObjectSetInteger(0,TrendlineCounterLong,OBJPROP_COLOR, clrAqua); 
         
         ObjectCreate(0,TrendlineCounterShort,OBJ_TREND,0,iTime(NULL,PERIOD_CURRENT,1),TrendlineShortPrice,iTime(NULL,PERIOD_CURRENT,10),TrendlineShortPrice);
         ObjectSetInteger(0,TrendlineCounterShort,OBJPROP_RAY_RIGHT, false); 
         ObjectSetInteger(0,TrendlineCounterShort,OBJPROP_COLOR, clrAqua);
}