Problem with trailing stop when activating

 

Hi,

my trailing stop is activated when reach 1/2 stop loss or profit.

Trailing stop skače between 2-3 pips.


Code:



void tStop(string symb, int stop, int MN)// Symbol + stop in pips + magic number
{
    double bsl = NormalizeDouble(MarketInfo(symb, MODE_BID) - stop * MarketInfo(symb, MODE_POINT), MarketInfo(symb, MODE_DIGITS));
    double ssl = NormalizeDouble(MarketInfo(symb, MODE_ASK) + stop * MarketInfo(symb, MODE_POINT), MarketInfo(symb, MODE_DIGITS));

    for (int i = OrdersTotal() - 1; i >= 0; i--)
    {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
            if (OrderMagicNumber() == MN)
                if (OrderSymbol() == symb)

                    if (OrderType() == OP_BUY && (OrderStopLoss() < bsl))
                        if (OrderModify(OrderTicket(), OrderOpenPrice(), bsl, OrderTakeProfit(), 0, clrNONE))
                        {
                            Print(symb + " Buy's Stop Trailled to " + (string)bsl);
                        }
                        else
                        {
                            Print(symb + " Buy's Stop Trail ERROR");
                        }

        if (OrderType() == OP_SELL && (OrderStopLoss() > ssl || OrderStopLoss() == 0))
            if (OrderModify(OrderTicket(), OrderOpenPrice(), ssl, OrderTakeProfit(), 0, clrNONE))
            {
                Print(symb + " Sell's Stop Trailled to " + (string)ssl);
            }
            else
            {
                Print(symb + " Sell's Stop Trail ERROR");
            }
    }
}


Activation onTimer:

if (profitOrder > get1_2_TP)
    {  // Print("profitOrder:"+get1_2_TP);
       
        if (AllowTrailing == true)
        {
            pipsTrail = DiffPips / 2;
            tStop(_Symbol, pipsTrail, MagicNumber);

            Print("Trailing stop:" + _Symbol);
        }

In got also Error:

 AUDUSD,H1: AUDUSD Sell's Stop Trail ERROR


Thanks

 
chris.dotan AUDUSD,H1: AUDUSD Sell's Stop Trail ERROR

On your buy orders you filter by symbol and magic number. On your sell orders you don't.