ordermodify() function don't work

To add comments, please log in or register
bouboufx
8
bouboufx  

Hello

when I execute the EA, the buy order is created but the error 130 message(invalid stop loss)  is displayed for the function ordermodify ()?

I used ordermodify() function beceause in my broker I can't created makret or pending order with stop loss and takeprofit levels. 


/+------------------------------------------------------------------+

//|                                                          bb2.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
extern int TakeProfit=10;
extern int StopLoss=10;
extern bool condition=true;

int OnInit()
  {

   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  if(condition)
  {
double TakeProfitLevel=Bid + TakeProfit*Point;
double StopLossLevel= Bid - StopLoss*Point;

int buyticket=OrderSend("EURUSD",OP_BUY,0.01,Ask,10,0,0,"my 1st order!");
if(OrderSelect(buyticket,SELECT_BY_TICKET))
{
Print("ticket=",OrderTicket(),"openprice=",OrderOpenPrice());
bool buymodify=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-10*Point,Bid+10*Point,0,clrNONE);
}
condition=false;
Print("erreur" , GetLastError());
}


   
  }
//+------------------------------------------------------------------+

Cuenta Desactivada
60
Cuenta Desactivada  

Hi,

You need to validate "STOPLEVEL" for the current symbol, "STOPLEVEL" is minimal stop level (in points) for orders.

//
Print("Stop level in points=",MarketInfo(Symbol(),MODE_STOPLEVEL));
//
PS: Please, use the code button (Alt+S) when sharing code in forum
William Roeder
19434
William Roeder  
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Check your return codes for errors, and report them including GLE/LE. Don't look at it unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

     int buyticket=OrderSend("EURUSD",OP_BUY,0.01,Ask,10,0,0,"my 1st order!");
    if(OrderSelect(buyticket,SELECT_BY_TICKET))
    
    You try to print GLE but you've already lost it when you do the select. Check immediately.

  3. You calculate your stops but if there is any slippage, they are bogus. Either compute them using OrderOpenPrice() and modify, or just include them with the OrderSend. There is no need to open an order and then set the stops. Simplify your code - do it in one step. TP/SL on OrderSend has been fine for years.
              Build 500 № 9 2013.05.09
              Need help me mql4 guru add take profit to this EA - Take Profit - MQL4 programming forum 2017.09.27

  4. In any case, 10 point stops may be the problem. You can't move stops (or pending prices) closer to the market than the minimum: MODE_STOPLEVEL * _Point or SymbolInfoInteger(SYMBOL_TRADE_STOPS_LEVEL).
              Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

To add comments, please log in or register