//+------------------------------------------------------------------+
//|                                              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 indicator_color1 Blue
#property indicator_color2 Red

// Buffers for arrows
double BuyArrowBuffer[];
double SellArrowBuffer[];

// Input parameters
input color BuyArrowColor = Blue;       // Color of buy arrow
input color SellArrowColor = Red;       // 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

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   // Indicator buffers
   SetIndexBuffer(0, BuyArrowBuffer);
   SetIndexBuffer(1, SellArrowBuffer);

   // Set arrow properties for Buy
   SetIndexStyle(0, DRAW_ARROW, EMPTY, ArrowSize);
   SetIndexArrow(0, BuyArrowStyle);

   // Set arrow properties for Sell
   SetIndexStyle(1, DRAW_ARROW, EMPTY, ArrowSize);
   SetIndexArrow(1, SellArrowStyle);

   IndicatorShortName("Arrow Signal");
   IndicatorDigits(0);

   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 start = prev_calculated > 0 ? prev_calculated - 1 : 1; // Start from the previous calculation
   
   for(int i = start; i < rates_total; i++)
   {
      // Reset buffers
      BuyArrowBuffer[i] = 0;
      SellArrowBuffer[i] = 0;

      // Buy condition: lower low and close > open
      if(low[i] < low[i+1] && close[i] > open[i])
         BuyArrowBuffer[i] = low[i] - ArrowOffset * Point;

      // Sell condition: higher high and close < open
      if(high[i] > high[i+1] && close[i] < open[i])
         SellArrowBuffer[i] = high[i] + ArrowOffset * Point;
   }
   return(rates_total);
}
//+------------------------------------------------------------------+