Strange Issue .TP is set below Buy order price , and Above for Sell Orders

 

Hello There ;

I've developed an EA to one client when he sent me yesterday night very strange screenshot. The problem as the trading history shows "Live" , there were orders which had invalid take profit level " The TP was lower than order price for buy and the TP was Higher than open for sell" . This doesn't make any sense. I know that it's impossible to set invalid tp or so level and the order gets executed rather it will generate error i think 4050 INVALID STOPS. Though in my code i already handled this error to prevent usage of invalid stop level if the user inputs the wrong parameter, i don't know how did this happen. For the first time, I see invalid TP levels get executed and MT doesn't prevent it from sending. Could it be a problem in the code or which it could possibly be?


 

Just for illustration, suppose a buy order was open at price 10, when the current ask price is at 2, i can validly set a take profit price of 6, right?. Vice versa for sell orders.

 
Seng Joo Thio:

Just for illustration, suppose a buy order was open at price 10, when the current ask price is at 2, i can validly set a take profit price of 6, right?. Vice versa for sell orders.

Hi ;

Market orders are opened at market price (Ask for Buy , Bid for Sell) . if the order open price is 10 you can't set TP to 6 beucase  the TP level will be lower than order open price , but this can work for pending orders . The issue here is that all orders are market orders and the TP & SL are calculated relative to the order open price . What I don't understand if in the code I set the Take profit = Ask + TP pips and for sell orders I set the TP to be Bid - TP pips 

So how comes the TP becomes lower for Buy order and higher for Sell orders , what makes things more weird is how did MT accept such order and didn'r generate INVALID STOP Error ?

int type=Close[1]>Open[1]?OP_BUY : OP_SELL ;
double sl=StopLoss*pip<=0 || StopLoss*pip<MarketInfo(Symbol(),MODE_STOPLEVEL) ?0:StopLoss*pip ;
double tp=TakeProfit*pip<=0 || TakeProfit*pip<MarketInfo(Symbol(),MODE_STOPLEVEL)?0: TakeProfit*pip ;
double lot=lotSize ;
double price=type==OP_BUY?Ask:Bid ;



 double stoploss=sl>0?(type==OP_BUY?NormalizeDouble(price-sl*Point,Digits):NormalizeDouble(price+sl*Point,Digits)):0 ;
 double takeprofit=tp>0?(type==OP_BUY?NormalizeDouble(price+tp*Point,Digits):NormalizeDouble(price-tp*Point,Digits)):0 ;

          int tkt=OrderSend(Symbol(),type,lot,price,3*pip,stoploss,takeprofit,"First Order",Magic,0 ,clrNONE) ;


as you see in the snippet of code above . if I set the  stoploss & takeprofit prices relates to ASK or Bid how comes they became like that . is there anything wrong here

 

I'm with you in that at the point of OrderSend, MT will not accept TP lower than Open Price, and SL higher than Open Price, for Buy Positions, and vice versa for Sell Positions.

However, my point in my earlier post is that IF there were new requests to reset SL and TP some time AFTER the initial OrderSend, there is no issue at all, and MT WILL accept such modifications (possible scenario as illustrated in my earlier post).

So in order to debug this problem, we need to see your entire code in order to rule out any possibility of it modifying the orders after the initial send. And you need to convince us whether your client manually change the values or not... LOL.

 
Seng Joo Thio:

I'm with you in that at the point of OrderSend, MT will not accept TP lower than Open Price, and SL higher than Open Price, for Buy Positions, and vice versa for Sell Positions.

However, my point in my earlier post is that IF there were new requests to reset SL and TP some time AFTER the initial OrderSend, there is no issue at all, and MT WILL accept such modifications (possible scenario as illustrated in my earlier post).

So in order to debug this problem, we need to see your entire code in order to rule out any possibility of it modifying the orders after the initial send. And you need to convince us whether your client manually change the values or not... LOL.

LOL :) , I don't think the client has changed it . I know that after the order is opened the SL  or the TP can be changed something like how  the  trailing stop … But in this EA orders are not modified at all after they have been opened we don't even use the OrderModify() function .

i'm here infront of 2 things " either the client had manually modified the stop loss  either by him self or by some sort of another EA that interfere with this one"  , Or what I believe in more is Broker slippage or spread . what makes me think in that when looking at these orders they are all opened almost at the same time 00:00 AM , this time is the Killer of accounts time  :) Do you think I\m corrent in that 

 
Karim Abdelhakim:

LOL :) , I don't think the client has changed it . I know that after the order is opened the SL  or the TP can be changed something like how  the  trailing stop … But in this EA orders are not modified at all after they have been opened we don't even use the OrderModify() function .

i'm here infront of 2 things " either the client had manually modified the stop loss  either by him self or by some sort of another EA that interfere with this one"  , Or what I believe in more is Broker slippage or spread . what makes me think in that when looking at these orders they are all opened almost at the same time 00:00 AM , this time is the Killer of accounts time  :) Do you think I\m corrent in that 

The order were closed at exact TP prices, no slippage. Spread has nothing to do here.

There is no doubt the TP was modified by the user (or eventually other EA). Don't lost your time.

 
Alain Verleyen:

The order were closed at exact TP prices, no slippage. Spread has nothing to do here.

There is no doubt the TP was modified by the user (or eventually other EA). Don't lost your time.

This what I'm trying to tell him that it's not a problem in the code , as it's impossible for TP or SL to be set like that at invalid levels   yet the MT accepts them and doesn't generate error even if I'm wrong and knows nothing about programming MT wouldn't allow me to do so .

What makes this also doesn't make any sense if you look at order open time and order close time you will notice that they lasted at least 1 Minute and one closed after 20 Minutes so if the TP levels had been like that from the very first beginning all orders would have been closed immediately because the TP level would have been reached . So you are correct , it seemd that something outside of the EA changed its TP Levels . 

The Problem now is that I tried to send him messages he doesn't respond and I put the EA on test for 2 days to see what is going on but nothing seemed strange , I even offered him a refund if there is problem in my code hopefully he sees this post , anyways thanks for help

 
Karim Abdelhakim:

This what I'm trying to tell him that it's not a problem in the code , as it's impossible for TP or SL to be set like that at invalid levels   yet the MT accepts them and doesn't generate error even if I'm wrong and knows nothing about programming MT wouldn't allow me to do so .

What makes this also doesn't make any sense if you look at order open time and order close time you will notice that they lasted at least 1 Minute and one closed after 20 Minutes so if the TP levels had been like that from the very first beginning all orders would have been closed immediately because the TP level would have been reached . So you are correct , it seemd that something outside of the EA changed its TP Levels . 

The Problem now is that I tried to send him messages he doesn't respond and I put the EA on test for 2 days to see what is going on but nothing seemed strange , I even offered him a refund if there is problem in my code hopefully he sees this post , anyways thanks for help

You need to check the logs, you will see the SL/TP changes there and also the initial SL/TP. It can be checked there that it's not your EA that modified the SL/TP.

The customer needs to understand, so explain him. If it's a job through freelance service, and you have to go to arbitration (hopefully not), you will win without any doubt.

 
Alain Verleyen:

You need to check the logs, you will see the SL/TP changes there and also the initial SL/TP. It can be checked there that it's not your EA that modified the SL/TP.

The customer needs to understand, so explain him. If it's a job through freelance service, and you have to go to arbitration (hopefully not), you will win without any doubt.

The job had already been closed a week ago , and already received good feedback , he just sent me this screen shot 2 days a go  and he said he found these issues . So as my  ethical responsibility to check what is going on if there is anything wrong and will fix it , but I tried to explain to him many times that it's not a problem in the code but he doesn't' want to believe , I finally even offered to give him a refund to his direct account because the job has already been closed so he can't open arbitration