Run OrderSend only in active Symbol window? Why?

 

Hi,

I have been trying to run the below script to open an order for e.g. EURUSD.

When the active window in Terminal is EURUSD then the order is open but if I click on a window of any other symbol, the error 129 appears.

I need to open two orders for pair trading and don't know why I can't do that. My broker said, there isn't anything blocked from their side.

Do you find the same issue? How to resolve it?

cornelius

#property show_inputs

extern string Symbol1="EURUSD";
extern double LotSize=0.01;

int start()
  {

int ticket = OrderSend(Symbol1, OP_BUY, LotSize, Ask, 2, 0, 0);

      if (ticket>0)            
        {
         Alert ("Order Buy succeded. Ticket = ",ticket);                                  
        } 
      else
        {
        Alert(GetLastError());
        }
       
   return(0);
  }
Files:
 

ERR_INVALID_PRICE 129 Invalid bid or ask price, perhaps, unnormalized price. After 5-second (or more) delay, it is necessary to refresh data using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.

Ask returns value of the Current Symbol. OrderSend(Symbol1, OP_BUY, LotSize, Ask, 2, 0, 0); You're trying Buy EURUSD at EURJPY price, Thats not gonna happen. Also, no Broker(except ECN perhaps) is going to let you send a pending order at Current Price use Ask+Cushion; where mathAbs(Cushion)>Minimum Stop Distance of Broker MarketInfo(iSymbol,MODE_STOPLEVEL). What you need is

MODE_ASK 10 Last incoming ask price. For the current symbol, it is stored in the predefined variable Ask
double MarketInfo( string symbol, int type)
Returns various data about securities listed in the Market Watch window. A part of information about the current security is stored in predefined variables.
Parameters:
symbol - Security symbol.
type - Request identifier that defines the type of information to be returned. Can be any of values of request identifiers.
Sample:
   double bid   =MarketInfo("EURUSD",MODE_BID);
   double ask   =MarketInfo("EURUSD",MODE_ASK);
   double point =MarketInfo("EURUSD",MODE_POINT);
   int    digits=MarketInfo("EURUSD",MODE_DIGITS);
   int    spread=MarketInfo("EURUSD",MODE_SPREAD);

 

Thanks ubzen a lot for comprehensive answer!

cornelius

 

To make the program generic:

#property show_inputs

extern double LotSize=0.01;

int start() {
   int ticket = OrderSend(Symbol(), OP_BUY, LotSize, Ask, 2, 0, 0);
   if (ticket>0) {
      Alert ("Order Buy succeded. Ticket = ",ticket);
   }   
   else {        
      Alert(GetLastError());
   }
   return(0);
}
Reason: