RefreshRates()

 

 Hello community 

I have always one problem 

the error 130 MT4

error description:  invalid stops

 

in the function below, if I call it then the error continuously will appear

also if I place it inside the OnTick() same error 130 will come again

so, why the error is coming by calling as a function

does the RefreshRates() help????

 

 

void BuyBreakEven()
{
   for (int cnt = 0; cnt < OrdersTotal(); cnt++)
   {
      int ticket_select = OrderSelect (cnt, SELECT_BY_POS);
      
      if ( OrderType() <= OP_SELL
      &&   OrderSymbol() == Symbol()
      &&   OrderMagicNumber() == buy_magic_number )
      {
         if (OrderType() == OP_BUY)
         {
            if (BreakEvenStart > 0 && BreakEven)
            {
               int ticket_modify =
                  OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+(BreakEvenValue*trade_point),
                     OrderTakeProfit(), 0, modify_arrow_color);

               if(!ticket_modify)Print("Break Even: Order cannot be modified, ", GetLastError());
               else Print("Break Even Placed Successfuly.");
            }
         }
      }
   }
}
 
      int ticket_select = OrderSelect (cnt, SELECT_BY_POS);
      //ORDER SELECTED

      if ( OrderType() <= OP_SELL
      &&   OrderSymbol() == Symbol()
      &&   OrderMagicNumber() == buy_magic_number )

But then,

         if (OrderType() == OP_BUY)
         {

You can not have OP_BUY and OP_SELL at the same time Mohammad.

so

if(OrderType()==OP_BUY)
 {
  //do something
 }

else if(OrderType()==OP_SELL)
 {
  //do something else
 }
 
Marco vd Heijden:

But then,


You can not have OP_BUY and OP_SELL at the same time Mohammad.

no my friend

you are not correct

I know what you mean

the first OP_SELL means the executed orders not the pending because in the mql table they are giving the OP_SELL value

ID

Value

Description

OP_BUY

0

Buy operation

OP_SELL

1

Sell operation

OP_BUYLIMIT

2

Buy limit pending order

OP_SELLLIMIT

3

Sell limit pending order

OP_BUYSTOP

4

Buy stop pending order

OP_SELLSTOP

5

Sell stop pending order

 

thanks for your try 

 

It filters for sell orders only.

if ( OrderType() <= OP_SELL

This litterally filters if Ordertype is <= smaller or == equal to OP_SELL.

From this moment on

         if (OrderType() == OP_BUY)
         {
            if (BreakEvenStart > 0 && BreakEven)
            {
               int ticket_modify =
                  OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+(BreakEvenValue*trade_point),
                     OrderTakeProfit(), 0, modify_arrow_color);
Only BUY orders are handled so show the value of
trade_point
 
Marco vd Heijden:

It filters for sell orders only.

This litterally filters if Ordertype is <= smaller or == equal to OP_SELL.

From this moment on

Only BUY orders are handled so show the value of
int OnInit()
  {
   if(Digits==3 || Digits==5) trade_point=Point*10;

//---
   return(INIT_SUCCEEDED);
  }
 
BreakEvenValue
 
Marco vd Heijden:

 

 

 I think that I found it

have been added the RefreshRates() then every think is ok

 

Thanks again Marco 

   for (int cnt3 = 0; cnt3 < OrdersTotal(); cnt3++)
   {
      int ticket_select = OrderSelect (cnt3, SELECT_BY_POS);
RefreshRates();
      if ( OrderType() <= OP_SELL
      &&   OrderSymbol() == Symbol()
      &&   OrderMagicNumber() == buy_magic_number )
      {
         if (OrderType() == OP_BUY)
         {
            if (BreakEvenStart > 0 && BreakEven)
            {
               int ticket_modify =
                  OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+(BreakEvenValue*trade_point),
                     OrderTakeProfit(), 0, modify_arrow_color);

               if(!ticket_modify)Alert("Break Even: Order cannot be modified, ", ErrorDescription(GetLastError()));
               else Print("Break Even Placed Successfuly.");
            }
         }
      }
   }

 

 
Mohammad Soubra:

 

 

 I think that I found it

have been added the RefreshRates() then every think is ok

 

Thanks again Marco 

 

Just by chance, RefreshRates() is useless in this code.
 
Alain Verleyen:
Just by chance, RefreshRates() is useless in this code.
so, what is the perfect solution???
 
Mohammad Soubra:
so, what is the perfect solution???
You need to print the price values (new and old stoploss, ask/bid price) when there is an error, not only the error #
if(!ticket_modify)Print("Break Even: Order cannot be modified, ", GetLastError());
In general you need to follow these rules when setting stoploss/takeprofit.
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
 
Alain Verleyen:
Just by chance, RefreshRates() is useless in this code.

Hello Mr Alain,

 

yes

you are right 

that was just a chance, I have tried the same in another broker with the error invalid stops!!! 

what is the correction? 

Reason: