Pivot points converted to zones

 

hi ive created this perfect pivot point object but im having trouble converting this code into one which creates rectangles to represent zones of potential support and resistance. Ive attached two EAs, one which creates the lines perfectly whilst the other is supposed to make zones but doing so unsuccessfully. Can someone please tell me what need to be adapted to create what i want. Thanks!

input string objPrefix = "WeeklyLevels_"; // Prefix for object names
input int numberOfWeeks = 10; // Number of weeks to display

bool linesCreated = false;

//+------------------------------------------------------------------+
//| Custom function to calculate and create pivot point lines         |
//+------------------------------------------------------------------+
void CreateWeeklyPivotLines(int weekOffset)
{
    double high1 = iHigh(Symbol(), PERIOD_W1, weekOffset + 1);
    double low1 = iLow(Symbol(), PERIOD_W1, weekOffset + 1);
    double close1 = iClose(Symbol(), PERIOD_W1, weekOffset + 1);

    // Start time
    datetime time1 = iTime(Symbol(), PERIOD_W1, weekOffset);
    // End time (set to one week in the future)
    datetime time2 = time1 + PeriodSeconds(PERIOD_W1);

    double pivotPoint = (high1 + low1 + close1) / 3;
    string objName = objPrefix + "PivotPoint" + IntegerToString(weekOffset);

    // Check if the line already exists
    if (ObjectCreate(0, objName, OBJ_TREND, 0, time1, pivotPoint, time2, pivotPoint))
    {
        ObjectSetInteger(0, objName, OBJPROP_COLOR, clrMediumBlue);
        ObjectSetInteger(0, objName, OBJPROP_WIDTH, 5);
    }

    double r1 = pivotPoint * 2 - low1;
    objName = objPrefix + "R1" + IntegerToString(weekOffset);

    // Check if the line already exists
    if (ObjectCreate(0, objName, OBJ_TREND, 0, time1, r1, time2, r1))
    {
        ObjectSetInteger(0, objName, OBJPROP_COLOR, clrLightBlue);
        ObjectSetInteger(0, objName, OBJPROP_WIDTH, 5);
    }

    double r2 = pivotPoint + high1 - low1;
    objName = objPrefix + "R2" + IntegerToString(weekOffset);

    // Check if the line already exists
    if (ObjectCreate(0, objName, OBJ_TREND, 0, time1, r2, time2, r2))
    {
        ObjectSetInteger(0, objName, OBJPROP_COLOR, clrLightBlue);
        ObjectSetInteger(0, objName, OBJPROP_WIDTH, 5);
    }

    double s1 = pivotPoint * 2 - high1;
    objName = objPrefix + "S1" + IntegerToString(weekOffset);

    // Check if the line already exists
    if (ObjectCreate(0, objName, OBJ_TREND, 0, time1, s1, time2, s1))
    {
        ObjectSetInteger(0, objName, OBJPROP_COLOR, clrCoral);
        ObjectSetInteger(0, objName, OBJPROP_WIDTH, 5);
    }

    double s2 = pivotPoint - (high1 - low1);
    objName = objPrefix + "S2" + IntegerToString(weekOffset);

    // Check if the line already exists
    if (ObjectCreate(0, objName, OBJ_TREND, 0, time1, s2, time2, s2))
    {
        ObjectSetInteger(0, objName, OBJPROP_COLOR, clrCoral);
        ObjectSetInteger(0, objName, OBJPROP_WIDTH, 5);
    }
}

//+------------------------------------------------------------------+
//| Initialize the lines                                            |
//+------------------------------------------------------------------+
void InitializeLines()
{
    if (!linesCreated)
    {
        for (int i = 0; i < numberOfWeeks; i++)
        {
            CreateWeeklyPivotLines(i);
        }

        linesCreated = true;
    }
}



void OnTick()
{
    InitializeLines();
}

This is what is supposed to create the zones:

void CreatePivotZones(string objPrefix, int weekOffset, double zonePercentage)
{
    double high1 = iHigh(Symbol(), PERIOD_W1, weekOffset + 1);
    double low1 = iLow(Symbol(), PERIOD_W1, weekOffset + 1);
    double close1 = iClose(Symbol(), PERIOD_W1, weekOffset + 1);

    // Start time
    datetime time1 = iTime(Symbol(), PERIOD_W1, weekOffset);
    // End time (set to one week in the future)
    datetime time2 = time1 + PeriodSeconds(PERIOD_W1);

    double pivotPoint = (high1 + low1 + close1) / 3;

    // Calculate support and resistance zones
    double r1 = pivotPoint * 2 - low1;
    double r2 = pivotPoint + high1 - low1;
    double s1 = pivotPoint * 2 - high1;
    double s2 = pivotPoint - (high1 - low1);

    // Calculate zone width as a percentage of the range between pivot points
    double zoneWidth = (r1 - s1) * zonePercentage / 100.0;

    // Calculate zone boundaries
    double zoneTopR1 = r1 + zoneWidth * SymbolInfoDouble(_Symbol, SYMBOL_POINT);
    double zoneBottomR1 = r1 - zoneWidth * SymbolInfoDouble(_Symbol, SYMBOL_POINT);
    double zoneTopR2 = r2 + zoneWidth * SymbolInfoDouble(_Symbol, SYMBOL_POINT);
    double zoneBottomR2 = r2 - zoneWidth * SymbolInfoDouble(_Symbol, SYMBOL_POINT);
    double zoneTopS1 = s1 + zoneWidth * SymbolInfoDouble(_Symbol, SYMBOL_POINT);
    double zoneBottomS1 = s1 - zoneWidth * SymbolInfoDouble(_Symbol, SYMBOL_POINT);
    double zoneTopS2 = s2 + zoneWidth * SymbolInfoDouble(_Symbol, SYMBOL_POINT);
    double zoneBottomS2 = s2 - zoneWidth * SymbolInfoDouble(_Symbol, SYMBOL_POINT);

    // Create support and resistance zone rectangles
    CreateZone(objPrefix + "R1Zone" + IntegerToString(weekOffset), clrLightBlue, time1, zoneBottomR1, time2, zoneTopR1);
    CreateZone(objPrefix + "R2Zone" + IntegerToString(weekOffset), clrLightBlue, time1, zoneBottomR2, time2, zoneTopR2);
    CreateZone(objPrefix + "S1Zone" + IntegerToString(weekOffset), clrCoral, time1, zoneBottomS1, time2, zoneTopS1);
    CreateZone(objPrefix + "S2Zone" + IntegerToString(weekOffset), clrCoral, time1, zoneBottomS2, time2, zoneTopS2);
}

//+------------------------------------------------------------------+
//| Custom function to create zone rectangles                        |
//+------------------------------------------------------------------+
void CreateZone(string objName, color clr, datetime time1, double price1, datetime time2, double price2)
{
    // Create a filled rectangle (zone)
    if (ObjectCreate(0, objName, OBJ_RECTANGLE, 0, time1, price1, time2, price2))
    {
        ObjectSetInteger(0, objName, OBJPROP_COLOR, clr);
        ObjectSetInteger(0, objName, OBJPROP_WIDTH, 0);
    }
}


void OnTick()
{
    int weekOffset = 0; 
    double zonePercentage = 30.0; 

    string objPrefix = "WeeklyLevels_"; 

    CreatePivotZones(objPrefix, weekOffset, zonePercentage);

}