MT5 Function that Returns the Maximum Drawdown for Symbol / Side

MQL5 指标 专家

工作已完成

执行时间9 小时
客户反馈
recommended to anyone
员工反馈
Clear description, quick test. A pleasure this project.

指定

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



反馈

1
开发者 1
等级
(75)
项目
80
6%
仲裁
46
11% / 54%
逾期
7
9%
工作中
2
开发者 2
等级
(9)
项目
19
16%
仲裁
3
67% / 0%
逾期
0
空闲
3
开发者 3
等级
(217)
项目
369
33%
仲裁
34
41% / 29%
逾期
108
29%
空闲
发布者: 1 代码
4
开发者 4
等级
(453)
项目
566
26%
仲裁
24
42% / 38%
逾期
85
15%
空闲
发布者: 6 代码
相似订单
I want a robot that will monitor the h4 time frame. wait for 10ema to cross below or above 50 ema. look for candles to touch the 10 ema, wait for a break of structure and a reversal to the neckline. the robot must send me notification when the reversal touches the neckline and give visual indication on the chart
Hello, I have an existing XAUUSD market-analysis system called I am looking for an experienced MQL5 developer to perform a technical review and prepare a precise architecture for rebuilding the existing SIGNAL ENGINE / ANALYSIS LOGIC in MQL5. IMPORTANT: This request is ONLY about the signal-analysis engine. I am NOT requesting an Expert Advisor (EA), automated trading system, order execution, or live trading
Hi, I'm looking for an experienced MQL5 developer to build a profitable Expert Advisor for MetaTrader 5. The goal is to get the highest possible return from a small account while keeping the account alive. ACCOUNT - Broker: IC Markets (EU, regulated), MT5, hedging account - Leverage: 1:30 - Deposit: 200 USD - Instruments: Forex and/or XAUUSD, your choice. Please check that the margin for the minimum lot size is
I need a professional MT5 Expert Advisor for multi-symbol trade monitoring and risk management. The EA should focus on trade management rather than generating trading signals. Requirements: Platform: MetaTrader 5 / MQL5 Monitor all open positions on the account Multi-symbol support Display a dashboard showing: Symbol Buy/Sell direction Lot size Entry price Current profit/loss Stop Loss Take Profit Configurable
Hi, I’m looking for an experienced MQL5/MT5 developer to build a complex AI-powered adaptive Expert Advisor for XAUUSD+ on Ultima Markets. I have a detailed 28-section technical specification, and the requirements are fixed. I’m looking for the complete implementation , not a simplified EA or a conventional indicator-based system. The project includes: Genuine AI/ML integration AI-based market regime classification
This may be a weird request but if anyone has an EA that is actually consistently profitable I want to buy a copy from you. Ideally trades a lot, I'm sure theres a coder out there who has made a profitable EA, I want to backtest if you have, I have been trying to code a few on my own with no success as I'm not yet good at coding, lets see what ya got.thanks
I need a simple MetaTrader 5 Expert Advisor based on a MACD crossover. Requirements: Platform: MetaTrader 5 / MQL5 Buy when the MACD main line crosses above the signal line Sell when the MACD main line crosses below the signal line Use completed candles only MACD parameters configurable Fixed lot size configurable Stop Loss configurable Take Profit configurable Maximum one open position per symbol Configurable Magic
I need a simple MT5 Expert Advisor based on Bollinger Bands. Requirements: Platform: MetaTrader 5 / MQL5 Buy when price closes below the lower Bollinger Band Sell when price closes above the upper Bollinger Band Bollinger period configurable, default 20 Deviation configurable, default 2.0 Fixed lot size configurable Stop Loss configurable Take Profit configurable Maximum one open position per symbol Use completed
Platform: MT5 / MQL5 Buy khi RSI < 30 Sell khi RSI > 70 RSI period configurable, default 14 Fixed lot configurable SL/TP configurable Max 1 position per symbol Completed candles only Configurable Magic Number Deliver .mq5 source Compile without errors/warnings No martingale/grid No profitability guarantee
Trading bot ea 30+ USD
yoo i want to make a trading bot i have my strategy in videos and also the rules to if anyone can work it out for me i will be glad welcome your bid and it urget let connect here on mgl5 And if you know you can not do the project without getting paid first please don't bid thanks

项目信息

预算
40+ USD
截止日期
到 1 天