Hidden TS only works on 1 chart and not on all open charts.

 

Hi,  need a little help.

I have tried so many options, but just can't seem to get this working properly.


I created a hidden trailing stop, which works fine if I only have one chart open, but when I have two charts open, it only seems to produce the TS on one chart.

I'm hoping that other eyes can see what I am doing wrong.


I have the Symbols checking and I have the Totals configured with symbols in mind as well.

 if((HiddenTrailingStop)&& OrderSymbol() == Symbol())
      {
         if(DoubleToString(SellProfit()+BuyProfit(),2)>(TrigSLProfit))  { TrigSL=HiddenTrailingStoppointsProfit;} // TrigSLProfit is the profit % that is calculated above
            else { TrigSL=HiddenTrailingStoppoints;}
       int buyCount = 0, sellCount = 0;
         for(int i = OrdersTotal() - 1; i >= 0; i--)
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
               if(IsValidOrder())
                   {
                     if(OrderType() == OP_BUY)
                        {  buyCount++;  }
                    else
                         if(OrderType() == OP_SELL)
                        { sellCount++;    }
                   }

     // No Trades
     
    if((buyCount==0) && (sellCount==0))   {TrigSLHold==0;}
     //---    BUYs
    if((buyCount > 0)&& OrderSymbol() == Symbol())
         {double CurrentHold=NormalizeDouble(Bid - TrigSL * _point, Digits);
          if(TrigSLHold==0)                              {TrigSLHold=CurrentHold;}
          else 
            {if(CurrentHold > TrigSLHold)               TrigSLHold=CurrentHold;}
    // Close Trigger hit
         if(NormalizeDouble(Bid, Digits)<TrigSLHold)
         { EA_Comment =" HTL"; send_alert("HTL Buy TrigSLHold "+Symbol()+" "+TrigSLHold); TrigSLHold=0;CloseAllBuyOpenPositions(MaxSlippage);OpenTradesallowed=0;profitcount=profitcount+1;}
         }
 
//--- SELLs

    if((sellCount > 0)&&  OrderSymbol() == Symbol())
         {double CurrentHold=NormalizeDouble(Ask + TrigSL * _point, Digits);
          if(TrigSLHold==0)              {TrigSLHold=CurrentHold;}
          else 
            {if(CurrentHold < TrigSLHold)              TrigSLHold=CurrentHold; }
         // Close Trigger Hit
          if(NormalizeDouble(Ask, Digits)>TrigSLHold)
              {EA_Comment =" HTL"; send_alert("HTL Sell TrigSLHold "+Symbol()+" "+TrigSLHold);TrigSLHold=0;  CloseAllSellOpenPositions(MaxSlippage);}

          }  

    }
 
Kristina Suh it only seems to produce the TS on one chart.
  1. Your code uses Ask and Bid. Those are only the current chart. It only runs on the current chart. Put it on the other chart also.
  2.          for(int i = OrdersTotal() - 1; i >= 0; i--)
             if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
                   if(IsValidOrder())
                       {
                         if(OrderType() == OP_BUY)
                            {  buyCount++;  }
                        else
                             if(OrderType() == OP_SELL)
                            { sellCount++;    }

    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.02.21)
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles (2006)
              Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles (1 February 2011)

    You need one Magic Number for each symbol/timeframe/strategy. Trade current timeframe, one strategy, and filter by symbol requires one MN.