MT5 : Pls. guide me how to plot Oscillator chart overlay : Demark indicator overlay Bollinger Band

 

Hi guys, been pulling my hair over this. how do i plot a chart onto the price . The code below attempts to normalize the Demark line (according to ChatGPT) but when i compiled it and deployed it on chart, nothing happens.

Appreciate some pointers and help!

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Magenta  // DeMark line color
#property indicator_color2 White    // Bollinger Band Upper line color
#property indicator_color3 White    // Bollinger Band Lower line color
#property indicator_color4 Aqua     // Middle Bollinger Band line color
// Indicator buffers
double DeMarkBuffer[];
double BollingerUpperBuffer[];
double BollingerLowerBuffer[];
double BollingerMiddleBuffer[];
// Input parameters
input int DeMarkPeriod = 11;             // DeMark period
input int BollingerPeriod = 11;          // Bollinger Band period
input double BollingerDeviation = 2.0;   // Bollinger Band deviation
input ENUM_TIMEFRAMES BB_Timeframe = PERIOD_M15; // Bollinger Band timeframe
// Handles for indicators
int DeMarkHandle;
int BollingerHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
    // Indicator buffer setup
    SetIndexBuffer(0, DeMarkBuffer);
    SetIndexBuffer(1, BollingerUpperBuffer);
    SetIndexBuffer(2, BollingerLowerBuffer);
    SetIndexBuffer(3, BollingerMiddleBuffer);
    // Set line styles
    PlotIndexSetInteger(0, PLOT_LINE_STYLE, STYLE_SOLID);
    PlotIndexSetInteger(1, PLOT_LINE_STYLE, STYLE_DOT);
    PlotIndexSetInteger(2, PLOT_LINE_STYLE, STYLE_DOT);
    PlotIndexSetInteger(3, PLOT_LINE_STYLE, STYLE_DOT);
    // Create DeMark Indicator (as an oscillator)
    DeMarkHandle = iCustom(NULL, 0, "DeMarker", DeMarkPeriod);
    if (DeMarkHandle == INVALID_HANDLE)
    {
        Print(_Symbol + " Error creating DeMarker handle: ", GetLastError());
        return INIT_FAILED;
    }
    // Create Bollinger Bands Indicator
    BollingerHandle = iBands(NULL, BB_Timeframe, BollingerPeriod, (int)BollingerDeviation, 0, PRICE_CLOSE);
    if (BollingerHandle == INVALID_HANDLE)
    {
        Print("Error creating Bollinger Bands handle: ", GetLastError());
        return INIT_FAILED;
    }
    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[])
{
    // Calculate DeMark Indicator values
    double deMarkerValue[];
    if (CopyBuffer(DeMarkHandle, 0, 0, rates_total, deMarkerValue) <= 0)
    {
        Print("Error copying DeMarker buffer: ", GetLastError());
        return 0;
    }
    // Normalize and map DeMark values to fit price chart
    for (int i = 0; i < rates_total; i++)
    {
        DeMarkBuffer[i] = deMarkerValue[i] * (high[i] - low[i]) + low[i];
    }
    // Calculate Bollinger Bands values
    double bbUpper[], bbLower[], bbMiddle[];
    if (CopyBuffer(BollingerHandle, 1, 0, rates_total, bbUpper) <= 0 ||
        CopyBuffer(BollingerHandle, 2, 0, rates_total, bbLower) <= 0 ||
        CopyBuffer(BollingerHandle, 0, 0, rates_total, bbMiddle) <= 0)
    {
        Print("Error copying Bollinger Bands buffer: ", GetLastError());
        return 0;
    }
    // Fill Bollinger Band buffers
    for (int i = 0; i < rates_total; i++)
    {
        BollingerUpperBuffer[i] = bbUpper[i];
        BollingerLowerBuffer[i] = bbLower[i];
        BollingerMiddleBuffer[i] = bbMiddle[i];
    }
    // Debugging: Print buffer values
    Print("DeMarkBuffer[0]: ", DeMarkBuffer[0]);
    Print("BollingerUpperBuffer[0]: ", BollingerUpperBuffer[0]);
    Print("BollingerLowerBuffer[0]: ", BollingerLowerBuffer[0]);
    Print("BollingerMiddleBuffer[0]: ", BollingerMiddleBuffer[0]);
    return rates_total;
}

Extraneous white-space removed by moderator. Please take note for next time you post code.

 
Your topic has been moved to the section: Technical Indicators
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 

Please, don't request help for ChatGPT (or other A.I.) generated code. It generates horrible code.

Either learn to code properly with the help of the documentation and book, or use the freelance section for such requests.