what do I need to add to make this trailing stop work?

 
//+------------------------------------------------------------------+
//|                                                trailing_stop.mq5 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
    double trailingStopDistance = 50; // trailing stop distance in points
    double currentPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); // current market price
    double trailingStopPrice;

    // iterate over all open orders
    for (int i = 0; i < OrdersTotal(); i++)
    {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
            // check if the order is a buy or sell order
            if (OrderType() == OP_BUY)
            {
                // calculate the trailing stop price for buy order
                trailingStopPrice = currentPrice - trailingStopDistance * _Point;

                // check if the order has a stop loss
                if (OrderStopLoss() > 0)
                {
                    // check if the current stop loss is below the trailing stop
                    if (OrderStopLoss() < trailingStopPrice)
                    {
                        // modify the order's stop loss level with the new trailing stop price
                        OrderModify(OrderTicket(), OrderOpenPrice(), trailingStopPrice, OrderTakeProfit(), 0, 0, 0, NULL, 0);
                    }
                }
                else
                {
                    // add a new stop loss at the trailing stop price
                    OrderModify(OrderTicket(), OrderOpenPrice(), trailingStopPrice, OrderTakeProfit(), 0, 0, 0, NULL, 0);
                }
            }
            else if (OrderType() == OP_SELL)
            {
                // calculate the trailing stop price for sell order
                trailingStopPrice = currentPrice + trailingStopDistance * _Point;

                // check if the order has a stop loss
                if (OrderStopLoss() > 0)
                {
                    // check if the current stop loss is above the trailing stop
                    if (OrderStopLoss() > trailingStopPrice)
                    {
                        // modify the order's stop loss level with the new trailing stop price
                        OrderModify(OrderTicket(), OrderOpenPrice(), trailingStopPrice, OrderTakeProfit(), 0, 0, 0, NULL, 0);
                    }
                }
                else
                {
                    // add a new stop loss at the trailing stop price
                    OrderModify(OrderTicket(), OrderOpenPrice(), trailingStopPrice, OrderTakeProfit(), 0, 0, 0, NULL, 0);
                }
            }
        }
    }
}
 
When you calculate trailingStopPrice you need to use NormalizeDouble(your equation,_Digits) 
Do that for both. 

Also bonus tip add input in front of double trailingStopDistance This lets you select different trails 
 

Even here Google would have told you:

https://www.mql5.com/en/articles/134
https://www.mql5.com/en/articles/1527
https://www.mql5.com/en/articles/2411

Bear in mind there's virtually nothing that hasn't already been programmed for MT4/MT5 and is ready for you!

 
  1. //|                                                trailing_stop.mq5 |                                <<<<<<< MT5?
    
    if (OrderType() == OP_BUY)                                                                            <<<<<<< MT4
    
    OrderModify(OrderTicket(), OrderOpenPrice(), trailingStopPrice, OrderTakeProfit(), 0, 0, 0, NULL, 0); <<<<<<< MT4

    Not MT5 code. Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.


  2.     double currentPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); // current market price
    
                else if (OrderType() == OP_SELL)
                {
                    trailingStopPrice = currentPrice + trailingStopDistance * _Point;

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)

      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
      My GBPJPY shows average spread = 26 points, average maximum spread = 134.
      My EURCHF shows average spread = 18 points, average maximum spread = 106.
      (your broker will be similar).
                Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)

  3.     // iterate over all open orders
        for (int i = 0; i < OrdersTotal(); i++)
        {
            if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

    In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading), while you are waiting for the current operation (closing, deleting, modifying) to complete, any number of other operations on other orders could have concurrently happened and changed the position indexing and order count:

    1. For non-FIFO (non-US brokers), (or the EA only opens one order per symbol), you can simply count down, in an index loop, and you won't miss orders. Get in the habit of always counting down.
                Loops and Closing or Deleting Orders - MQL4 programming forum

    2. For In First Out (FIFO rules — US brokers), and you (potentially) process multiple orders per symbol, you must find the earliest order (count up), close it, and on a successful operation, reprocess all positions (from zero).
                CloseOrders by FIFO Rules - Strategy Tester - MQL4 programming forum - Page 2 #16
                MetaTrader 5 platform beta build 2155: MQL5 scope, global Strategy Tester and built-in Virtual Hosting updates - Best Expert Advisors - General - MQL5 programming forum #1.11

    3. and check OrderSelect in case later positions were deleted.
                What are Function return values ? How do I use them ? - MQL4 programming forum
                Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

    4. and if you (potentially) process multiple orders, must call RefreshRates() after server calls if you want to use, on the next order / server call, the Predefined Variables (Bid/Ask.) Or instead, be direction independent and just use OrderClosePrice().

  4. Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number/symbol filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum (2013)
              PositionClose is not working - MQL5 programming forum (2020)
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles (2006)
              Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles (2011)
              Limit one open buy/sell position at a time - General - MQL5 programming forum (2022)

    You need one Magic Number for each symbol/timeframe/strategy.
         Trade current timeframe, one strategy, and filter by symbol requires one MN.
         If trading multiple timeframes, and filter by symbol requires use a range of MN (base plus timeframe).
              Why are MT5 ENUM_TIMEFRAMES strange? - General - MQL5 programming forum - Page 2 #11 (2020)