Help for my EA

 
Hello everyone, I am an Italian newbie, I have created a simple EA based on crossing of moving averages and I work with 3 pairs of currencies. I would need to terminate EA when the total closed orders reach $ 5 profit but for every single pair, with magic number. Can someone help me?
 

If you uploaded your code here so the users may help for example:

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button

Thank you.

 
Sergey Golubev:

Or use Freelance service to find the coder for fixing/improvement for example: 

============

Thank you for your answer! 

I would  EA terminated when the total of the closed orders (with magic number) is profit => 5 $

Here is the code:


#property copyright "Copyright © 2018"
#property link      "http://www..com/"

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

// exported variables
extern double BuyLots6 = 0.1;
extern int BuyStoploss6 = 20;
extern int BuyTakeprofit6 = 30;
extern double SellLots7 = 0.1;
extern int SellStoploss7 = 20;
extern int SellTakeprofit7 = 30;


// 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;

datetime BarTime1 = 0;


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

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

void OnEveryNewBar1()
{
    PipValue = 1;
    if (NDigits == 3 || NDigits == 5) PipValue = 10;
    if (BarTime1 < Time[0])
    {
        // we have a new bar opened
        BarTime1 = Time[0]; // keep the new bar open time
        TechnicalAnalysis2x2();
        TechnicalAnalysis2x3();
        
    }
}

void TechnicalAnalysis2x2()
{
    if ((iMA(NULL, NULL,5,0,MODE_EMA,PRICE_CLOSE,1) > iMA(NULL, NULL,21,0,MODE_EMA,PRICE_CLOSE,1)) && (iMA(NULL, NULL,5,0,MODE_EMA,PRICE_CLOSE,2) <= iMA(NULL, NULL,21,0,MODE_EMA,PRICE_CLOSE,2)))
    {
        IfOrderDoesNotExist5();
        
    }
}

void IfOrderDoesNotExist5()
{
    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)
    {
        BuyOrder6();
        
    }
}

void BuyOrder6()
{
    double SL = Ask - BuyStoploss6*PipValue*Point;
    if (BuyStoploss6 == 0) SL = 0;
    double TP = Ask + BuyTakeprofit6*PipValue*Point;
    if (BuyTakeprofit6 == 0) TP = 0;
    int ticket = -1;
    if (true)
    ticket = OrderSend(Symbol(), OP_BUY, BuyLots6, Ask, 3, 0, 0, "", 1, 0, Blue);
    else
    ticket = OrderSend(Symbol(), OP_BUY, BuyLots6, Ask, 3, SL, TP, "", 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 TechnicalAnalysis2x3()
{
    if ((iMA(NULL, NULL,5,0,MODE_EMA,PRICE_CLOSE,1) < iMA(NULL, NULL,21,0,MODE_EMA,PRICE_CLOSE,1)) && (iMA(NULL, NULL,5,0,MODE_EMA,PRICE_CLOSE,2) >= iMA(NULL, NULL,21,0,MODE_EMA,PRICE_CLOSE,2)))
    {
        IfOrderDoesNotExist4();
        
    }
}

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

void SellOrder7()
{
    double SL = Bid + SellStoploss7*PipValue*Point;
    if (SellStoploss7 == 0) SL = 0;
    double TP = Bid - SellTakeprofit7*PipValue*Point;
    if (SellTakeprofit7 == 0) TP = 0;
    int ticket = -1;
    if (true)
    ticket = OrderSend(Symbol(), OP_SELL, SellLots7, Bid, 3, 0, 0, "", 1, 0, Red);
    else
    ticket = OrderSend(Symbol(), OP_SELL, SellLots7, Bid, 3, SL, TP, "", 1, 0, Red);
    if (ticket > -1)
    {
        if (true)
        {
            OrderSelect(ticket, SELECT_BY_TICKET);
            bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Red);
            if (ret == false)
            Print("OrderModify() error - ", ErrorDescription(GetLastError()));
        }
            
    }
    else
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
}



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





 
serbauer:

Thank you for your answer! 

I would  EA terminated when the total of the closed orders (with magic number) is profit => 5 $

Here is the code:





I am not a coder.
I just hope someone will help here on the thread (if not so go to Freelance).