#property  indicator_buffers 1
#property indicator_chart_window

double     ExtACBuffer[];

// Input parameters
extern int midnightHour = 0; // Hour of the midnight open in New York EST (0-23)
extern int midnightMinute = 0; // Minute of the midnight open in New York EST (0-59)

// Global variables
datetime prevDate; // Previous date
double prevNYClose; // Previous New York EST market close price
double prevNYOpen; // Previous New York EST midnight open price

// Custom indicator initialization function
int init()
{
    SetIndexBuffer(0, ExtACBuffer);
    prevDate = 0;
    return 0;
}

// Custom indicator start function
int start()
{
    datetime currentDate = Time[0]; // Current date
    double currentNYClose = Close[0]; // Current New York EST market close price
    //double currentNYOpen; // Current New York EST midnight open price
    int bias; // Daily bias (1 for up, -1 for down)

    // Check if a new trading day has started
    if (TimeDay(currentDate) != TimeDay(prevDate))
    {
        prevNYClose = currentNYClose;
        prevNYOpen = iOpen(_Symbol, PERIOD_D1, prevDate); // Get previous day's open from daily chart
    }

    // Compare previous New York EST market close price with previous midnight open price
    if (prevNYClose > prevNYOpen)
    {
        bias = 1; // Up bias
    }
    else if (prevNYClose < prevNYOpen)
    {
        bias = -1; // Down bias
    }
    else
    {
        bias = 0; // No bias
    }

    // Draw arrows on the chart based on the daily bias
    if (bias == 1)
    {
        Comment("Daily Bias: UP");
        ObjectCreate("DailyBiasArrow", OBJ_ARROW, 0, prevDate, prevNYClose);
        ObjectSet("DailyBiasArrow", OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
        ObjectSet("DailyBiasArrow", OBJPROP_COLOR, clrGreen);
    }
    else if (bias == -1)
    {
        Comment("Daily Bias: DOWN");
        ObjectCreate("DailyBiasArrow", OBJ_ARROW, 0, prevDate, prevNYClose);
        ObjectSet("DailyBiasArrow", OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
        ObjectSet("DailyBiasArrow", OBJPROP_COLOR, clrRed);
    }
    else
    {
        Comment("Daily Bias: NONE");
        ObjectDelete("DailyBiasArrow");
    }

    prevDate = currentDate; // Update previous date

    return 0;
}
