Error message in EA - 'OnInit' - function already defined and has body

 

Hi,

I have been trading for a few years, and finally decided to take the plunge and learn more about building Expert Advisors.

Playing around in - Bots Builder - has helped a lot. I used it to construct a very basic EA.

The next step is adding a License Check Function - where the EA expires after 30 Days. I found a very useful guide online on how to add licence checking capabilities.

I followed the guide step by step, I run in to one error when hitting compile for the last time.

'OnInit' - function already defined and has body Line: 504 - Columm: 5



As I understand:  The OnInit() function is the event handler. It must be of void or int type, with no parameters.

The answer is probably simple, but my lack of understanding has had be stuck for a few days, reading online, and trying to solve the error.

Any help would be greatly appreciated.


Files:
Test_EA.mq4  828 kb
 
You had more than one Oninit(). check your code . 
 
Yip Sin Hang #:
You had more than one Oninit(). check your code . 

Thank you for the reply.

If I remove the 2nd - OnInit - on Line 504.

I receive a bunch of errors.

 
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. 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. 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.
    5. Calling undefined functions.
    6. Sometimes, not using strict (MT4 code).
    7. Code that will not compile.
    8. Creating code outside of functions.
    9. Creating incomplete code.
    10. Initialization of Global variables with non-constants.
    11. Assigning a MT5 handle to a double or missing the buffer and bar indexes in a MT4 call.
    12. Useing MT4 Trade Functions without first selecting an order.
    13. Even it says do not use it for coding. (2023)
    14. Uses NULL in OrderSend.*
    EA builder
    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 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.

 
William Roeder #:
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. 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. 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.
    5. Calling undefined functions.
    6. Sometimes, not using strict (MT4 code).
    7. Code that will not compile.
    8. Creating code outside of functions.
    9. Creating incomplete code.
    10. Initialization of Global variables with non-constants.
    11. Assigning a MT5 handle to a double or missing the buffer and bar indexes in a MT4 call.
    12. Useing MT4 Trade Functions without first selecting an order.
    13. Even it says do not use it for coding. (2023)
    14. Uses NULL in OrderSend.*
    EA builder
    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 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.



Thanks for the Reply.

(1) Didn't realize there is a separate MQL4 section. My bad.

(2) I completely understand, the bot compiles fine before I try to add the Licence Check Function. But adding the 7 lines used by the Licence check, which also uses the OnInit function, causes a conflict.


I was hoping there might be a way to reassign the first instance of the OnInit function used by the Licence check, I'm learning, it's not that simple. Like you pointed out, the other instances of the OnInit function is a part of the logic created by "Bots Builder" as part of the EA.

I should commit and learn the language, so I can understand the fundamentals.

Thank you for taking the time to write a reply, and the advice. 

Reason: