I need help modifying MT5 built-in Experts: ExpertMACD.mq5 to open a position in the opposite direction

 
Hello everyone, I want to modify the MT5 built-in Experts: ExpertMACD.mq5, if the current signal is to buy, then open a sell order, if the signal is to sell, then open a buy order

I have no experience with MQL scripting , but I know it's probably a simple line or 2 of code that could be edited to make these changes, just not 100% sure which and what to change it to.

Please help, thanks
 //+------------------------------------------------------------------+
 //|                                                   ExpertMACD.mq5 |
 //|                             Copyright 2000-2024, MetaQuotes Ltd. |
 //|                                             https://www.mql5.com |
 //+------------------------------------------------------------------+
 #property copyright "Copyright 2000-2024, MetaQuotes Ltd."
 #property link        "https://www.mql5.com"
 #property version    "1.00"
 //+------------------------------------------------------------------+
 //| Include                                                          |
 //+------------------------------------------------------------------+
 #include <Expert\Expert.mqh>
 #include <Expert\Signal\SignalMACD.mqh>
 #include <Expert\Trailing\TrailingNone.mqh>
 #include <Expert\Money\MoneyNone.mqh>
 //+------------------------------------------------------------------+
 //| Inputs                                                           |
 //+------------------------------------------------------------------+
 //--- inputs for expert
 input string Inp_Expert_Title            = "ExpertMACD" ;
 int           Expert_MagicNumber          = 10981 ;
 bool          Expert_EveryTick            = false ;
 //--- inputs for signal
 input int     Inp_Signal_MACD_PeriodFast  = 12 ;
 input int     Inp_Signal_MACD_PeriodSlow  = 24 ;
 input int     Inp_Signal_MACD_PeriodSignal= 9 ;
 input int     Inp_Signal_MACD_TakeProfit  = 50 ;
 input int     Inp_Signal_MACD_StopLoss    = 20 ;
 //+------------------------------------------------------------------+
 //| Global expert object                                             |
 //+------------------------------------------------------------------+ 
CExpert ExtExpert;
 //+------------------------------------------------------------------+
 //| Initialization function of the expert                            |
 //+------------------------------------------------------------------+
 int OnInit ( void )
  {
 //--- Initializing expert 
   if (!ExtExpert.Init( Symbol (), Period (),Expert_EveryTick,Expert_MagicNumber))
     {
       //--- failed 
       printf ( __FUNCTION__ + ": error initializing expert" );
      ExtExpert.Deinit();
       return (- 1 );
     }
 //--- Creation of signal object 
   CSignalMACD *signal= new CSignalMACD;
   if (signal== NULL )
     {
       //--- failed 
       printf ( __FUNCTION__ + ": error creating signal" );
      ExtExpert.Deinit();
       return (- 2 );
     }
 //--- Add signal to expert (will be deleted automatically)) 
   if (!ExtExpert.InitSignal(signal))
     {
       //--- failed 
       printf ( __FUNCTION__ + ": error initializing signal" );
      ExtExpert.Deinit();
       return (- 3 );
     }
 //--- Set signal parameters 
   signal.PeriodFast(Inp_Signal_MACD_PeriodFast);
   signal.PeriodSlow(Inp_Signal_MACD_PeriodSlow);
   signal.PeriodSignal(Inp_Signal_MACD_PeriodSignal);
   signal.TakeLevel(Inp_Signal_MACD_TakeProfit);
   signal.StopLevel(Inp_Signal_MACD_StopLoss);
 //--- Check signal parameters 
   if (!signal.ValidationSettings())
     {
       //--- failed 
       printf ( __FUNCTION__ + ": error signal parameters" );
      ExtExpert.Deinit();
       return (- 4 );
     }
 //--- Creation of trailing object 
   CTrailingNone *trailing= new CTrailingNone;
   if (trailing== NULL )
     {
       //--- failed 
       printf ( __FUNCTION__ + ": error creating trailing" );
      ExtExpert.Deinit();
       return (- 5 );
     }
 //--- Add trailing to expert (will be deleted automatically)) 
   if (!ExtExpert.InitTrailing(trailing))
     {
       //--- failed 
       printf ( __FUNCTION__ + ": error initializing trailing" );
      ExtExpert.Deinit();
       return (- 6 );
     }
 //--- Set trailing parameters
 //--- Check trailing parameters 
   if (!trailing.ValidationSettings())
     {
       //--- failed 
       printf ( __FUNCTION__ + ": error trailing parameters" );
      ExtExpert.Deinit();
       return (- 7 );
     }
 //--- Creation of money object 
   CMoneyNone *money= new CMoneyNone;
   if (money== NULL )
     {
       //--- failed 
       printf ( __FUNCTION__ + ": error creating money" );
      ExtExpert.Deinit();
       return (- 8 );
     }
 //--- Add money to expert (will be deleted automatically)) 
   if (!ExtExpert.InitMoney(money))
     {
       //--- failed 
       printf ( __FUNCTION__ + ": error initializing money" );
      ExtExpert.Deinit();
       return (- 9 );
     }
 //--- Set money parameters
 //--- Check money parameters 
   if (!money.ValidationSettings())
     {
       //--- failed 
       printf ( __FUNCTION__ + ": error money parameters" );
      ExtExpert.Deinit();
       return (- 10 );
     }
 //--- Tuning of all necessary indicators 
   if (!ExtExpert.InitIndicators())
     {
       //--- failed 
       printf ( __FUNCTION__ + ": error initializing indicators" );
      ExtExpert.Deinit();
       return (- 11 );
     }
 //--- succeed 
   return ( INIT_SUCCEEDED );
  }
 //+------------------------------------------------------------------+
 //| Deinitialization function of the expert                          |
 //+------------------------------------------------------------------+
 void OnDeinit ( const int reason)
  {
   ExtExpert.Deinit();
  }
 //+------------------------------------------------------------------+
 //| Function-event handler "tick"                                    |
 //+------------------------------------------------------------------+
 void OnTick ( void )
  {
   ExtExpert. OnTick ();
  }
 //+------------------------------------------------------------------+
 //| Function-event handler "trade"                                   |
 //+------------------------------------------------------------------+
 void OnTrade ( void )
  {
   ExtExpert. OnTrade ();
  }
 //+------------------------------------------------------------------+
 //| Function-event handler "timer"                                   |
 //+------------------------------------------------------------------+
 void OnTimer ( void )
  {
   ExtExpert. OnTimer ();
  }
 //+------------------------------------------------------------------+
Files:
 
  1. xingfuman: I have no experience with MQL scripting

    You have only four choices:

    1. Search for it (CodeBase or Market). Do you expect us to do your research for you?

    2. Try asking at:

    3. MT4: Learn to code it.
      MT5: Begin learning to code it.

      If you don't learn MQL4/5, 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 your code.
                I need HEEEELP, please, it's URGENT...really ! - General - MQL5 programming forum (2017)

    4. Or pay (Freelance) someone to code it. Top of every page is the link Freelance.
                Hiring to write script - General - MQL5 programming forum (2019)

    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
              No free help (2017)


  2. xingfuman: if the current signal is to buy, then open a sell order, if the signal is to sell, then open a buy order

    Not worth the time. Always buying is a loosing strategy, so is always selling. Either way you pay the spread.

 

cExpert is set in stone, you can't really modify it like that

You need to code it from scratch using the Trade.mqh library. Your best chance is to reverse engineer codes in the codebase, and ignore these built-in experts which can't be modified.

Another option is to make your own signal script which the EA wizard can import, and call it "Signals of the macd", but this is much more tedious and there aren't clear guides on going about this