USDJPY always produces Error 4107

 

Hi,


Why in the world does this

_ticket=OrderSend("USDJPY",OP_BUY,_lotsize,NormalizeDouble(Ask,4),_slippage,_stop,_prof,_comment,_magic,_expiry,_arrow);


always fail with error 4107 in my demo account?

 

First question: why are you normalizing the price (at all), and particularly to 4 digits? JPY crosses are 2 or 3 digits.

Second question: are you using this code on a different chart to USDJPY? 

 
honest_knave:

First question: why are you normalizing the price (at all), and particularly to 4 digits? JPY crosses are 2 or 3 digits.

Second question: are you using this code on a different chart to USDJPY? 

Hi,

I get the same result with plain old Ask,-slippage,.....

Yes, the code is being used on a AUDUSD chart, along with a couple of other pairs that don't cause any problems.

 
MrMonty:

Hi,

I get the same result with plain old Ask,-slippage,.....

Yes, the code is being used on a AUDUSD chart, along with a couple of other pairs that don't cause any problems.

You can't use Ask to place an order on USDJPY if the EA is running on AUDUSD. Please read the documentation.

You have to use MarketInfo() to get USDJPY price.

 
Alain Verleyen:

You can't use Ask to place an order on USDJPY if the EA is running on AUDUSD. Please read the documentation.

You have to use MarketInfo() to get USDJPY price.

Ok ...I'll do that now.

I'm curious though, why would the other pairs work properly?

 
MrMonty:

Hi,

I get the same result with plain old Ask,-slippage,.....

Yes, the code is being used on a AUDUSD chart, along with a couple of other pairs that don't cause any problems.

When you use the predefined variables of Bid and Ask, they relate to the chart the code is running on.

So, if you are running this code on the AUDUSD chart, then you are trying to open a Buy order on USDJPY at the Ask price of AUDUSD.

You need to use the correct price. You can either get all the current info on the latest USDJPY tick using:

   MqlTick tick;
   SymbolInfoTick("USDJPY",tick);

 and then access the appropriate value e.g.

tick.bid


Or you can retrieve just the value you need:

SymbolInfoDouble("USDJPY",SYMBOL_BID)

or the older way:

MarketInfo("USDJPY",MODE_BID)


The documentation on SymbolInfoDouble() suggests that SymbolInfoTick() is preferable in this scenario but I haven't encountered the issues using SymbolInfoDouble():

Note

It is recommended to use SymbolInfoTick() if the function is used for getting information about the last tick. It may well be that not a single quote has appeared yet since the terminal is connected to a trading account. In such a case, the requested value will be indefinite.

In most cases, it is enough to use SymbolInfoTick() function allowing a user to receive the values of Ask, Bid, Last, Volume and the time of the last tick's arrival during a single call. 

 

MrMonty: he code is being used on a AUDUSD chart, along with a couple of other pairs that don't cause any problems.

_ticket=OrderSend("USDJPY",OP_BUY,_lotsize,NormalizeDouble(Ask,4),_slippage,_stop,_prof,_comment,_magic,_expiry,_arrow);
  1. This is why I recommend
    Do not trade multiple currencies in one EA
    • You can't use any predefined variables, can't use the tester, must poll (not OnTick,) and usually other problems.
    • Code it to trade the chart pair only. Look at the others if you must.
    • Then put it on other charts to trade the other pairs. Done.
  2. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
Reason: