MT5 Indicator Error

 

Hi, 

I Need assistant the indicator script thatni generated from chartgpt.. this are my values below.


Code me a RSI and CCI MT5 indicator with the following parameters.

RSI input 1color blue, Level 10. 90, 80, 20 and 50

CCI input 5000 with color red

Send a pop-up alert when CCI input 5000 touches RSI 1 level 90

Send a pop-up alert when CCI input 5000 touches RSI 1 level 10


After generating it, I load it but is still not working. see below.

//+------------------------------------------------------------------+
//|                                                 RSI_CCI_Alert.mq5|
//|                         Copyright 2024, MetaTrader 5 Community   |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2024"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue  // RSI Color
#property indicator_color2 Red   // CCI Color
// Input parameters
input int RSI_Period = 14;      // RSI Period
input double CCI_Period = 5000;  // CCI Period
input double RSI_Level1 = 90;    // RSI Level 90
input double RSI_Level2 = 10;    // RSI Level 10
input double RSI_Level3 = 80;    // RSI Level 80
input double RSI_Level4 = 20;    // RSI Level 20
input double RSI_Level5 = 50;    // RSI Level 50
// Buffers
double RSI_Buffer[];
double CCI_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                           |
//+------------------------------------------------------------------+
int OnInit()
{
    SetIndexBuffer(0, RSI_Buffer);
    SetIndexBuffer(1, CCI_Buffer);
    IndicatorSetInteger(INDICATOR_DIGITS, 0);
    
    // Set levels for RSI
    IndicatorSetDouble(INDICATOR_LEVELS, RSI_Level1);
    IndicatorSetDouble(INDICATOR_LEVELS, RSI_Level2);
    IndicatorSetDouble(INDICATOR_LEVELS, RSI_Level3);
    IndicatorSetDouble(INDICATOR_LEVELS, RSI_Level4);
    IndicatorSetDouble(INDICATOR_LEVELS, RSI_Level5);
    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 double &spread[])
{
    // Calculate RSI
    int rsi_start = rates_total - RSI_Period;
    for(int i = rsi_start; i < rates_total; i++)
    {
        RSI_Buffer[i] = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i);
    }
    // Calculate CCI
    int cci_start = rates_total - CCI_Period;
    for(int i = cci_start; i < rates_total; i++)
    {
        CCI_Buffer[i] = iCCI(NULL, 0, CCI_Period, PRICE_TYPICAL, i);
    }
    // Check for alerts
    for(int i = 1; i < rates_total; i++)
    {
        if (CCI_Buffer[i] >= RSI_Level1 && CCI_Buffer[i-1] < RSI_Level1)
            Alert("CCI touched RSI Level 90!");
        if (CCI_Buffer[i] <= RSI_Level2 && CCI_Buffer[i-1] > RSI_Level2)
            Alert("CCI touched RSI Level 10!");
    }
    return(rates_total);
}
//+------------------------------------------------------------------+
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2024.10.10
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 

When you post code please use the CODE button (Alt-S)!

Use the CODE button

 
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
 

Hi

ChartGPT is not the best advisor here – it mixes up mql5 and mlq4 code (As it did in your case). Try to fix the code and we can try you with your mistakes. 

Here there are multiple problems with this: you need to define Indicator_plot property. Then you need to set indicators type and styles for both buffers. Also you should define RSI and CCI handles (iRSI and iCCI) on the oninit function and then only get the proper values in the OnCalulcate using CopyBuffer function. Besides that – you don’t really need RSI here, because you want an alert where CCI value reach 90 or 10 level, so those are constant values (not related to RSI values at all) then it’s even simpler. But still you need to fix all those mistakes which ChatGpT has given you. 

Have a nice day👍📊