Download MetaTrader 5

Invalid Stops

To add comments, please log in or register
Gouveiaa
123
Gouveiaa  
2016.07.16 18:16:23.479 2016.07.14 23:59:00   failed market sell 0.02 EURUSD sl: 80.00000 tp: 50.00000 [Invalid stops]

Good afternoon!

I just finished to code my EA and I insert a fixed SL and TP, I stared with values like 20/25 and I tought the error was the small number, so I tried 80 and 50, as the example, but I get the same error, can someone help me?

Best regards 

Osama Shaban
1470
Osama Shaban  
You need to upload the code or at least the OrderSend( ) line and the SL & TP calculations to give you the right answer !.
Gouveiaa
123
Gouveiaa  
Osama Shaban:
You need to upload the code or at least the OrderSend( ) line and the SL & TP calculations to give you the right answer !.
bool LongPositionOpen()
{
   
   MqlTradeRequest mrequest;                             // Will be used for trade requests
   MqlTradeResult mresult;                               // Will be used for results of trade requests
   
   ZeroMemory(mrequest);
   ZeroMemory(mresult);
   
   double Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);    // Ask price
   double Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);    // Bid price
  
   if(!PositionSelect(_Symbol))
     {
      double buyStopLoss = BuyStopLoss(_Symbol ,StopLoss ,ORDER_PRICE_OPEN);
      if(buyStopLoss > 0) mrequest.sl = AdjustAboveStopLevel(_Symbol ,buyStopLoss);
     
      double buyTakeProfit = BuyTakeProfit(_Symbol ,TakeProfit ,ORDER_PRICE_OPEN);
      if(buyTakeProfit > 0) mrequest.tp = AdjustAboveStopLevel(_Symbol , buyTakeProfit);
      
      double stopLevel = SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL) * _Point;
      double minStopLevel = SymbolInfoDouble(_Symbol,SYMBOL_ASK) + stopLevel;
  
      mrequest.action = TRADE_ACTION_DEAL;               // Immediate order execution
      mrequest.price = NormalizeDouble(Ask,_Digits);     // Lastest Ask price
      mrequest.sl = StopLoss;                            // Stop Loss
      mrequest.tp = TakeProfit;                          // Take Profit
      mrequest.symbol = _Symbol;                         // Symbol
      mrequest.volume = Lot;                             // Number of lots to trade
      mrequest.magic = 0;                                // Magic Number
      mrequest.type = ORDER_TYPE_BUY;                    // Buy Order
      mrequest.type_filling = ORDER_FILLING_FOK;         // Order execution type
      mrequest.deviation=5;                              // Deviation from current price
      return(OrderSend(mrequest,mresult));               // Send order
     
     if(mrequest.price <= minStopLevel)
   {
      Print("Invalid Stop Price");
   }
    }
Here, for example
Frederic Metraux
513
Frederic Metraux  
double minStopLevel = SymbolInfoDouble(_Symbol,SYMBOL_ASK) - stopLevel;
Gouveiaa
123
Gouveiaa  
twalk:
Still the same error :/
Marco vd Heijden
Moderator
4753
Marco vd Heijden  
Gouveiaa:
Still the same error :/
      mrequest.sl = StopLoss;                            // Stop Loss
      mrequest.tp = TakeProfit;                          // Take Profit
Where are these calculated?
Gouveiaa
123
Gouveiaa  
Marco vd Heijden:
Where are these calculated?
I deleted, could you give me the right funtion to calculate those? Thank you
Mohammad Soubra
27436
Mohammad Soubra  

Very confused!!!

Something is hidden. 

seems you are using the code of MT5 in mt4 

... 

Siti Latifah
7002
Siti Latifah  
Mohammad Soubra:

Very confused!!!

Something is hidden. 

seems you are using the code of MT5 in mt4 

... 

you're right...


it is mql5 command

--

      mrequest.action = TRADE_ACTION_DEAL;               // Immediate order execution
      mrequest.price = NormalizeDouble(Ask,_Digits);     // Lastest Ask price
      mrequest.sl = StopLoss;                            // Stop Loss
      mrequest.tp = TakeProfit;                          // Take Profit
      mrequest.symbol = _Symbol;                         // Symbol
      mrequest.volume = Lot;                             // Number of lots to trade
      mrequest.magic = 0;                                // Magic Number
      mrequest.type = ORDER_TYPE_BUY;                    // Buy Order
      mrequest.type_filling = ORDER_FILLING_FOK;         // Order execution type
      mrequest.deviation=5;                              // Deviation from current price
      return(OrderSend(mrequest,mresult));               // Send order
---
Mohammad Soubra
27436
Mohammad Soubra  
Siti Latifah:

you're right...


it is mql5 command

--

Also,

Look at the take profit

it is 50.00000 for selling EURUSD !!! The 50 is greater than 1 !!!

so, the best is to forget this story at all

;) 

Drazen Penic
2578
Drazen Penic  

Stop loss and take profit in the MqlRequest struct are prices, not a number of points or pips.

 

sl

Stop Loss price in case of the unfavorable price movement

tp

Take Profit price in the case of the favorable price movement

 

 

One of them must be below, other must be above the order price (depending on order type - buy or sell). 

12
To add comments, please log in or register