Error 130 (Invalid Stops) on Pending Order

 
I am having problems with an error 130 on PENDING orders where the stop is close to the market price. However, I can take the same trade (for example Sell Stop, price=1.2792, stop=1.2809, take profit=1.2787, with current market price on the EURUSD of 1.2808) and it works just fine when executed manually.

I still have not figured out a pattern as to when it works and when it does not. But if anyone has seen this problem before can can share some insight, that would be much appreciated.

Thanks.
 
Looks to be a rounding problem. When I pass the exact literal numbers, my trade works. However, if I calculate these numbers, I get a 130 error. The numbers print fine, but I assume that there is enough of a rounding error to cause the problem. Is there a way to round these floating point numbers? Any ideas?
 
I think I solved the problem with the NormalizeDouble function.
 
In my opinion You set stops too closely to price. (see MarketInfo(Symbol(),MODE_STOPS);)