Debug

MQL5 Experts

Spécifications

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");
}
```

Répondu

1
Développeur 1
Évaluation
(52)
Projets
62
6%
Arbitrage
22
23% / 36%
En retard
4
6%
Occupé
2
Développeur 2
Évaluation
(8)
Projets
11
18%
Arbitrage
7
43% / 29%
En retard
1
9%
Gratuit
3
Développeur 3
Évaluation
(466)
Projets
697
56%
Arbitrage
43
30% / 33%
En retard
113
16%
Travail
4
Développeur 4
Évaluation
(11)
Projets
13
38%
Arbitrage
0
En retard
2
15%
Gratuit
5
Développeur 5
Évaluation
(30)
Projets
55
22%
Arbitrage
12
67% / 8%
En retard
2
4%
Gratuit
6
Développeur 6
Évaluation
(37)
Projets
59
27%
Arbitrage
25
20% / 52%
En retard
10
17%
Travail
7
Développeur 7
Évaluation
(140)
Projets
204
80%
Arbitrage
17
29% / 47%
En retard
10
5%
Travail
Commandes similaires
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px 'Helvetica Neue'} Hello Looking for someone to help me improve my current strategy on my own algorithm and to also add hedging mode
I want the script in mql5 language for my martingale strategy. The script should open trades in both directions buy and sell and if any trade closes in loss then open new trade in that direction by using the next volume and when trade closes in profit then reset the volume to first from volume list and also maximum consecutive losses limit will apply. If trades closes consecutively in losses and hits the limit then
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

Informations sur le projet

Budget
30+ USD
Pour le développeur
27 USD
Délais
de 1 à 10 jour(s)