The problem of closing deal!

 

I have no idea why the following code doesn't close the deal at the specified point. It opens the deal correctly but doesn't close it. Here is my code. I appreciate your help in advance:
//+------------------------------------------------------------------+
//|                                                      AutoTrader.mq5 |
//|                        Generated by ChatGPT                      |
//+------------------------------------------------------------------+
...

<Improperly formatted code was removed by moderator. Please use the CODE button (Alt-S) when inserting code — https://www.mql5.com/en/articles/24#insert-code >

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
  • www.mql5.com
Trading is done by sending orders to open positions using the OrderSend() function, as well as to place, modify or delete pending orders. Each...
 
Mohammad Amin:
I have no idea why the following code doesn't close the deal at the specified point. It opens the deal correctly but doesn't close it. Here is my code. I appreciate your help in advance:

       
ChatGPT creates bad code.  Don’t use it,  I doubt you’ll get any help here with it 
Also use Alt+s to post code
 
Mohammad Amin:
I have no idea why the following code doesn't close the deal at the specified point. It opens the deal correctly but doesn't close it. Here is my code. I appreciate your help in advance:
//+------------------------------------------------------------------+
//|                                                      AutoTrader.mq5 |
//|                        Generated by ChatGPT                      |
//+------------------------------------------------------------------+
...
Please, don't request help for ChatGPT (or other A.I.) generated code. It generates horrible code, mixing MQL4 and MQL5. Please use the Freelance section for such requests — https://www.mql5.com/en/job
Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • 2024.05.25
  • www.mql5.com
The largest freelance service with MQL5 application developers
 

Stop using ChatGPT/Copilot.
          Help needed to debug and fix an AI EA - Trading Systems - MQL5 programming forum #2 (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, “LP-MOBI”, 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. Calling MT4 functions in MT5 code.
  8. Sometimes, not using strict (MT4 code).
  9. Code that will not compile.
  10. Creating code outside of functions. * 
  11. Creating incomplete code. * 
  12. Initialization of Global variables with non-constants. * 
  13. Assigning a MT5 handle to a double or missing the buffer and bar indexes in a MT4 call. * 
  14. Useing MT4 Trade Functions without first selecting an order. * 
  15. 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.