Why does the trailing stop function not work properly in the following MQL4 CODE? Can anyone please help me to fix it?

 
When I want the effect: It starts when the profit reaches an increase of 300 points. If you hold a BUY order now, and every time the price rises by 100 points compared to the entry price, adjust the position of SL to SL+100 points. If you hold a SELL order now, and every time the price drops by 100 points compared to the entry price, adjust the SL position to SL-100 points.


extern bool checkHLOrder = true; 

extern bool useFixedSL = true; 
extern double fixedSL = 300.0; 



void OnTick()
{
Check_Trailing();
Check_OpenOrder();
}



void Check_Trailing()
{
    int orders = OrdersTotal();
    for(int i = 0; i < orders; i++)
    {
        if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
            
            if(OrderSymbol() != Symbol())
                continue;
            
            double currentPrice = MarketInfo(Symbol(), MODE_BID);
            double openPrice = OrderOpenPrice();
            double profit = OrderProfit();
            double stopLoss = OrderStopLoss();
            double trailingStop = 0;
            
            
            if(OrderType() == OP_BUY)
            {
                if(profit >= 300)
                {
                    int pointMove = (int) ((currentPrice - openPrice) / Point);
                    if(pointMove > 0)
                    {
                        int trailingStopMove = (int) (pointMove / 100) * 100;
                        trailingStop = openPrice + trailingStopMove * Point;
                        
                        if(trailingStop > stopLoss || stopLoss == 0)
                        {
                            
                            if(OrderModify(OrderTicket(), OrderOpenPrice(), trailingStop, OrderTakeProfit(), 0, Green))
                            {
                                
                                Print("Trailing stop for order ", OrderTicket(), " has been modified to ", trailingStop);
                            }
                            else
                            {
                                
                                Print("Failed to modify trailing stop for order ", OrderTicket(), " Error code: ", GetLastError());
                            }
                        }
                    }
                }
            }
            
            else if(OrderType() == OP_SELL)
            {
                if(profit >= 300)
                {
                    int pointMove2 = (int) ((openPrice - currentPrice) / Point);
                    if(pointMove2 > 0)
                    {
                        int trailingStopMove2 = (int) (pointMove2 / 100) * 100;
                        trailingStop = openPrice - trailingStopMove2 * Point;
                        
                        if(trailingStop < stopLoss || stopLoss == 0)
                        {
                            
                            if(OrderModify(OrderTicket(), OrderOpenPrice(), trailingStop, OrderTakeProfit(), 0, Red))
                            {
                                
                                Print("Trailing stop for order ", OrderTicket(), " has been modified to ", trailingStop);
                            }
                            else
                            {
                                
                                Print("Failed to modify trailing stop for order ", OrderTicket(), " Error code: ", GetLastError());
                            }
                        }
                    }
                }
            }
        }
    }
}

void Check_OpenOrder()
{
    static datetime lastBarTime = 0;
    datetime currentBarTime = iTime(Symbol(), PERIOD_CURRENT, 0);

    if (IsPositionOpen() || !IsNewBar(lastBarTime, currentBarTime))
    {
        return; 
    }

    lastBarTime = currentBarTime;

    if (checkHLOrder == true) 
    {
        double currentPrice = Ask;
        double lastHigh = High[1];
        double lastLow = Low[1];
        if (Low[0] > lastHigh || High[0] < lastLow)
        {
            Print("Current price is not within last bar's H and L. Order not placed.");
            return;
        }
    }

    int ticket;
    double buyStopPrice = High[3];
    double sellStopPrice = Low[3];
    double stopLoss;
    double takeProfit = 3000;
    double lotSize = 0.1;
    int magicNumber = 123;

    
    for (int i = OrdersTotal() - 1; i >= 0; i--)
    {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
            if (OrderSymbol() == Symbol() && (OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP))
            {
                if (!OrderDelete(OrderTicket()))
                {
                    Print("Error deleting order: ", GetLastError());
                }
            }
        }
    }

    
    if (useFixedSL == true)
    {
        stopLoss = fixedSL;
    }
    else
    {
        double jpyMultiplier = 1;
        if (StringFind(Symbol(), "JPY") >= 0) 
        {
            jpyMultiplier = 1000;
        }
        else
        {
            jpyMultiplier = 100000;
        }
        stopLoss = (High[1] - Low[1]) * 2 * jpyMultiplier;
        
    }


ticket = OrderSend(Symbol(), OP_BUYSTOP, lotSize, buyStopPrice, 10, buyStopPrice - stopLoss * Point, buyStopPrice + takeProfit * Point, "Buy Stop Order", magicNumber, 0, Blue);
if (ticket == -1)
{
    Print("Error opening buy stop order: ", GetLastError());
}

ticket = OrderSend(Symbol(), OP_SELLSTOP, lotSize, sellStopPrice, 10, sellStopPrice + stopLoss * Point, sellStopPrice - takeProfit * Point, "Sell Stop Order", magicNumber, 0, Red);
if (ticket == -1)
{
    Print("Error opening sell stop order: ", GetLastError());
}

}


bool IsPositionOpen()
{
    int total = OrdersTotal();
    for (int i = 0; i < total; i++)
    {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
            if (OrderSymbol() == Symbol() && (OrderType() == OP_BUY || OrderType() == OP_SELL))
            {
                return true;
            }
        }
    }
    return false;
}


bool IsNewBar(datetime lastBarTime, datetime currentBarTime)
{
static int waitTime = 10; 
if (lastBarTime != currentBarTime)
{
if (TimeCurrent() - currentBarTime >= waitTime)
{
return true;
}
}
return false;
}
 
hahago:

OrderProfit() is a currency(e.g. USD) value... Not point value.

Reason: