Trade Up With Trailing Gap

 

Hello,


I want to trade up (add to position) with a trailing gap after a certain amount of pips but only ONE trade up order as the trade up distance is reached.
E.g.

place buy order - first order
at +50 pips trade up trailing with trailing gap - new trade up order (the EA currently places multiple trade up orders at each trade up level, it should place only one order per trade up level).
at +100 pips trade up traing with trailing gap - another new trade up order (again, the EA does not just open one extra order at the trade up point, it sometimes opens 2,3,4 or more per level).

The problem is that the trade up trailing block will open more than one trade as the distance is reached, I only want it to open one at the trading up distance.

void TradeUpTrailing()
{
    double lots = 0;
    double takeprofit = 0, stoploss = 0;
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        if (OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
        {
            if (OrderType() == OP_BUY && Ask - OrderOpenPrice() > TradeUpPoint*PipValue*Point && (OrderStopLoss() < Ask-(TradeUpPoint+TrailingGap)*PipValue*Point))
            {
                stoploss = Ask-TrailingGap*PipValue*Point;
                takeprofit = Ask+NewTakeProfit*PipValue*Point;
                if (NewTakeProfit == 0) takeprofit = OrderTakeProfit();
                bool ret1 = OrderModify(OrderTicket(), OrderOpenPrice(), stoploss, takeprofit, OrderExpiration(), White);
                if (ret1 == false)
                Print("OrderClose() error - ", ErrorDescription(GetLastError()));
                else
                {
                    int ticket = -1;
                    if (true)
                    ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 4, 0, 0, "My Expert", 1, 0, White);
                    else
                    ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 4, stoploss, takeprofit, "My Expert", 1, 0, White);
                    if (ticket > -1)
                    {
                        if (true)
                        {
                            OrderSelect(ticket, SELECT_BY_TICKET);
                            bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), stoploss, takeprofit, 0, White);
                            if (ret == false)
                            Print("OrderModify() error - ", ErrorDescription(GetLastError()));
                        }
                        
                    }
                }
                
            }
            if (OrderType() == OP_SELL && OrderOpenPrice() - Bid > TradeUpPoint*PipValue*Point && (OrderStopLoss() > Bid+(TradeUpPoint+TrailingGap)*PipValue*Point))
            {
                stoploss = Bid+TrailingGap*PipValue*Point;
                takeprofit = Bid-NewTakeProfit*PipValue*Point;
                if (NewTakeProfit == 0) takeprofit = OrderTakeProfit();
                bool ret2 = OrderModify(OrderTicket(), OrderOpenPrice(), stoploss, takeprofit, OrderExpiration(), White);
                if (ret2 == false)
                Print("OrderModify() error - ", ErrorDescription(GetLastError()));
                else
                {
                    int ticket2 = -1;
                    if (true)
                    ticket2 = OrderSend(Symbol(), OP_SELL, Lots, Bid, 4, 0, 0, "My Expert", 1, 0, White);
                    else
                    ticket2 = OrderSend(Symbol(), OP_SELL, Lots, Bid, 4, stoploss, takeprofit, "My Expert", 1, 0, White);
                    if (ticket2 > -1)
                    {
                        if (true)
                        {
                            OrderSelect(ticket2, SELECT_BY_TICKET);
                            bool ret4 = OrderModify(OrderTicket(), OrderOpenPrice(), stoploss, takeprofit, 0, White);
                            if (ret4 == false)
                            Print("OrderModify() error - ", ErrorDescription(GetLastError()));
                        }
                        
                    }
                }
                
            }
            
        }
    }
    else
    Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    
}
 
gangsta1:

Hello,


I want to trade up (add to position) with a trailing gap after a certain amount of pips but only ONE trade up order as the trade up distance is reached.
E.g.

place buy order - first order
at +50 pips trade up trailing with trailing gap - new trade up order (the EA currently places multiple trade up orders at each trade up level, it should place only one order per trade up level).
at +100 pips trade up traing with trailing gap - another new trade up order (again, the EA does not just open one extra order at the trade up point, it sometimes opens 2,3,4 or more per level).

The problem is that the trade up trailing block will open more than one trade as the distance is reached, I only want it to open one at the trading up distance.



what a terrible code, to me it looks like you don't know what's gonna happen if you run it....

Is there a need for changing the takeprofitlevel with your trailing ??  and if so why do you change it then ?? 

your code.....

                bool ret1 = OrderModify(OrderTicket(), OrderOpenPrice(), stoploss, takeprofit, OrderExpiration(), White);
                if (ret1 == false)
                Print("OrderClose() error - ", ErrorDescription(GetLastError()));

Is this trying closing ???    if not why do you print message  "OrderClose() error -  'Errnumber' "

------

You are checking the open trades and inside this loop you try to open new trades  .......     just can't believe you know what you do

also the way how you try to open first without stopsetting and then a line with it  and then modifying it not knowing if it has already stopsettings

Really ,really , really this makes me dizzy

Explain me how can this be good ???? 

Reason: