Invalid Stops MQL5 / - TP

 

Hi All,

I have an issue with sending orders, due to 

2018.10.22 23:53:13.079 Core 1 2017.03.15 19:00:00   failed modify #2 sell 0.03 EURUSD sl: 0.00000, tp: 0.00000 -> sl: 0.01000, tp: -0.01000 [Invalid stops]

this kind of error. I believe all stops are normalized, adapted for stoplevel and i think are ok. I also tried 2 versions - with setting the tp and sl in the ordersend, and by modifying the order later, none work.

This is my code, this all feels strange, considering the SL and TP are calculated rigth, i hope you can find something i didnt notice.

double stoplevel=SymbolInfoInteger(Symbol(),SYMBOL_TRADE_STOPS_LEVEL)*point;    

     int pts = 0;
     if(SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN)==0.01)pts=2;
     if(SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN)==0.1)pts=1;
      double tp=0,sl=0,Lots;
      if(CashSize==0)Lots=LotSize;
      else 
       Lots = NormalizeDouble((AccountInfoDouble(ACCOUNT_BALANCE)/CashSize)*LotSize,pts);

      if(direction==0)
        {
         if(TakeProfit>0)
         {
          tp=NormalizeDouble((Bid+TakeProfit*point),_Digits);
          if(TakeProfit*point<stoplevel)tp=NormalizeDouble((Bid+stoplevel),_Digits);
         }else{tp=0;}
         
         if(StopLoss>0) 
         {
          sl=NormalizeDouble(Bid-StopLoss*point,_Digits);
          if(StopLoss*point<stoplevel)sl=NormalizeDouble((Bid-stoplevel),_Digits);
         }
        bool buyop = ExtTrade.PositionOpen(_Symbol,ORDER_TYPE_BUY,Lots,SymbolInfoDouble(_Symbol,SYMBOL_ASK),0,0,"BB EA");
        if(buyop) 
         {
          traded=true;
            if(ExtTrade.PositionModify(_Symbol,sl,tp))
               {Print("Order  was successfully modified.");}
         else Print("Order was NOT successfully modified.",GetLastError());
         }
        }

      if(direction==1)
        {
         if(TakeProfit>0)
         {
          tp=NormalizeDouble((Ask-TakeProfit*point),_Digits);
          if(TakeProfit*point<stoplevel)tp=NormalizeDouble((Ask-stoplevel),_Digits);
         }else{tp=0;}
         if(StopLoss>0) 
         {
          sl=NormalizeDouble((Ask+StopLoss*point),_Digits);
          if(StopLoss*point<stoplevel)sl=NormalizeDouble((Ask+stoplevel),_Digits);
         }
        bool sellop = ExtTrade.PositionOpen(_Symbol,ORDER_TYPE_SELL,Lots,SymbolInfoDouble(_Symbol,SYMBOL_BID),0,0,"BB EA");
        if(sellop)
        {
         traded=true;
            if(ExtTrade.PositionModify(_Symbol,sl,tp))
               {Print("Order  was successfully modified.");}
         else Print("Order was NOT successfully modified.",GetLastError());
         
        }
        }


 

it may  be from the Bid/Ask calculation

if i used MQLTick there is no problem with the stops, but then i doesnt open sell trades, the  Bid i think does not quite work. When i used CSymbol to determine bid/ask, sell worked but the problems with the stops started. If i use SymbolInfoDouble(_Symbol,SYMBOL_ASK) , no orders are opened. Very strange !

 
Stanislav Ivanov:

Hi All,

I have an issue with sending orders, due to 

2018.10.22 23:53:13.079 Core 1 2017.03.15 19:00:00   failed modify #2 sell 0.03 EURUSD sl: 0.00000, tp: 0.00000 -> sl: 0.01000, tp: -0.01000 [Invalid stops]

this kind of error. I believe all stops are normalized, adapted for stoplevel and i think are ok. I also tried 2 versions - with setting the tp and sl in the ordersend, and by modifying the order later, none work.

This is my code, this all feels strange, considering the SL and TP are calculated rigth, i hope you can find something i didnt notice.


Really ? A SL of 0.01 and a negative TP doesn't seem "calculated right".

What is Ask/Bid in mql5 ?

 
Alain Verleyen:

Really ? A SL of 0.01 and a negative TP doesn't seem "calculated right".

What is Ask/Bid in mql5 ?

what i meant is that they seemed right, but considering they dont work, they apparently are not

 

the TP and SL i have set to 100 pips, but i have no idea how can a negative TP be ?

Sorry but i am not that good in MQL5

 
Stanislav Ivanov:

the TP and SL i have set to 100 pips, but i have no idea how can a negative TP be ?

Sorry but i am not that good in MQL5

Because your Ask value is 0.

Forum on trading, automated trading systems and testing trading strategies

Invalid Stops MQL5 / - TP

Alain Verleyen, 2018.10.22 23:10

Really ? A SL of 0.01 and a negative TP doesn't seem "calculated right".

What is Ask/Bid in mql5 ?

Answer the question please.
 
Print() all the things.
 
Alain Verleyen:

Because your Ask value is 0.

Answer the question please.
The latest price, one used to buy, the other for sell
 
ok, i tested the Bid/Ask, when i use mqltick they work, the tp,sl are ok. When i use CSymbol Ask/Bid, they return 0.
 
Stanislav Ivanov:
ok, i tested the Bid/Ask, when i use mqltick they work, the tp,sl are ok. When i use CSymbol Ask/Bid, they return 0.

Try this:

double NormalizePrice(double price)
  {
   double m_tick_size=SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);
   return(NormalizeDouble(MathRound(price/m_tick_size)*m_tick_size,_Digits));
  }
 
Stanislav Ivanov:

it may  be from the Bid/Ask calculation

if i used MQLTick there is no problem with the stops, but then i doesnt open sell trades, the  Bid i think does not quite work. When i used CSymbol to determine bid/ask, sell worked but the problems with the stops started. If i use SymbolInfoDouble(_Symbol,SYMBOL_ASK) , no orders are opened. Very strange !



CPositionInfo  ExtPositionInfo;

ExtSymbolInfo.Name(Symbol());

PositionSelect(_Symbol);

May help.

Reason: