WPR_Period - cannot convert enum

 

Please help me correct this code error on line 59.

Here is the code in the attachment.

The error is 'WPR_Period' - cannot convert enum

OpenAI
OpenAI
  • openai.com
Creating safe AGI that benefits all of humanity
 
progress chukwu:

Please help me correct this code error on line 59.

Here is the code in the attachment.

The error is 'WPR_Period' - cannot convert enum

Please post your code properly. Use the >code-button<

Your usage of indicators is wrong. You need to create the indicator once in OnInit. You get a handle, use the handle with CopyBuffer to get the data.

Your parameters are wrong, you place the cursor on the function name and then press F1 to open the documentation.


 
+------------------------------------------------------------------+
//|                                        CrossIndicator.mq5       |
//|              Copyright 2023, OpenAI. All rights reserved.       |
//|                      https://www.openai.com/&nbsp;                     |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

// Input parameters
input int CCI_Period = 14;
input int WPR_Period = 14;

// Indicator buffers
double CCI_Buffer[];
double WPR_Buffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
    // Set indicator buffers
    SetIndexBuffer(0, CCI_Buffer);
    SetIndexBuffer(1, WPR_Buffer);

    // Set indicator labels
    IndicatorSetString(INDICATOR_SHORTNAME, "CCI-WPR Cross");

    return INIT_SUCCEEDED;
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
{
    int limit = rates_total - prev_calculated;

    // Check if enough bars are available for both indicators
    int bars_required = MathMax(CCI_Period, WPR_Period);

    if (prev_calculated == 0)
        bars_required += 1;

    if (bars_required > rates_total)
        return 0; // Not enough bars, wait for more data

    // Calculate CCI values
    for (int i = limit; i >= 0; i--)
    {
        CCI_Buffer[i] = iCCI(Symbol(), 0, CCI_Period, i);
        WPR_Buffer[i] = iWPR(Symbol(), WPR_Period, i);

        // Check for indicator cross
        if (i > 0)
        {
            if (CCI_Buffer[i] > WPR_Buffer[i] && CCI_Buffer[i - 1] <= WPR_Buffer[i - 1])
                Alert("CCI-WPR cross detected: UP");

            if (CCI_Buffer[i] < WPR_Buffer[i] && CCI_Buffer[i - 1] >= WPR_Buffer[i - 1])
                Alert("CCI-WPR cross detected: DOWN");
        }
    }

    return rates_total;
}

Dominik Christian Egert #:
Please post your code properly. Use the >code-button<

Your usage of indicators is wrong. You need to create the indicator once in OnInit. You get a handle, use the handle with CopyBuffer to get the data.

Your parameters are wrong, you place the cursor on the function name and then press F1 to open the documentation.


OpenAI
OpenAI
  • openai.com
Creating safe AGI that benefits all of humanity
 
progress chukwu #:

I am not a programmer.

As you can see the code was generated by openai.

I know what I want to do but I don't know how to go about it 

 
This
iWPR(Symbol(), WPR_Period, i);

Should be

iWPR(Symbol(), 0, WPR_Period, i);
 
Fabio Cavalloni #:
This

Should be

Thanks but I have tried this  already.

The problem is with the WPR_Period section of the line. 

 
progress chukwu #:

Thanks but I have tried this  already.

The problem is with the WPR_Period section of the line. 

The WPR_Period is correctly an integer type.

In your initial code, it's applied wrongly to timeframe instead of period of indicator.

With the code I wrote it will work correctly.
 
progress chukwu #:

I am not a programmer.

As you can see the code was generated by openai.

I know what I want to do but I don't know how to go about it 

You need to either learn to code MQL5 or pay someone to do it for you.


 
progress chukwu #:

Thanks but I have tried this  already.

The problem is with the WPR_Period section of the line. 

Insufficient. iWPA must be called in OnInit.
 
Dominik Christian Egert #:
Insufficient. iWPA must be called in OnInit.

You are right, I supposed it to be MQL4 but it is MQL5...

So @progress chukwu as you can see in a lot of free code around here, on MQL5 you need to declare and assign indicator handles into OnInit, and CopyBuffers into OnTick/OnCalculate.

 
Dominik Christian Egert #:
Insufficient. iWPA must be called in OnInit.

Thanks 👍

How do I call it in OnInit? 

Reason: