Debug

MQL5 Experts

Specification

Here's the modified version of the code that will buy US100 and sell Dax40 simultaneously with an equity stop loss of 50 USD and equity profit of 1 USD. After reaching the stop loss or profit target, the code will close the trades and open new ones:

```mq5
//+------------------------------------------------------------------+
//|                                                     My Expert.mq5 |
//|                              Copyright © 2021 your_company_name |
//|                                      https://www.your_website.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2021 your_company_name"
#property link      "https://www.your_website.com"
#property version   "1.00"
#property strict

// Input parameters
input double StopLoss = 50;     // Equity stop loss in USD
input double ProfitTarget = 1;  // Equity profit target in USD

// Global variables
bool BuyUS100 = false;   // Flag to buy US100
bool SellDax40 = false;  // Flag to sell Dax40

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
    // Initialize the flags
    BuyUS100 = true;
    SellDax40 = true;
    
    return INIT_SUCCEEDED;
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
    // Close any open positions
    if (PositionSelect(_Symbol))
        PositionClose(_Symbol);
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
    // Check if the buy US100 flag is set
    if (BuyUS100)
    {
        // Calculate the lot size based on equity stop loss
        double lotSize = StopLoss / (SymbolInfoDouble(_Symbol, SYMBOL_BID) - SymbolInfoDouble(_Symbol, SYMBOL_BID)/100);
        
        // Open a buy position
        OrderSend(_Symbol, OP_BUY, lotSize, SymbolInfoDouble(_Symbol, SYMBOL_BID), 10, SymbolInfoDouble(_Symbol, SYMBOL_BID) - StopLoss, SymbolInfoDouble(_Symbol, SYMBOL_BID) + ProfitTarget, "Buy US100", 0, 0, Green);
        
        BuyUS100 = false;  // Reset the buy flag
    }
    
    // Check if the sell Dax40 flag is set
    if (SellDax40)
    {
        // Calculate the lot size based on equity stop loss
        double lotSize = StopLoss / (SymbolInfoDouble("DAX40", SYMBOL_ASK) - SymbolInfoDouble("DAX40", SYMBOL_ASK)/100);
        
        // Open a sell position
        OrderSend("DAX40", OP_SELL, lotSize, SymbolInfoDouble("DAX40", SYMBOL_ASK), 10, SymbolInfoDouble("DAX40", SYMBOL_ASK) + StopLoss, SymbolInfoDouble("DAX40", SYMBOL_ASK) - ProfitTarget, "Sell Dax40", 0, 0, Red);
        
        SellDax40 = false;  // Reset the sell flag
    }
    
    // Check if the equity stop loss is reached
    if (AccountInfoDouble(ACCOUNT_EQUITY) <= AccountInfoDouble(ACCOUNT_BALANCE) - StopLoss)
    {
        // Close the positions
        ClosePositions();
        
        // Open new positions
        BuyUS100 = true;
        SellDax40 = true;
    }
    
    // Check if the equity profit target is reached
    if (AccountInfoDouble(ACCOUNT_EQUITY) >= AccountInfoDouble(ACCOUNT_BALANCE) + ProfitTarget)
    {
        // Close the positions
        ClosePositions();
        
        // Open new positions
        BuyUS100 = true;
        SellDax40 = true;
    }
}

//+------------------------------------------------------------------+
//| Close all open positions                                          |
//+------------------------------------------------------------------+
void ClosePositions()
{
    // Close the US100 position
    if (PositionSelect(_Symbol))
        PositionClose(_Symbol);
        
    // Close the Dax40 position
    if (PositionSelect("DAX40"))
        PositionClose("DAX40");
}
```

Responded

1
Developer 1
Rating
(52)
Projects
62
6%
Arbitration
22
23% / 36%
Overdue
4
6%
Busy
2
Developer 2
Rating
(8)
Projects
11
18%
Arbitration
7
43% / 29%
Overdue
1
9%
Free
3
Developer 3
Rating
(466)
Projects
697
56%
Arbitration
43
30% / 33%
Overdue
113
16%
Working
4
Developer 4
Rating
(11)
Projects
13
38%
Arbitration
0
Overdue
2
15%
Free
5
Developer 5
Rating
(30)
Projects
55
22%
Arbitration
12
67% / 8%
Overdue
2
4%
Free
6
Developer 6
Rating
(37)
Projects
59
27%
Arbitration
25
20% / 52%
Overdue
10
17%
Working
7
Developer 7
Rating
(140)
Projects
204
80%
Arbitration
17
29% / 47%
Overdue
10
5%
Working
Similar orders
Long Position 1. Trend Line: When a Lower High (LH) is formed, draw a trend line from the previous Higher High (HH) to the new LH. 2. Trend Line Adjustment: If a new Lower High (LH) is formed without breaking the trend line, redraw the trend line to the new LH. Draw a trend line between the Higher High (HH) and the Higher Low (HL). If a new Higher High (HH) is formed, remove the previous trend line and draw a new one
Please watch the video on this youtube channel and download the Indicator from there. https://www.youtube.com/watch?v=ldTomLu8DxE&amp ;t=32s Rules are explained on the video and the download of the indicator is on the same video
I would like an EA that follows exactly this steps to trade de daily candle. Watch the video and then see if you can do the task. https://www.youtube.com/watch?v=g3oDYq4P9ZE Document is one this link https://cdn.discordapp.com/attachments/1135977927469703230/1135978751461695598/Daily_Bias-TTrades_edu.pdf?ex=669a9a27&amp ;is=669948a7&hm=96de195f7e695a381c1261b065f67b94fae319d02a0c88641b146f8b2978320c& Should have
I have a custom EA that works fine in the live market trading, but when doing a back test in the strategy tester , it does not open sell orders. There are no errors or warnings; it just doesn't open sell orders. I've checked every possible reason that might be the reason why it does not open sell orders, but I can't find anything, especially since it works fine in the real market and it opens both buys and sells
Hi, I have an indicator from my friend, I want to copy it to my own MT5 can you do that for me. Here is the link
I installed the E.A. into the Experts folder in MT4. When I double click on it nothing happens. When I right click and "attach to chart" nothing happens. The E.A. is not grayed out, it simply will not attach. Any help would be greatly Appreciated
I have an EA and want to add few new logic to fetch profit taking factors and other values from an external master data and use it in existing EA
Hello Every one, Good day, I want from someone professional to create an EA is working on Mt5, This EA is working by depend on some indicators, and all those indicators must be working on MACD window, not on the chart, for more details please read my attached pdf file carefully. Many Thanks
I'm looking for an expert MQL5 developer that can create an EA that's based on my price action trading strategy with no indicators. The EA must analyze trades based on my price action rules, enter trades based on my price action rules, manage trades based on my price action rules and exit trades based on my price action rules
hi hi there i have an strategy on tradingview and i want to automate it like metatrader EA so i want the strategy to open and close trade automaticlly on tradingview

Project information

Budget
30+ USD
For the developer
27 USD
Deadline
from 1 to 10 day(s)