GMMA and BBAND, coding solution

 
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Brown
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2

double shortMA[];
double longMA[];
double middleLine[];
double upLine[];
double bottomLine[];

int shortPeriods[6] = {3, 5, 8, 10, 12, 15};
int longPeriods[6] = {30, 35, 40, 45, 50, 60};
int shortPeriodCount = ArraySize(shortPeriods);
int longPeriodCount = ArraySize(longPeriods);
double sumShort, sumLong;

int OnInit()
{
SetIndexBuffer(0, middleLine);
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(1, upLine);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(2, bottomLine);
SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 2);

return(INIT_SUCCEEDED);

}

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[])
{
if (rates_total <= shortPeriods[shortPeriodCount - 1])
return(0);

ArraySetAsSeries(shortMA, true);
ArraySetAsSeries(longMA, true);

for (int i = 0; i < shortPeriodCount; i++) {
    shortMA[i] = iMA(NULL, 0, shortPeriods[i], 0, MODE_SMA, PRICE_CLOSE, i);
}

for (int i = 0; i < longPeriodCount; i++) {
    longMA[i] = iMA(NULL, 0, longPeriods[i], 0, MODE_SMA, PRICE_CLOSE, i);
}

sumShort = ArraySum(shortMA, shortPeriodCount);
sumLong = ArraySum(longMA, longPeriodCount);

for (int i = 0; i < rates_total; i++) {
    middleLine[i] = (sumShort + sumLong) / 2;
    upLine[i] = middleLine[i] + iStdDev(NULL, 0, 20, 0, MODE_SMA, PRICE_CLOSE, i) * 2;
    bottomLine[i] = middleLine[i] - iStdDev(NULL, 0, 20, 0, MODE_SMA, PRICE_CLOSE, i) * 2;
}

return(rates_total);
}
'i' - variable already defined

   see previous declaration of 'i'

'ArraySum' - function not defined

HOW TO CODING IT?
 
  1. Add "#property strict" at the beginning of your code
  2. There is no built-in function called "ArraySum". You have to create it.

Did you copy this code from somewhere?

Os is this yet another horrible result of ChatGPT?

 
Fernando Carreiro #:
  1. Add "#property strict" at the beginning of your code
  2. There is no built-in function called "ArraySum". You have to create it.

Did you copy this code from somewhere?

Os is this yet another horrible result of ChatGPT?

yup from chatgpt


1. have is 

#property copyright "Copyright 2022, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

#property indicator_chart_window

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2023.02.14
  • 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
 
mt4 money #: yup from chatgpt

ChatGPT is useless and produces horrible code. Stop using it—learn to code or hire someone to code for you.

 
mt4 money #: yup from chatgpt

Chatgpt (the worst), EA builder, EA Builder Pro, EATree, Etasoft forex generator, Forex Strategy Builder, ForexEAdvisor, ForexRobotAcademy.com, forexsb, FX EA Builder, fxDreema, Forex Generator, FxPro, Molanis, Octa-FX Meta Editor, Online Forex Expert Advisor Generator, Strategy Builder FX, Strategy Quant, Visual Trader Studio, MQL5 Wizard, etc., are all the same. You will get something quick, but then you will spend a much longer time trying to get it right, than if you learned the language up front, and then just wrote it.

  1. Since you haven't learned MQL4/5, therefor there is no common language for us to communicate.
    If we tell you what you need, you can't code it.
    If we give you the code, you don't know how to integrate it into yours.
    We are willing to HELP you when you post your attempt (using Code button) and state the nature of your problem, but we are not going to debug your hundreds of lines of code. You are essentially going to be on your own.

  2. Chatgpt
    1. Mixing MT4 and MT5 code together.
    2. Creating multiple OnCalculate/OnTick functions.
    3. OnCalculate returning a double.
    4. Filling buffers with zero in OnInit (they have no size yet). Setting buffer elements to zero but not setting Empty Value to correspond.
    EA builder makes bad code:
    1. Counting up while closing multiple orders.
    2. New bar code: Bars is unreliable (Max bars in chart), volume is unreliable (miss ticks.) Always use time.
    3. Not adjusting for 4/5 digit brokers, TP/SL and slippage.
    4. Not adjusting for ECN brokers. pre-Build 500)
    5. Not checking return codes.
    EATree
    uses objects on chart to save values — not persistent storage (files or GV+Flush.) No recovery (crash/power failure.)
    FX EA Builder makes bad code:
    1. Not checking return codes.
    2. Loosing open tickets on terminal restart. No recovery (crash/power failure.)
    3. Not adjusting stops for the spread.
    4. Using OrdersTotal directly.
    FOREXEADVISOR STRATEGY BUILDER makes bad code:
    1. Non-updateing global variables.
    2. Compilation errors.
    3. Not checking return codes.
    ForexEAdvisor makes bad code:
    1. Not checking return codes.
    2. Not reporting errors.