Code from chatgbt correction

 

Hi,

Just got this code from chatgbt.

it uses rsi overbought and oversold levels with engulfing candles.

i also asked it to us 200ema to determine the type of trades it can open.

Unforutunately, the are over 19 errors.

Can you guys please help to eliminate the errors.

...

Improperly formatted code removed by moderator. Please EDIT your post and use the CODE button (Alt-S) when inserting code.

Code button in editor

Hover your mouse over your post and select "edit" ... 

...

 

Do you really expect someone to fix the horrible code produced by that A.I. because you did not want to hire a human coder?

And now you want a human coder to fix it for free? 🤦‍♂️

Maybe you will get lucky! 😒

 
torisms: Just got this code from chatgbt.
  1. Why did you post your MT4 question in the MT5 EA 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. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  3. Chatgpt (the worst), 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.

    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.
      5. Calling undefined functions.
      6. Sometimes, not using strict.
      7. Code that will not compile.
      8. Creating code outside of functions.
      9. Creating incomplete code.
      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 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
      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
      1. Non-updateing global variables.
      2. Compilation errors.
      3. Not checking return codes.
      4. Not reporting errors.

 

Here's an idea - why don't you go back to ChatGPT and ask it to fix the errors?

It might learn something.

 
@Drazen Penic #: Here's an idea - why don't you go back to ChatGPT and ask it to fix the errors? It might learn something.
Good one! 👏 🤣
 
Drazen Penic #:

Here's an idea - why don't you go back to ChatGPT and ask it to fix the errors?

It might learn something.

The problem is OP doesn't know MQL4, and therefor can't tell it what is wrong. If he does know, he wouldn't have used it.

 
@William Roeder #:The problem is OP doesn't know MQL4, and therefor can't tell it what is wrong. If he does know, he wouldn't have used it.

He meant it as simply asking the A.I. to "fix the code". It was a joke, William. You remind me of Sheldon sometimes—both for the positives and the negatives.

 
torisms:

Hi,

Just got this code from chatgbt.

it uses rsi overbought and oversold levels with engulfing candles.

i also asked it to us 200ema to determine the type of trades it can open.

Unforutunately, the are over 19 errors.

Can you guys please help to eliminate the errors.

#property copyright "Copyright 2023, You got Lucky!!"
#property link      ""
#property version   "1.00"
#property strict

double rsiOverbought = 70;
double rsiOversold = 30;
double ema200;

int ticket = 0;
double stopLoss = 0;
double takeProfit = 0;
double lotSize = 0.1;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit() {
//--- create timer
   ema200 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, 0);
//---
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick() {
//---
   while(true) {
      // Check the current RSI value
      double rsi = iRSI(NULL, 0, 14, PRICE_CLOSE, 0);

      // Check the current price position relative to 200EMA
      bool isAboveEma200 = iClose(NULL, 0, 0) > ema200;

      // Check for bullish engulfing candle
      bool isBullishEngulfing = iClose(NULL, 0, 1) < iOpen(NULL, 0, 1)
                                && iClose(NULL, 0, 0) > iOpen(NULL, 0, 0)
                                && iClose(NULL, 0, 0) > iClose(NULL, 0, 1);

      // Check for bearish engulfing candle
      bool isBearishEngulfing = iClose(NULL, 0, 1) > iOpen(NULL, 0, 1)
                                && iClose(NULL, 0, 0) < iOpen(NULL, 0, 0)
                                && iClose(NULL, 0, 0) < iClose(NULL, 0, 1);

      // Check if there is an open position
      if (ticket > 0) {
         // Check the status of the open position
         int orderSelect = OrderSelect(ticket, SELECT_BY_TICKET);
         if (orderSelect) {
            // If the position is in profit, move the stop loss to breakeven
            if (OrderProfit() > 0) {

               double newStopLoss = OrderOpenPrice();
               if (OrderType() == OP_BUY) {
                  newStopLoss += (OrderStopLoss() - OrderOpenPrice());
               } else if (OrderType() == OP_SELL) {
                  newStopLoss -= (OrderOpenPrice() - OrderStopLoss());
               }
               bool modifyOrder = OrderModify(ticket, OrderOpenPrice(), newStopLoss, takeProfit, 0, Green);
               if (modifyOrder) {
                  Print("Position ", ticket, " is in profit, stop loss moved to breakeven.");
               }
            }
            // If the position is not in profit, check for stop loss or take profit hit
            else {
               if (OrderStopLoss() > 0 && Bid <= OrderStopLoss()) {
                  bool closeOrder = OrderClose(ticket, lotSize, Bid, 0, Red);
                  if (closeOrder) {
                     Print("Stop loss hit for position ", ticket);
                  }
               }
               else if (OrderTakeProfit() > 0 && Bid >= OrderTakeProfit()) {
                  bool closeOrder = OrderClose(ticket, lotSize, Bid, 0, Green);
                  if (closeOrder) {
                     Print("Take profit hit for position ", ticket);
                  }
               }
            }
         }
      }
      // If there is no open position, check for new entry signals
      else {
         // Open a long position if RSI is oversold and there is a bullish engulf
      }
   }
}

//+------------------------------------------------------------------+
 
Drazen Penic #:

Here's an idea - why don't you go back to ChatGPT and ask it to fix the errors?

It might learn something.

Actually, you can copy the compiler errors back to ChatGPT and it will attempt to correct them. Most of the time, it does so eventually, though it may take several tries.

Unfortunately, ChatGPT won't really learn anything from it. It might at least not make the same mistake within the same session. Or it might.

But what y'all miss is that for those of us trying to learn MQL5, it actually helps a lot to see implementations of the concepts you're trying to code, even if it's imperfect, it's a starting point.

Also ChatGPT is actually pretty good at minor changes, e.g., "change the stop loss mechanism from PSAR to ATR", it will probably get right. And a heck of a lot faster than I can do at this point.

 
Scott Allen #: But what y'all miss is that for those of us trying to learn MQL5, it actually helps a lot ...

No it does not. The art and skill of being a good programmed is learned by making mistakes and learning from them as you struggle to understand and overcome the difficulties.

That struggle teaches you to think for yourself and wires the brain to become better at problem solving. Take that away and all you will be left with is a "script kiddy" with a short-term view of things.

 

i'm so sorry that i see most of you are so  arrogant to help when someone says that he got the code from chatgpt and keep  blames and make jokes and fun of the person 

i dont think it's a mistake or a shame to hide when some normal ppl whos not a programmer try to use the new technology to achieve something in coding , CHATGPT is a new tool everyone can use it for anything and it helps alot of peoples .

So when someone need help you should leave him , what a professional attitude   :) . it's all about money . Me also have some problem in coding but i'm searching online about the solution instead of asking here and see you do the same with me 

Reason: