how Add close all?

 

any one help me to put close all open orders & delete all pending orders & stop the EA......... when the equity > 20 $ or < -20 $



#include <stdlib.mqh>
#include <WinUser32.mqh>

// exported variables
extern double BuyLots2 = 0.01;
extern int BuyStoploss2 = 0;
extern int BuyTakeprofit2 = 500;
extern double BuyLots4 = 0.01;
extern int BuyStoploss4 = 0;
extern int BuyTakeprofit4 = 500;
extern int PriceOffset4 = 250;
extern double BuyLots17 = 0.01;
extern int BuyStoploss17 = 0;
extern int BuyTakeprofit17 = 500;
extern int PriceOffset17 = 500;
extern double BuyLots5 = 0.01;
extern int BuyStoploss5 = 0;
extern int BuyTakeprofit5 = 500;
extern int PriceOffset5 = 750;
extern double BuyLots6 = 0.01;
extern int BuyStoploss6 = 0;
extern int BuyTakeprofit6 = 500;
extern int PriceOffset6 = 1000;
extern double BuyLots18 = 0.01;
extern int BuyStoploss18 = 0;
extern int BuyTakeprofit18 = 500;
extern int PriceOffset18 = -250;
extern double BuyLots19 = 0.01;
extern int BuyStoploss19 = 0;
extern int BuyTakeprofit19 = 500;
extern int PriceOffset19 = -500;
extern double BuyLots20 = 0.01;
extern int BuyStoploss20 = 0;
extern int BuyTakeprofit20 = 500;
extern int PriceOffset20 = -750;
extern double BuyLots21 = 0.01;
extern int BuyStoploss21 = 0;
extern int BuyTakeprofit21 = 500;
extern int PriceOffset21 = -1000;
extern double Equity8 = 20;
extern double Equity9 = -20;


// local variables
double PipValue=1;    // this variable is here to support 5-digit brokers
bool Terminated = false;
string LF = "\n";  // use this in custom or utility blocks where you need line feeds
int NDigits = 4;   // used mostly for NormalizeDouble in Flex type blocks
int ObjCount = 0;  // count of all objects created on the chart, allows creation of objects with unique names
int current = 0;



int init()
{
    NDigits = Digits;
    
    if (false) ObjectsDeleteAll();      // clear the chart
    
    
    Comment("");    // clear the chart
}

// Expert start
int start()
{
    if (Bars < 10)
    {
        Comment("Not enough bars");
        return (0);
    }
    if (Terminated == true)
    {
        Comment("EA Terminated.");
        return (0);
    }
    
    OnEveryTick1();
    
}

void OnEveryTick1()
{
    if (true == false && false) PipValue = 10;
    if (true && (NDigits == 3 || NDigits == 5)) PipValue = 10;
    
    IfOrderDoesNotExist3();
    CheckEquity8();
    CheckEquity9();
    
}

void IfOrderDoesNotExist3()
{
    bool exists = false;
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
        {
            exists = true;
        }
    }
    else
    {
        Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    }
    
    if (exists == false)
    {
        BuyOrder2();
        BuyPendingOrder4();
        BuyPendingOrder18();
        
    }
}

void BuyOrder2()
{
    double SL = Ask - BuyStoploss2*PipValue*Point;
    if (BuyStoploss2 == 0) SL = 0;
    double TP = Ask + BuyTakeprofit2*PipValue*Point;
    if (BuyTakeprofit2 == 0) TP = 0;
    int ticket = -1;
    if (true)
    ticket = OrderSend(Symbol(), OP_BUY, BuyLots2, Ask, 100, 0, 0, "My Expert", 1, 0, Blue);
    else
    ticket = OrderSend(Symbol(), OP_BUY, BuyLots2, Ask, 100, SL, TP, "My Expert", 1, 0, Blue);
    if (ticket > -1)
    {
        if (true)
        {
            OrderSelect(ticket, SELECT_BY_TICKET);
            bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Blue);
            if (ret == false)
            Print("OrderModify() error - ", ErrorDescription(GetLastError()));
        }
            
    }
    else
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
}

void BuyPendingOrder4()
{
    int expire = TimeCurrent() + 60 * 0;
    double price = NormalizeDouble(Ask, NDigits) + PriceOffset4*PipValue*Point;
    double SL = price - BuyStoploss4*PipValue*Point;
    if (BuyStoploss4 == 0) SL = 0;
    double TP = price + BuyTakeprofit4*PipValue*Point;
    if (BuyTakeprofit4 == 0) TP = 0;
    if (0 == 0) expire = 0;
    int ticket = OrderSend(Symbol(), OP_BUYSTOP, BuyLots4, price, 4, SL, TP, "My Expert", 2, expire, Blue);
    if (ticket == -1)
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
    BuyPendingOrder17();
    
}

void BuyPendingOrder17()
{
    int expire = TimeCurrent() + 60 * 0;
    double price = NormalizeDouble(Ask, NDigits) + PriceOffset17*PipValue*Point;
    double SL = price - BuyStoploss17*PipValue*Point;
    if (BuyStoploss17 == 0) SL = 0;
    double TP = price + BuyTakeprofit17*PipValue*Point;
    if (BuyTakeprofit17 == 0) TP = 0;
    if (0 == 0) expire = 0;
    int ticket = OrderSend(Symbol(), OP_BUYSTOP, BuyLots17, price, 4, SL, TP, "My Expert", 3, expire, Blue);
    if (ticket == -1)
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
    BuyPendingOrder5();
    
}

