Download MetaTrader 5

How to plug in a Script to EA?

To add comments, please log in or register
huntrader64
11
huntrader64  

Hi guys, please I need help to plug these two things together...

I have this EA (mql4), which is monitoring the account Balance, Equity and Profit. When the set profit or the set loss % is reached the robot closes all open trades.

I also want the Autotrade in Mt4 to be turned off to prevent the main EA to open new trades.

I have a Script for that, but I don't know how to plug it in to EA. Can somebody please help me?


The Script:


#include <WinUser32.mqh>

extern bool DisableAllEAs = TRUE;
 
void DisableEA() {
keybd_event(17, 0, 0, 0);
keybd_event(69, 0, 0, 0);
keybd_event(69, 0, 2, 0);
keybd_event(17, 0, 2, 0);
}
 
 
int start() {
 
if (DisableAllEAs == TRUE) {
DisableEA();
return (0);
}}


The EA:


//If sett loss or profit reached close all trades and stop EA

extern double equity_percent_from_balances=0.9;

extern int profit_target=200;

 

 

int start()

  {

  

   if(AccountEquity()<(AccountBalance()*equity_percent_from_balances) ||        (AccountProfit()>profit_target))

     {

      int total=OrdersTotal();

 

      for(int i=total-1;i>=0;i--)

        {

         if(OrderSelect(i,SELECT_BY_POS)==true)

           {

            int type=OrderType();

 

            bool result=false;

 

            switch(type)

              {

               case OP_BUY       : result=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,Red);

               break;

               case OP_SELL      : result=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,Red);

              }

 

            if(result==false)

              {

               Sleep(0);

              }

           }

        }

     }

   return(0);

  }


whroeder1
17116
whroeder1  
huntrader64: I have a Script for that, but I don't know how to plug it in to EA.
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it

  2. When your condition occurs, call the function. learn to code it, or pay (Freelance) someone to code it. 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 SRC) and the nature of your problem.
To add comments, please log in or register