can anyone help me with this code ? please help me !

 

So I have been making an AI with  button labels


the first button opens bye 

and the second one opens a sell


I want to add another two buttons one that opens a sell limit and one that opens a buy limit   far from the last trade opened accordingly and I want  to be able to edit the space between them in pipes and their lots


and also   if it is possible to make the bot close all trades  after some profit  I put it in the input panel 


here it is the code , I don't know what is its problem, can you please help me ! 

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2018, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright "Keith Watford"
#property link      "none"
#property version   "1.00"
#property strict
//--- input parameters
input int         MagicNumber=99;
input double      LotSize=0.01;
input int         PendingOrderPipsDistance = 20;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   if(IsTesting())
     {
      string name;
      string heading[4]= {"Buy","Sell"};
      int xc=5;
      int yc=30;

      for(int i=0; i<2; i++)
        {
         name=heading[i];
         ObjectCreate(0,name,OBJ_BUTTON,0,0,0);
         ObjectSetText(name,name,10,"Arial",clrBlue);
         ObjectSetInteger(0,name,OBJPROP_XDISTANCE,xc);
         ObjectSetInteger(0,name,OBJPROP_YDISTANCE,yc);
         yc+=20;
        }
      name="Pending";

      ObjectCreate(0,name,OBJ_BUTTON,0,0,0);
      ObjectSetText(name,name,10,"Arial",clrBlue);
      ObjectSetInteger(0,name,OBJPROP_XDISTANCE,xc);
      ObjectSetInteger(0,name,OBJPROP_YDISTANCE,yc);

      for(int i=2; i<4; i++)
        {
         name=heading[i];
         ObjectCreate(0,name,OBJ_LABEL,0,0,0);
         ObjectSetText(name,name,10,"Arial",clrBlue);
         ObjectSetInteger(0,name,OBJPROP_XDISTANCE,xc);
         ObjectSetInteger(0,name,OBJPROP_YDISTANCE,yc);
         ObjectSetInteger(0,name,OBJPROP_SELECTED,false);
         yc+=20;
        }
     }
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(IsTesting())
     {
      string name="Buy";
      if(ObjectGetInteger(0,name,OBJPROP_STATE)==true)
        {
         ObjectSetInteger(0,name,OBJPROP_STATE,false);
         int ticket=OrderSend(Symbol(),OP_BUY,LotSize,Ask,50,NULL,NULL,NULL,MagicNumber,0,clrNONE);
        }
      name="Sell";
      if(ObjectGetInteger(0,name,OBJPROP_STATE)==true)
        {
         ObjectSetInteger(0,name,OBJPROP_STATE,false);
         int ticket=OrderSend(Symbol(),OP_SELL,LotSize,Ask,50,NULL,NULL,NULL,MagicNumber,0,clrNONE);
        }

     name="Pending";
        if(ObjectGetInteger(0,name,OBJPROP_STATE)==true)
        {
            ObjectSetInteger(0,name,OBJPROP_STATE,false);
            int lastTradeTicket = OrderTicket();
            if(lastTradeTicket > 0)
            {
                if(OrderSelect(lastTradeTicket, SELECT_BY_TICKET))
                {
                    double lastTradePrice = OrderOpenPrice();
                    double pendingPrice = NormalizeDouble(lastTradePrice - (20 * Point), Digits);
                    for(int i = 0; i < 3; i++)
                    {
                        int ticket=OrderSend(Symbol(), OP_SELLSTOP, LotSize, pendingPrice, 0, NULL, NULL, NULL, MagicNumber, 0, clrNONE);
                    }
                }
            }
        }
    }
}
  
//+------------------------------------------------------------------+
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Order Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

any help please ? 


i dont know how to do it , even chat GPT cant help me !!!

 
The best thing for you would be to ask a freelancer (https://www.mql5.com/en/job) to do it for you!
But please read up well beforehand:
rules: https://www.mql5.com/en/job/rules
EA   requirements specification:  https://www.mql5.com/en/articles/4368
Indicator requirements specification: https://www.mql5.com/en/articles/4304
How to Order a Trading Robot in MQL5 and MQL4:  https://www.mql5.com/en/articles/117
Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • 2023.01.14
  • www.mql5.com
The largest freelance service with MQL5 application developers
 
      string heading[4]= {"Buy","Sell"};
      ⋮

      for(int i=2; i<4; i++)
        {
         name=heading[i];
         ObjectCreate(0,name,OBJ_LABEL,0,0,0);
You can't create objects with a name of NULL.
 

William Roeder #:
You can't create objects with a name of NULL.

okay , but what i should do , cant you help edit the code 


because the buy and the sell button are working !!

 
bassem ED #:

i dont know how to do it , even chat GPT cant help me !!!

What is chat GPT?

Where did you get the code from?

#property copyright "Keith Watford"

It appears that you have obtained some of my code from somewhere and modified it.

It is important that you study and fully understand code before you try to modify it

string heading[4]= {"Buy","Sell"};

You have a 4 element array but you have only assigned a value to 2.

int lastTradeTicket = OrderTicket();

You must select an order before you use OrderTicket() etc.


Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.

 
Keith Watford #:

What is chat GPT?

Where did you get the code from?

It appears that you have obtained some of my code from somewhere and modified it.

It is important that you study and fully understand code before you try to modify it

You have a 4 element array but you have only assigned a value to 2.

You must select an order before you use OrderTicket() etc.


Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.

Sorry bro if I used your code without asking for it and I'll try to learn program from scratch

and I'm sorry because I choose the place of the subject wrong , for the chat GPT?  it's an Ai that can generate code for you  Everybody is talking about it these days   but I think it is not good with mql code

 
bassem ED #:

Sorry bro if I used your code without asking for it and I'll try to learn program from scratch

and I'm sorry because I choose the place of the subject wrong , for the chat GPT?  it's an Ai that can generate code for you  Everybody is talking about it these days   but I think it is not good with mql code

I have no problem with you using my code. I just wondered where you got it from.

But as I said you should study the original code and fully understand it before trying to modify it.

Reason: