//+------------------------------------------------------------------+
//|                                           PricePointsMonitor.mq4 |
//|                                       Copyright 2025, Tophatd4v4 |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, Tophat4dv4"
#property link      ""
#property version   "1.00"
#property strict
#property indicator_chart_window

// Input parameters
input int Period1 = 5;           // First period
input int Period2 = 10;          // Second period
input int Period3 = 20;          // Third period
input int Period4 = 30;          // Fourth period
input ENUM_BASE_CORNER Corner = CORNER_LEFT_UPPER; // Display corner
input color TextColor = clrWhite; // Text color

//+------------------------------------------------------------------+
//| Custom indicator initialization function                           |
//+------------------------------------------------------------------+
int OnInit()
{
    // Create separate labels for title and each period
    ObjectCreate(0, "PricePoints_Title", OBJ_LABEL, 0, 0, 0);
    ObjectCreate(0, "PricePoints_1", OBJ_LABEL, 0, 0, 0);
    ObjectCreate(0, "PricePoints_2", OBJ_LABEL, 0, 0, 0);
    ObjectCreate(0, "PricePoints_3", OBJ_LABEL, 0, 0, 0);
    ObjectCreate(0, "PricePoints_4", OBJ_LABEL, 0, 0, 0);

    // Set properties for each label
    int y_offset = 0;
    int line_spacing = 15; // Pixels between lines

    // Title
    ObjectSetInteger(0, "PricePoints_Title", OBJPROP_CORNER, Corner);
    ObjectSetInteger(0, "PricePoints_Title", OBJPROP_XDISTANCE, 10);
    ObjectSetInteger(0, "PricePoints_Title", OBJPROP_YDISTANCE, 10 + y_offset);
    ObjectSetInteger(0, "PricePoints_Title", OBJPROP_XSIZE, 200);
    y_offset += line_spacing;

    // Period 1
    ObjectSetInteger(0, "PricePoints_1", OBJPROP_CORNER, Corner);
    ObjectSetInteger(0, "PricePoints_1", OBJPROP_XDISTANCE, 10);
    ObjectSetInteger(0, "PricePoints_1", OBJPROP_YDISTANCE, 10 + y_offset);
    ObjectSetInteger(0, "PricePoints_1", OBJPROP_XSIZE, 200);
    y_offset += line_spacing;

    // Period 2
    ObjectSetInteger(0, "PricePoints_2", OBJPROP_CORNER, Corner);
    ObjectSetInteger(0, "PricePoints_2", OBJPROP_XDISTANCE, 10);
    ObjectSetInteger(0, "PricePoints_2", OBJPROP_YDISTANCE, 10 + y_offset);
    ObjectSetInteger(0, "PricePoints_2", OBJPROP_XSIZE, 200);
    y_offset += line_spacing;

    // Period 3
    ObjectSetInteger(0, "PricePoints_3", OBJPROP_CORNER, Corner);
    ObjectSetInteger(0, "PricePoints_3", OBJPROP_XDISTANCE, 10);
    ObjectSetInteger(0, "PricePoints_3", OBJPROP_YDISTANCE, 10 + y_offset);
    ObjectSetInteger(0, "PricePoints_3", OBJPROP_XSIZE, 200);
    y_offset += line_spacing;

    // Period 4
    ObjectSetInteger(0, "PricePoints_4", OBJPROP_CORNER, Corner);
    ObjectSetInteger(0, "PricePoints_4", OBJPROP_XDISTANCE, 10);
    ObjectSetInteger(0, "PricePoints_4", OBJPROP_YDISTANCE, 10 + y_offset);
    ObjectSetInteger(0, "PricePoints_4", OBJPROP_XSIZE, 200);

    return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                         |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
    ObjectDelete(0, "PricePoints_Title");
    ObjectDelete(0, "PricePoints_1");
    ObjectDelete(0, "PricePoints_2");
    ObjectDelete(0, "PricePoints_3");
    ObjectDelete(0, "PricePoints_4");
}

//+------------------------------------------------------------------+
//| 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[])
{
    // Check if enough bars
    if(rates_total < Period4) return(0);
    
    // Calculate price differences
    double diff1 = close[0] - close[Period1];
    double diff2 = close[0] - close[Period2];
    double diff3 = close[0] - close[Period3];
    double diff4 = close[0] - close[Period4];
    
    // Set text for each label with 4 decimal places
    ObjectSetString(0, "PricePoints_Title", OBJPROP_TEXT, "Price Differences:");
    ObjectSetString(0, "PricePoints_1", OBJPROP_TEXT, StringFormat("%d bars ago: %.4f", Period1, diff1));
    ObjectSetString(0, "PricePoints_2", OBJPROP_TEXT, StringFormat("%d bars ago: %.4f", Period2, diff2));
    ObjectSetString(0, "PricePoints_3", OBJPROP_TEXT, StringFormat("%d bars ago: %.4f", Period3, diff3));
    ObjectSetString(0, "PricePoints_4", OBJPROP_TEXT, StringFormat("%d bars ago: %.4f", Period4, diff4));
    
    // Set properties for all labels
    string objects[] = {"PricePoints_Title", "PricePoints_1", "PricePoints_2", "PricePoints_3", "PricePoints_4"};
    for(int i = 0; i < ArraySize(objects); i++)
    {
        ObjectSetInteger(0, objects[i], OBJPROP_COLOR, TextColor); // Use user-defined color
        ObjectSetInteger(0, objects[i], OBJPROP_FONTSIZE, 12);
        ObjectSetString(0, objects[i], OBJPROP_FONT, "Arial");
    }
    
    return(rates_total);
}
//+------------------------------------------------------------------+