Trailing stop loss modifying positions on another symbols when expert is attached to multiple charts.

 
void Trail() {
    Print("Trail() called for symbol: ", _Symbol);  // Log the function call and current chart symbol
    int totalPositions = PositionsTotal();
    for (int i = 0; i < totalPositions; i++) {
        ulong ticket = PositionGetTicket(i);
        if (PositionSelectByTicket(ticket)) {
            string positionSymbol = PositionGetString(POSITION_SYMBOL); // Get the symbol of the position
            if (positionSymbol != _Symbol) {
                // Skip positions that do not match the current chart symbol
                continue;
            }

            double pointMultiplier = (StringFind(positionSymbol, "JPY") > -1) ? 0.01 : 0.0001;
            double priceOpen = PositionGetDouble(POSITION_PRICE_OPEN);
            double currentSL = PositionGetDouble(POSITION_SL);
            double newSL;
            double tp = PositionGetDouble(POSITION_TP);

            // Handle BUY positions
            if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) {
                if (bid - priceOpen > Trailtrigger * _Point) {
                    newSL = NormalizeDouble(bid - Traildistance * _Point, _Digits);
                    // Modify SL only if the new SL is better (higher) than the current SL
                    if (newSL > currentSL) {
                        Print("Attempting to modify BUY position SL from ", currentSL, " to ", newSL, " for symbol: ", positionSymbol);
                        if (!trade.PositionModify(ticket, newSL, tp)) {
                            Print("Failed to modify BUY position SL. Error: ", GetLastError(), " for symbol: ", positionSymbol);
                        } else {
                            Print("Successfully modified BUY position SL to ", newSL, " for symbol: ", positionSymbol);
                        }
                    }
                }
            }
            // Handle SELL positions
            else if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) {
                if (priceOpen - ask > Trailtrigger * _Point) {
                    newSL = NormalizeDouble(ask + Traildistance * _Point, _Digits);
                    // Modify SL only if the new SL is better (lower) than the current SL
                    if (newSL < currentSL) {
                        Print("Attempting to modify SELL position SL from ", currentSL, " to ", newSL, " for symbol: ", positionSymbol);
                        if (!trade.PositionModify(ticket, newSL, tp)) {
                            Print("Failed to modify SELL position SL. Error: ", GetLastError(), " for symbol: ", positionSymbol);
                        } else {
                            Print("Successfully modified SELL position SL to ", newSL, " for symbol: ", positionSymbol);
                        }
                    }
                }
            }
        } else {
            Print("Failed to select position by ticket: ", ticket);
        }
    }
}
I attached the expert to 3 charts. USD/CAD, CAD/JPY, USD/JPY. If I enable trailing stop loss on any JPY pair, the expert will grab any position open and try to modify the stop loss to that JPY pair price - my stoploss.
For example, any USD/CAD position will be CONSTANTLY, NON STOP, being attempted to get modified. Also, I'm not seeing any logs when this happens, just this error message every second the trailing stop loss is enabled:
"2024.06.06 11:32:33.444 Trades '1091281011': failed modify #114111858 buy 0.17 USDCAD sl: 1.36753, tp: 1.37553 -> sl: 113.84200, tp: 1.37553 [Invalid stops]"
"2024.06.06 11:32:33.444 MeanChange (CADJPY,M30) CTrade::OrderSend: modify position #114111858 USDCAD (sl: 113.84200, tp: 1.37553) [invalid stops]"

Is the error not in the trailing stop function? It's the only position.Modify statement in my entire code. 

Any help here would be greatly appreciated.
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
  • www.mql5.com
All requests to execute trade operations are sent as a structure of a trade request MqlTradeRequest using function OrderSend() . The function...
 
julian lagier: Any help here would be greatly appreciated.
  1. Bid and ask are not defined.
  2. You define but never use pointMultiplier.
 
William Roeder #:
  1. Bid and ask are not defined.
  2. You define but never use pointMultiplier.

I will address this and come back, thank you very very much!