why doesn't my program not update t/p and s/l levels?

 

Hi, I am new to this forum. I have just started to write my own EA.. I have the following codes..

            
            if (Close[1] < B1S1Avg)    // if previous close is below average price, then current price is nearer to sell level, so create a sell order to average up
            {   // Create sell order
                RefreshRates();
                if (Bid > (sPrice[1] + MathAbs(bPrice[1] - sPrice[1]) * fibLevel))
                {   // Create a sell at market order
                    sellTicket = OrderSend(Symbol(), OP_SELL, lotSize, 0, 0, 0, 0, "S2-1 bCount="+bCount+" sCount="+sCount, 0, 0, Green);
                    if (sellTicket > 0)
                    {
                        orderS = OrderSelect(sellTicket,SELECT_BY_TICKET);
                        sCount++;                             // S2
                        sPrice[sCount] = OrderOpenPrice();    // sPrice[2]
                        sTicket[sCount] = sellTicket;         // sTicket[2]
                        sellAvgPrice = (sPrice[1] + sPrice[2]) / 2;
                        orderM = OrderModify(sellTicket, OrderOpenPrice(), OrderStopLoss(), 2 * sellAvgPrice - bPrice[1] - (takeProfitPips + 30) * Point, 0, Green);
                         
                        // Adjust take profit and stop loss levels for other deals
                        orderS = OrderSelect(sTicket[1],SELECT_BY_TICKET);   // adjust S1 t/p level
                        orderM = OrderModify(sTicket[1], OrderOpenPrice(), OrderStopLoss(), 2 * sellAvgPrice - bPrice[1] - (takeProfitPips + 30) * Point, 0, Green);
                        
                        orderS = OrderSelect(bTicket[1],SELECT_BY_TICKET);    // adjust B1 s/l level
                        orderM = OrderModify(bTicket[1], OrderOpenPrice(), 2 * sellAvgPrice - bPrice[1] - (takeProfitPips + 20) * Point, OrderTakeProfit(), 0, Green);     
                        return;
                    }
                    
                }

the program is able to execute the position at OrderSend, but is not able to execute the OrderModify commands.. could someone help please?

Many Thanks

 
Please check journal tab. Every time the system executes a OrderModify you can see it there. It logs errors and you will find out the problem.
 
Jeffrey Chin:

Hi, I am new to this forum. I have just started to write my own EA.. I have the following codes..

the program is able to execute the position at OrderSend, but is not able to execute the OrderModify commands.. could someone help please?

Many Thanks

First you have to make sure you are entering the trade loop . I assume the code reaches that point.

Then you may have 2 problems :

1.You are trying to adjust the TP and SL at the same time , i've encountered a little broker that did not like that

2.You may be hitting the stop level limit (which is the minimum of how close your stops can be to the live price close price)

MarketInfo(_Symbol, MODE_STOPLEVEL);//this returns it in points if i recall 
//and
SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);

These will return the value in points so you will have to ((double)value)*_Point to get it in price