void BuyPendingOrder5()
{
    int expire = TimeCurrent() + 60 * 0;
    double price = NormalizeDouble(Ask, NDigits) + PriceOffset5*PipValue*Point;
    double SL = price - BuyStoploss5*PipValue*Point;
    if (BuyStoploss5 == 0) SL = 0;
    double TP = price + BuyTakeprofit5*PipValue*Point;
    if (BuyTakeprofit5 == 0) TP = 0;
    if (0 == 0) expire = 0;
    int ticket = OrderSend(Symbol(), OP_BUYSTOP, BuyLots5, price, 4, SL, TP, "My Expert", 4, expire, Blue);
    if (ticket == -1)
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
    BuyPendingOrder6();
    
}

void BuyPendingOrder6()
{
    int expire = TimeCurrent() + 60 * 0;
    double price = NormalizeDouble(Ask, NDigits) + PriceOffset6*PipValue*Point;
    double SL = price - BuyStoploss6*PipValue*Point;
    if (BuyStoploss6 == 0) SL = 0;
    double TP = price + BuyTakeprofit6*PipValue*Point;
    if (BuyTakeprofit6 == 0) TP = 0;
    if (0 == 0) expire = 0;
    int ticket = OrderSend(Symbol(), OP_BUYSTOP, BuyLots6, price, 4, SL, TP, "My Expert", 5, expire, Blue);
    if (ticket == -1)
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
    
}

void BuyPendingOrder18()
{
    int expire = TimeCurrent() + 60 * 0;
    double price = NormalizeDouble(Ask, NDigits) + PriceOffset18*PipValue*Point;
    double SL = price - BuyStoploss18*PipValue*Point;
    if (BuyStoploss18 == 0) SL = 0;
    double TP = price + BuyTakeprofit18*PipValue*Point;
    if (BuyTakeprofit18 == 0) TP = 0;
    if (0 == 0) expire = 0;
    int ticket = OrderSend(Symbol(), OP_BUYLIMIT, BuyLots18, price, 4, SL, TP, "My Expert", 6, expire, Blue);
    if (ticket == -1)
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
    BuyPendingOrder19();
    
}

void BuyPendingOrder19()
{
    int expire = TimeCurrent() + 60 * 0;
    double price = NormalizeDouble(Ask, NDigits) + PriceOffset19*PipValue*Point;
    double SL = price - BuyStoploss19*PipValue*Point;
    if (BuyStoploss19 == 0) SL = 0;
    double TP = price + BuyTakeprofit19*PipValue*Point;
    if (BuyTakeprofit19 == 0) TP = 0;
    if (0 == 0) expire = 0;
    int ticket = OrderSend(Symbol(), OP_BUYLIMIT, BuyLots19, price, 4, SL, TP, "My Expert", 7, expire, Blue);
    if (ticket == -1)
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
    BuyPendingOrder20();
    
}

void BuyPendingOrder20()
{
    int expire = TimeCurrent() + 60 * 0;
    double price = NormalizeDouble(Ask, NDigits) + PriceOffset20*PipValue*Point;
    double SL = price - BuyStoploss20*PipValue*Point;
    if (BuyStoploss20 == 0) SL = 0;
    double TP = price + BuyTakeprofit20*PipValue*Point;
    if (BuyTakeprofit20 == 0) TP = 0;
    if (0 == 0) expire = 0;
    int ticket = OrderSend(Symbol(), OP_BUYLIMIT, BuyLots20, price, 4, SL, TP, "My Expert", 8, expire, Blue);
    if (ticket == -1)
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
    BuyPendingOrder21();
    
}

void BuyPendingOrder21()
{
    int expire = TimeCurrent() + 60 * 0;
    double price = NormalizeDouble(Ask, NDigits) + PriceOffset21*PipValue*Point;
    double SL = price - BuyStoploss21*PipValue*Point;
    if (BuyStoploss21 == 0) SL = 0;
    double TP = price + BuyTakeprofit21*PipValue*Point;
    if (BuyTakeprofit21 == 0) TP = 0;
    if (0 == 0) expire = 0;
    int ticket = OrderSend(Symbol(), OP_BUYLIMIT, BuyLots21, price, 4, SL, TP, "My Expert", 9, expire, Blue);
    if (ticket == -1)
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
    
}

void CheckEquity8()
{
    
    if (AccountEquity() > Equity8)
    {
            
    }
}

void CheckEquity9()
{
    
    if (AccountEquity() < Equity9)
    {
            
    }
}



int deinit()
{
    if (false) ObjectsDeleteAll();
    
    
}

 
Though it is not hard at all I'd suggest you to have an experienced coder do it for you. This is about your money --- if a bug sneaks in as result of changing the code you'll get burned!
 
forex206:
any one help me to put close all open orders & delete all pending orders & stop the EA......... when the equity > 20 $ or < -20 $
No Slaves here, learn to code or pay someone. We're not going to code it FOR you. We are willing to HELP you.
if (MathAbs(AccountEquity() - AccountBalance()) > 20) CloseAllOrders()
Reason: