//+------------------------------------------------------------------+
//|                                              Arrow Signal.mq4    |
//|                        User-defined MT4 Indicator                |
//+------------------------------------------------------------------+
#property copyright "User"
#property link      "https://example.com"
#property version   "1.02"
#property indicator_chart_window
#property indicator_buffers 2
#property strict

//
//
//

input color BuyArrowColor    = clrBlue;       // Color of buy arrow
input color SellArrowColor   = clrRed;        // Color of sell arrow
input int   ArrowOffset      = 20;            // Offset for arrows (in points)
input int   BuyArrowStyle    = 233;           // Style of buy arrow (default: Arrow Up)
input int   SellArrowStyle   = 234;           // Style of sell arrow (default: Arrow Down)
input int   ArrowSize        = 2;             // Size of arrows

double upArr[],dnArr[],trend[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int OnInit()
{
   IndicatorBuffers(3);
   SetIndexBuffer(0, upArr,INDICATOR_DATA); SetIndexStyle(0, DRAW_ARROW, EMPTY,ArrowSize,BuyArrowColor); SetIndexArrow(0, BuyArrowStyle);
   SetIndexBuffer(1, dnArr,INDICATOR_DATA); SetIndexStyle(1, DRAW_ARROW, EMPTY,ArrowSize,SellArrowColor);SetIndexArrow(1, SellArrowStyle);
   SetIndexBuffer(2, trend,INDICATOR_CALCULATIONS);

   IndicatorSetString(INDICATOR_SHORTNAME,"Arrow Signal");
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[])
{
   int i=rates_total-prev_calculated+1; if (i>=rates_total) i=rates_total-1; 
   
   for (; i>=0 && !_StopFlag; i--)
   {
      
      trend[i] = (i<rates_total-1) ? (low[i]<low[i+1] && close[i]>open[i]) ? 1 : (high[i]>high[i+1] && close[i]<open[i]) ? -1 : 0 : 0;
      upArr[i] = dnArr[i] = EMPTY_VALUE;
      if (i<rates_total-1 && trend[i] != trend[i+1])
      {
        if (trend[i] == 1) upArr[i] = low[i]  - ArrowOffset * _Point;
        if (trend[i] ==-1) dnArr[i] = high[i] + ArrowOffset * _Point;
      }
   }
return(rates_total);
}
