MT5 Function that Returns the Maximum Drawdown for Symbol / Side

MQL5 Indicadores Asesores Expertos

Trabajo finalizado

Plazo de ejecución 9 horas
Comentario del Cliente
recommended to anyone
Comentario del Ejecutor
Clear description, quick test. A pleasure this project.

Tarea técnica

Create a Function that Returns the Maximum Drawdown for a Symbol and Side 

NOTE:

  • I am not looking for the Maximum Daily Drawdown, I am looking for the maximum drawdown for currently open trades of a referenced symbol and side.
  • Function needs to work for multi symbols 

Use this code to Count the Number of Trades for the Symbol & Side;

If number of Trades for the Symbol and side == 0 (then Maximum Drawdown is reset to Zero).

int NumberOfTrades(string symb, int OrderType)
  {
   int val=0;

   for (int cnt = 0; cnt < PositionsTotal(); cnt++) 
     {
      if(!position.SelectByIndex(cnt))
        {
         continue;
        }
      if(position.
Symbol() != symb)
         continue;
      if(position.Symbol()== symb)
         if(position.PositionType() == OrderType)
            val++;
     }
   return (val);
  }


Potentially code to leverage (or use your own).

double CalculateMaxOpenDrawdown(string symbol, ENUM_ORDER_TYPE side)
{
   // Define the variables to store drawdown information
   double maxDrawdown = 0.0;
   double dailyHigh = 0.0;
   double dailyLow = 0.0;
   int lastOrderDay = 0;

   // Iterate through open orders
   for (int i = 0; i < OrdersTotal(); i++)
   {
      // Get order ticket
      ulong ticket = OrderGetTicket(i);

      // Check if the order is for the specified symbol and side
      if (OrderGetString(ORDER_SYMBOL) == symbol && OrderGetInteger(ORDER_TYPE) == side)
      {
         // Get the order's open time and price
         datetime orderOpenTime = OrderGetInteger(ORDER_TIME_SETUP);
         double orderOpenPrice = OrderGetDouble(ORDER_PRICE_OPEN);

         // Extract the day from the order open time
         datetime serverTime = TimeCurrent(); // Use the current server time
         int orderDay = TimeDay(orderOpenTime);
         int currentDay = TimeDay(serverTime);

         // If the order day is different from the last order day, reset dailyHigh and dailyLow
         if (orderDay != lastOrderDay)
         {
            dailyHigh = orderOpenPrice;
            dailyLow = orderOpenPrice;
            lastOrderDay = orderDay;
         }

         // Update dailyHigh and dailyLow if necessary
         if (orderOpenPrice > dailyHigh)
            dailyHigh = orderOpenPrice;
         else if (orderOpenPrice < dailyLow)
            dailyLow = orderOpenPrice;

         // Calculate the drawdown for the current order
         double drawdown = side == OP_BUY ? (orderOpenPrice - dailyLow) : (dailyHigh - orderOpenPrice);

         // Update maxDrawdown if the current drawdown is greater
         if (drawdown > maxDrawdown)
            maxDrawdown = drawdown;
      }
   }

   return maxDrawdown;
}



Han respondido

1
Desarrollador 1
Evaluación
(75)
Proyectos
80
6%
Arbitraje
46
11% / 54%
Caducado
7
9%
Trabaja
2
Desarrollador 2
Evaluación
(9)
Proyectos
19
16%
Arbitraje
3
67% / 0%
Caducado
0
Libre
3
Desarrollador 3
Evaluación
(217)
Proyectos
369
33%
Arbitraje
34
41% / 29%
Caducado
108
29%
Libre
Ha publicado: 1 ejemplo
4
Desarrollador 4
Evaluación
(453)
Proyectos
566
26%
Arbitraje
24
42% / 38%
Caducado
85
15%
Libre
Ha publicado: 6 ejemplos
Solicitudes similares
I’m looking for an experienced MT4 developer to create a custom indicator (or EA) with mobile push notifications based on the following strategy. Trend Filter (Daily Timeframe) Daily Close above 50 EMA = Bullish Bias Daily Close below 50 EMA = Bearish Bias Entry Timeframe (H1) RSI Settings RSI Period: 14 (default) Upper Level: 65 Lower Level: 35 Buy Signal Generate a BUY signal when: Daily bias is Bullish (Daily
Hello, I'm looking for EA or indicator that would help me reach at least 0.5 lot daily on XAUUSD pair. I trade with 30-35 spread on live standard account. 0.3 to 0.5 lot on XAUUSD is all i need per day, without losing too much money during week or month doing that. Every advice od product is welcome. tg @stellarcptadmin
✅ MT4 EA Developer Checklist (For Your Ladder EA) 1️⃣ Indicator Integration EA reads signals from provided custom indicator (.ex4 or .mq4) Detects “Buy Next” / “Sell Next” signals on current candle Works with arrow-based or buffer-based signals 2️⃣ Next Candle Execution EA does not trade on the candle where the signal appears Orders placed only at first tick of the next candle Timeframes supported: M1, M5, M15
Hello, i need expert developer that have been develop so many profitable AI bots that work for mt5 and ctrader autonomously if you know you can easily execute this requirement bid for it. NOTE:- YOU MUST COME WITH SAMPLE FOR THE 2 TRADING PLATFORM. While i take a look at your profile and reach out to you thanks
I am looking for an experienced MT4/MT5 developer to analyze my trading history and replicate the strategy in a new Expert Advisor (EA). The developer must have proven experience in reverse engineering strategies, analyzing trading data, and developing EAs across various trading methodologies. A deep understanding of XAUUDS and BTCUSD behavior, as well as chart analysis, is essential. Please note that we do not have
Ea.Mix 30+ USD
I am in need of a good scalping bot for gold or any currency pair. If you have one that is working, reach out. You must be able to provide a trial version so I can test the bot myself
I am in need of a good scalping bot for gold or any currency pair. If you have one that is working, reach out. You must be able to provide a trial version so I can test the bot myself
i have built a indicator on trading view which is veryt good, its based on liquidity sweeps on stop losses. im looking for an someone with experience in trading and indicators that has worked on similar strategy indicators. it already wins lots of very good trades im looking to tighten up on uneccesary trades it may send to clean it up as i currently am testing it out running to signal channel and want it the best /
Generate a signal and place 2 arrows on the chart when these conditions happen. Rules: Levels up:price is below the Kijunsen and Senku A value is less than Senku B value Kijun sen close = previous kijun sen close; Kijun sen close value is LESS than Senku B close value Senkou B close = previous senku B close. Levels down: price is above Kijunsen. Senku A value is above Senku B value
ZigZag based on oscillators is needed The idea of ​​the indicator Create a ZigZag indicator, which is constructed based on extreme values determined using oscillators. It can use any classical normalized oscillator, which has overbought and oversold zones. The algorithm should first be executed with the WPR indicator, then similarly add the possibility to draw a zigzag using the following indicators: CCI Chaikin RSI

Información sobre el proyecto

Presupuesto
40+ USD
Plazo límite de ejecución
a 1 día(s)