Please Help Error code 138 at backtesting

 
//+------------------------------------------------------------------+

//|                                                        test1.mq4 |
//|                                      Copyright 2023, Frank Harey |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, Frank Harey"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
input double Lots = 0.01;
input int Magic = 12345;
input double TP = 1000;
input double SL = 500;
extern double upperRSI = 70;
extern double lowwerRSI = 30;
bool CheckRSIDi()
  {
   double rsi = iRSI(NULL, 0, 14, PRICE_CLOSE, 0);

   double price = NormalizeDouble(iClose(NULL, 0, 0), Digits);

   double ma = NormalizeDouble(iMA(NULL, 0, 14, 0, MODE_SMA, PRICE_CLOSE, 0), Digits);


   if(rsi < ma && price > ma)
     {
      return true;
     }
   else
      if(rsi > ma && price < ma)
        {
         return true;
        }
   return false;
  }
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

   if(OrdersTotal() > 0)
     {
      return;
     }

// ตรวจสอบสัญญาณ RSI Divergence
   findTrade();

  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
/*void EntryOrder()
  {
   if()
     {

     }
  }*/




//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OpenBuy()
  {
   int ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-SL*Point,Ask+TP*Point,"Order",Magic,0,clrGreen);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OpenSell()
  {
   int ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+SL*Point,Bid-TP*Point,"Order",Magic,0,clrRed);
  }
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void findTrade()
  {
   double price = NormalizeDouble(iClose(NULL, 0, 0), Digits); // กำหนดค่า price ด้วย iClose

   if(CheckRSIDi())
     {
      // หากเกิดสัญญาณ RSI Divergence ขึ้น ให้เปิดออเดอร์ซื้อ (Buy)
      if(OrdersTotal() == 0)
        {
         double stoploss = price - SL * Point;
         double takeprofit = price + TP * Point;
         int ticket = OrderSend(NULL, OP_BUY, 0.1, price, 3, stoploss, takeprofit, "RSI Divergence Buy", 0, 0, Green);
        }
     }
   else
     {
      // ถ้าไม่เกิดสัญญาณ RSI Divergence ให้ปิดออเดอร์ (หากมี)
      if(OrdersTotal() > 0)
        {
         for(int i = OrdersTotal() - 1; i >= 0; i--)
           {
            if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
              {
               if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
                 {
                  if(OrderType() == OP_BUY)
                    {
                     OrderClose(OrderTicket(), OrderLots(), Bid, 3, Red);
                    }
                  else
                     if(OrderType() == OP_SELL)
                       {
                        OrderClose(OrderTicket(), OrderLots(), Ask, 3, Red);
                       }
                 }
              }
           }
        }
     }
}

i dont know why   i use chatgpt


but live demo it can open order






   

Descubra las nuevas posibilidades de MetaTrader 5 con la comunidad y los servicios MQL5
Descubra las nuevas posibilidades de MetaTrader 5 con la comunidad y los servicios MQL5
  • 2023.02.24
  • www.mql5.com
MQL5 es un lenguaje built-in de estrategias comerciales para el terminal MetaTrader 5. Este lenguaje permite escribir sus propios sistemas automáticos de trading, indicadores técnicos, scripts y bibliotecas de funciones.
Files:
test1.mq4  10 kb
 

Please edit your post (don't create a new post) and replace your code properly (with "</>" or Alt-S), or attach the original file directly with the "+ Attach file" button below the text box.

NB! Very important! DO NOT create a new post. EDIT your original post.

 
Fernando Carreiro #:

Please edit your post (don't create a new post) and replace your code properly (with "</>" or Alt-S), or attach the original file directly with the "+ Attach file" button below the text box.

NB! Very important! DO NOT create a new post. EDIT your original post.

sry never post before    thank you

 
Weerayut Phengsri #: sry never post before    thank you

Before posting, did you read the documentation about error 138?

138

ERR_REQUOTE

Requote

Did you do a search and read all the previous posts about the same issue?


If the answer was yes, to the above, then please explain what it is that you did not understand so that we can help you with that specific misunderstanding.

 
Fernando Carreiro #:

Before posting, did you read the documentation about error 138?

138

ERR_REQUOTE

Requote

Did you do a search and read all the previous posts about the same issue?


If the answer was yes, to the above, then please explain what it is that you did not understand so that we can help you with that specific misunderstanding.

thank you  but im not good english  and newbie for write mql4   i use chatgpt write it and i try to fix but cant

 
Weerayut Phengsri: i use chatgpt

Unfortunately, I only noticed this in your post now!

We cannot help you if you used ChatGPT.

It produces horrible code, and since you don't know anything about programming in MQL yourself, you will not understand our advice, nor will you be able to fix it either since you don't know how to code.

So, either learn to code yourself or hire a human coder to do it for you.

 
Fernando Carreiro #:

Unfortunately, I only noticed this in your post now!

We cannot help you if you used ChatGPT.

It produces horrible code, and since you don't know anything about programming in MQL yourself, you will not understand our advice, nor will you be able to fix it either since you don't know how to code.

So, either learn to code yourself or hire a human coder to do it for you.

ok thank you  i am learning

 
  1. Use the code button.

  2. int ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-SL*Point,Ask+TP*Point,"Order",Magic,0,clrGreen);

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)

      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
      My GBPJPY shows average spread = 26 points, average maximum spread = 134.
      My EURCHF shows average spread = 18 points, average maximum spread = 106.
      (your broker will be similar).
                Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)

  3. int ticket = OrderSend(NULL, OP_BUY, 0.1, price, 3, stoploss, takeprofit, "RSI Divergence Buy", 0, 0, Green);

    Be careful with NULL.

    1. On MT4, you can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not, OrderSend does not.
    2. Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
    3. Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
    4. MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
      MT5: create them.
    5. Cloud Protector Bug? - MQL4 programming forum (2020)

  4. Weerayut Phengsri: i dont know why   i use chatgpt

    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 (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)
      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. Use the code button.

  2. You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)

      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
      My GBPJPY shows average spread = 26 points, average maximum spread = 134.
      My EURCHF shows average spread = 18 points, average maximum spread = 106.
      (your broker will be similar).
                Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)

  3. Be careful with NULL.

    1. On MT4, you can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not, OrderSend does not.
    2. Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
    3. Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
    4. MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
      MT5: create them.
    5. Cloud Protector Bug? - MQL4 programming forum (2020)

  4. 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 (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)
      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.

thank you very very much i will learning from you ^^

Reason: