Skip to content
The Chat Archive
llama-3.3-70b-instruct· Meta LMArena Human Preference 140K

'06.mq5' 0 'OBJPRICELABEL' - undeclared identifier 06.mq5 109 39 'OBJPRICELABEL' -…

  1. User

    '06.mq5' 0 'OBJ_PRICE_LABEL' - undeclared identifier 06.mq5 109 39 'OBJ_PRICE_LABEL' - cannot convert enum 06.mq5 109 39 built-in: bool ObjectCreate(long,const string,ENUM_OBJECT,int,datetime,double,...) 06.mq5 109 39 2 errors, 0 warnings 2 0

  2. Assistant

    The issue here is that OBJ_PRICE_LABEL is not a valid object type in MQL5. I made an error in my previous response by suggesting its use.

    In MQL5, labels are created using OBJ_LABEL, not OBJ_PRICE_LABEL. Here's the corrected code:

    //+------------------------------------------------------------------+
    //|                                      CustomPriceGrid_EA.mq5      |
    //|                                      Conversion by ChatGPT       |
    //|                                      https://www.openai.com      |
    //+------------------------------------------------------------------+
    #property copyright "Conversion by ChatGPT"
    #property link      "https://www.openai.com"
    #property version   "1.00"
    
    //--- input parameters
    input group           "Grid Visualization Settings"
    input double          InpStartPrice = 100.0;     // Starting Price (for drawing)
    input double          InpSpacing    = 1.0;       // Price Spacing (for drawing)
    input int             InpNumLines   = 10;        // Number of Lines (Above and Below Start)
    
    input group           "Style Settings"
    input color           InpLineColor  = clrBlue;   // Line Color
    input int             InpLineWidth  = 1;         // Line Width
    input ENUM_LINE_STYLE InpLineStyle  = STYLE_SOLID; // Line Style
    
    // A prefix to uniquely identify our objects
    string PREFIX = "CustomGridEA_";
    
    //+------------------------------------------------------------------+
    //| Expert initialization function                                   |
    //+------------------------------------------------------------------+
    int OnInit()
    {
        // Input validation
        if(InpSpacing <= 0)
        {
            Alert("Error: Price Spacing must be greater than 0.");
            return(INIT_FAILED);
        }
        
        if(InpNumLines < 1)
        {
            Alert("Error: Number of Lines must be at least 1.");
            return(INIT_FAILED);
        }
    
        // Draw the visual grid lines when the EA loads or settings change
        DrawGrid();
        
        return(INIT_SUCCEEDED);
    }
    
    //+------------------------------------------------------------------+
    //| Expert deinitialization function                                 |
    //+------------------------------------------------------------------+
    void OnDeinit(const int reason)
    {
        // Clean up all visual objects when the EA is removed
        DeleteGrid();
    }
    
    //+------------------------------------------------------------------+
    //| Expert tick function                                             |
    //+------------------------------------------------------------------+
    void OnTick()
    {
        //======================================================================
        // THIS IS WHERE YOU WILL ADD YOUR TRADING FUNCTIONS
        //
        // When you provide your trading logic/functions, they will be called 
        // or implemented here. This function runs every time the price updates.
        //
        // Example placeholders:
        // CheckForBuySignal();
        // CheckForSellSignal();
        // ManageOpenTrades();
        //
        //======================================================================
    
    }
    
    //+------------------------------------------------------------------+
    //| Function to Draw the Grid Lines (Visualization)                  |
    //+------------------------------------------------------------------+
    void DrawGrid()
    {
        // 1. Delete previous lines before redrawing (important if settings change)
        DeleteGrid();
    
        // 2. Calculate the starting price (the lowest line)
        double currentPrice = InpStartPrice - (InpNumLines * InpSpacing);
        
        // 3. Determine total lines to draw (Above + Below + the Start line itself)
        int totalLines = (InpNumLines * 2) + 1;
    
        // 4. Loop and create objects
        for(int i = 0; i < totalLines; i++)
        {
            // Define unique names for the line and the label
            string lineName = PREFIX + "Line_" + IntegerToString(i);
            string labelName = PREFIX + "Label_" + IntegerToString(i);
    
            //--- Draw the Horizontal Line (OBJ_HLINE)
            if(ObjectCreate(0, lineName, OBJ_HLINE, 0, 0, currentPrice))
            {
                ObjectSetInteger(0, lineName, OBJPROP_COLOR, InpLineColor);
                ObjectSetInteger(0, lineName, OBJPROP_WIDTH, InpLineWidth);
                ObjectSetInteger(0, lineName, OBJPROP_STYLE, InpLineStyle);
                ObjectSetInteger(0, lineName, OBJPROP_BACK, false); // Draw line on top of candles
                ObjectSetInteger(0, lineName, OBJPROP_SELECTABLE, false); // Make it non-selectable
            }
    
            //--- Draw the Price Label (OBJ_LABEL)
            if(ObjectCreate(0, labelName, OBJ_LABEL, 0, 0, currentPrice))
            {
                ObjectSetInteger(0, labelName, OBJPROP_COLOR, InpLineColor);
                // Use the chart's specific decimal precision for the text
                string priceText = DoubleToString(currentPrice, _Digits);
                ObjectSetString(0, labelName, OBJPROP_TEXT, priceText);
                ObjectSetInteger(0, labelName, OBJPROP_XDISTANCE, 5); // Small offset from the axis
                ObjectSetInteger(0, labelName, OBJPROP_YDISTANCE, 0);
                ObjectSetInteger(0, labelName, OBJPROP_CORNER, CORNER_RIGHT_UPPER); // Align label to the right
            }
    
            // Increment the price for the next iteration
            currentPrice += InpSpacing;
        }
        
        // Force the chart to refresh visually
        ChartRedraw();
    }
    
    //+------------------------------------------------------------------+
    //| Function to Delete the Grid Lines                                |
    //+------------------------------------------------------------------+
    void DeleteGrid()
    {
        // Deletes all objects on the chart whose name starts with our PREFIX
        ObjectsDeleteAll(0, PREFIX);
    }
    //+------------------------------------------------------------------+
    

    This should resolve the compilation errors you were experiencing.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.