erorr code

 

Hello friends

I want to write a simple indicator as follows

According to the close price of the week and  day Or any time  the amount of  ATR of the same time

Draw a line above and below the chart as follows 


high_line= close price+ ATR

low_line = close price - ATR

for mt4

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2


double hnDayBuffer[];
double lnDayBuffer[];


int init()
{
   
    string plotNameHn = "hnDay";
    string plotNameLn = "lnDay";
    double PLOT_STYLE = DRAW_LINE;
    

    PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_LINE);
    PlotIndexSetInteger(0, PLOT_STYLE, STYLE_SOLID);
    PlotIndexSetInteger(0, PLOT_LINE_COLOR, clrBlue);
    PlotIndexSetInteger(0, PLOT_LINE_WIDTH, 2);
    PlotIndexSetString(0, PLOT_LABEL, plotNameHn);
    
    PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_LINE);
    PlotIndexSetInteger(1, PLOT_STYLE, STYLE_SOLID);
    PlotIndexSetInteger(1, PLOT_LINE_COLOR, clrRed);
    PlotIndexSetInteger(1, PLOT_LINE_WIDTH, 2);
    PlotIndexSetString(1, PLOT_LABEL, plotNameLn);
    

    SetIndexBuffer(0, hnDayBuffer);
    SetIndexBuffer(1, lnDayBuffer);
    
    IndicatorSetInteger(INDICATOR_DIGITS, MarketInfo(Symbol(), MODE_DIGITS));
    IndicatorSetString(INDICATOR_SHORTNAME, "ATR Based Levels");
    
    return(0);
}

int start()
{

    int atr_period = 14;
    double closePrice = iClose(_Symbol, PERIOD_D1, 1);
    double atrValue = iATR(_Symbol, PERIOD_D1, 1);

    double hnDay = closePrice + atrValue;
    double lnDay = closePrice - atrValue;
    

    hnDayBuffer[0] = hnDay;
    lnDayBuffer[0] = lnDay;
    
    return(0);
}
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Price Constants - Indicator Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

This very much looks like ChatGPT work.

In your code you have mixed MQL5 syntax with very old MQL4 syntax.

For start, this indicator needs "property strict" directive and it needs OnCalculate and OnInit functions instead of "init" and "start".

Use MetaEditor wizard and add new indicator file. Then try to migrate code from above init and start functions into OnInit and OnCalculate.

 
Drazen Penic #: This very much looks like ChatGPT work.
Yep. Stop using ChatGPT.
          Help needed to debug and fix an AI EA - Trading Systems - MQL5 programming forum (2023)

ChatGPT (the worst), “Bots Builder”, “EA builder”, “EA Builder Pro”, EATree, “Etasoft forex generator”, “Forex Strategy Builder”, ForexEAdvisor (aka. ForexEAdvisor STRATEGY BUILDER, and Online Forex Expert Advisor Generator), ForexRobotAcademy.com, forexsb, “FX EA Builder”, fxDreema, Forex Generator, FxPro, Molanis, Octa-FX Meta Editor, 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.

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.

ChatGPT
  1. Even it says do not use it for coding.*
  2. Mixing MT4 and MT5 code together.
  3. Creating multiple OnCalculate/OnTick functions.
  4. OnCalculate returning a double.
  5. Filling buffers with zero in OnInit (they have no size yet). Setting buffer elements to zero but not setting Empty Value to correspond.
  6. Calling undefined functions.
  7. Sometimes, not using strict (MT4 code).
  8. Code that will not compile.
  9. Creating code outside of functions.*
  10. Creating incomplete code.*
  11. Initialization of Global variables with non-constants.*
  12. Assigning a MT5 handle to a double or missing the buffer and bar indexes in a MT4 call.*
  13. Useing MT4 Trade Functions without first selecting an order.*
  14. Uses NULL in OrderSend.*
bot builder Creating two OnInit() functions.*
EA builder
  1. Counting up while closing multiple orders.
  2. Not useing time in new bar detection.
  3. Not adjusting for 4/5 digit brokers, TP/SL and slippage.*
  4. Not checking return codes.
EATree Uses objects on chart to save values — not persistent storage (files or GV+Flush.) No recovery (crash/power failure.)
ForexEAdvisor
  1. Non-updateing global variables.
  2. Compilation errors.
  3. Not checking return codes.
  4. Not reporting errors.
FX EA Builder
  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.
  5. Using the old event handlers.