Python order filling type and deviation

 
I have tried different levels of deviations. Now I have it set to 0. I even changed the order filling type to FOK and still buy more expensive than I set the price. What is the issue because I think I gave up on MT5
 
Dragos Drimbe: I have tried different levels of deviations. Now I have it set to 0. I even changed the order filling type to FOK and still buy more expensive than I set the price. What is the issue because I think I gave up on MT5

It is called spread! You will always buy at a higher price and sell at a lower price. You buy at the Ask price and you sell at the Bid price.

 
I want to buy at the price I set if not I dont want to buy
 
Dragos Drimbe #: I want to buy at the price I set if not I dont want to buy

That is not how trading works! You have two choices:

  • You wait until the Ask price is at (or below) the price you want, and then place the market order, or ...
  • you place a buy limit pending order and wait for it to be triggered at or below the price you want.
 
Yes nuy limit order seems to be the way, the problem is it work only with pending orders and I have to think at a way to remove it if is not fulfilled and  the conditions are not valid anymore
 
Dragos Drimbe #: Yes nuy limit order seems to be the way, the problem is it work only with pending orders and I have to think at a way to remove it if is not fulfilled and  the conditions are not valid anymore

Then use the first option. Have your code monitor the Ask price, and if or when it reaches the price you want, then place the market buy order.

 
I am trying the buy limit order but I get invalid price for some unknown reason. I checked the price and is valid
 
Dragos Drimbe #: I am trying the buy limit order but I get invalid price for some unknown reason. I checked the price and is valid

When you use pending orders, you have to check for the broker's Stops Levels and Freeze Levels limitations. For many brokers, you can't place a pending order too close to the current prices.

 
Fernando Carreiro #:

When you use pending orders, you have to check for the broker's Stops Levels and Freeze Levels limitations. For many brokers, you can't place a pending order too close to the current prices.

I dont think it is the case here. I got an order fulfilled. I have read somewhere on this forum that this error might occure when the market is closed


I have to solve the problem to close the pending order if is not valid anymore and I have no idea how to get only pending orders for the symbol

 
Here is how to get the orders from the API.


The functions starting with Order* will be the ones giving you access to pending orders.

Take a look and see how you get access to them.


 
Dragos Drimbe #: I dont think it is the case here. I got an order fulfilled. I have read somewhere on this forum that this error might occure when the market is close. I have to solve the problem to close the pending order if is not valid anymore and I have no idea how to get only pending orders for the symbol

See the example code for "orders_get" to retrieve information on active orders and then use "order_send" with " TRADE_ACTION_REMOVE" to remove/delete the pending order.

However, I still advise you to use the first option instead of pending orders so close to the current market prices. Most brokers do not allow for that.

Reason: