Invalid TP/SL

 

I'm trying to understand error I recently started to receive that causes my EA to stop.
The EA works perfectly but once in few days i get error "Invalid TP/SL".

I've checked my EA TP and SL and as you can see there is no SL but only TP.
After checking and verifying that, I've found that the EA attempted to open with a tp at the same point as open price which explains the error 
but I couldn't find any reason for that error to happen from the code.

// Global variables
int Take_Profit = 40;
.
.
.
.
.
.
void OnTick(){
.
.
.
        orderSend = OrderSend(Symbol(),OP_BUY,0.01,Ask,1,0,Ask+Take_Profit*_Point,"comment",12345,0,Red);
}

This is my only OrderSend so it has to come from here.
If any of you know what's wrong with that and can help it would be much appriciated.
Thanks alot in advance for any help.

 
Niv Cohen: I'm trying to understand error I recently started to receive that causes my EA to stop. The EA works perfectly but once in few days i get error "Invalid TP/SL". I've checked my EA TP and SL and as you can see there is no SL but only TP. After checking and verifying that, I've found that the EA attempted to open with a tp at the same point as open price which explains the error but I couldn't find any reason for that error to happen from the code. This is my only OrderSend so it has to come from here. If any of you know what's wrong with that and can help it would be much appriciated.

Invalid stops do not cause an EA to exit. It only causes the order to not be placed. If it is stopping/exiting your EA then it is your code logic that is causing that.

When placing stops, you must check that they follow the broker's contract rules, such as the Stops Level and Freeze Level. Please read the following:

You should also check that the values of the stops are aligned to the allowed price tick size.

Forum on trading, automated trading systems and testing trading strategies

How To Manage 0.5 or 0.05 Price Steps (Tick Value, Tick Size) in order to avoid Error 130

Fernando Carreiro, 2018.01.04 12:13


You must NOT use NormalizeDouble(). You must use the Tick-Size to correctly set the price values. This has been discussed on the forum many times, so do a search but the most common post you will see goes something like this ...


In essence, make sure that your price quotes, are properly aligned to the Tick size (see following examples).

...
double tickSize = SymbolInfoDouble( _Symbol, SYMBOL_TRADE_TICK_SIZE );
...
double normalised_price = round( price / tick_size ) * tick_size;
...
// Or use a function
double Round2Ticksize( double price )
{
   double tick_size = SymbolInfoDouble( _Symbol, SYMBOL_TRADE_TICK_SIZE );
   return( round( price / tick_size ) * tick_size );
}


You may also benefit from reading this: https://www.mql5.com/en/forum/223705#comment_6279080



    Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
    Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
    • book.mql4.com
    Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
     
    Fernando Carreiro #:

    Invalid stops do not cause an EA to exit. It only causes the order to not be placed. If it is stopping/exiting your EA then it is your code logic that is causing that.

    When placing stops, you must check that they follow the broker's contract rules, such as the Stops Level and Freeze Level. Please read the following:

    Thank you very much Fernando for your quick reply.

    I've check it and the problem isn't related to limitation. 

    The problem is that the order send is sending an order with T.P exactly as the open price, for an example:

    Open trade: 1.13649 , S.l: 0.00 , T.P: 1.13649
    Becaues the TP and Open trade price are the same the error is caused

    That's why I've shared the ordersend code only because it sends the order and I wonder why it is attempting to set the T.P like the Open trade price
    since there is Ask+Take_Profit*_Point.
    What makes it weird is that the EA works perfectly fine and take trades with no problem but once in few days it gets this error and stops. 
    Backtesting doesn't show the error aswell.

    Moreover, I've already tried the Round2Ticksize solution before posting this thread and it wan't the fix of the error because I just got the error today after adding the Round2Ticksize.
     
    Niv Cohen #:

    Thank you very much Fernando for your quick reply.

    I've check it and the problem isn't related to limitation. 

    The problem is that the order send is sending an order with T.P exactly as the open price, for an example:

    Open trade: 1.13649 , S.l: 0.00 , T.P: 1.13649
    Becaues the TP and Open trade price are the same the error is caused

    That's why I've shared the ordersend code only because it sends the order and I wonder why it is attempting to set the T.P like the Open trade price
    since there is Ask+Take_Profit*_Point.
    What makes it weird is that the EA works perfectly fine and take trades with no problem but once in few days it gets this error and stops. 
    Backtesting doesn't show the error aswell.

    Moreover, I've already tried the Round2Ticksize solution before posting this thread and it wan't the fix of the error because I just got the error today after adding the Round2Ticksize.

    Then the code you are using is not the same as the one you presented here, and the calculation for the T/P is different or incorrect or the variable "Take_Profit" is being set to 0 somewhere in your full code.

    Since you did not provide your full code, then you will have to debug it and find the bug on your own.