I certainly appreciate the willingness of everyone here to help--it has benefitted me greatly. And I am sorry some are tired (qjol et al.) Some day I do hope to donate to say thanks.
In testing my demo account I notice that sometimes an order can be filled in stages. Say I send in an order for 1.5 lots of the EUR/USD pair (ECN). I might show three trades that total 1.5 lots in the Trade tab or in the Order History Tab once all are closed out. in code I send in the order, record the ticket if the send is successful, and use that ticket to modify the order for a stop loss and profit stop.
Each partial fill has a ticket # in the Order History. It appears that even though I am using the original ticket # the server side recognizes that that order was split into three small orders during the fill process. So when I modify the order using the original ticket the server is able to correctly identify and modify the partial fill even though it has a different ticket#. Am I reading this correctly?
As always many thanks for the input.
Nah. Your coding may have some left over memory in handling the ticket number. I also have the same problem last time.
Broker always done request based on your request. So, it must be your coding logic.
Show us your code and we will help you if we can. Please use SRC (besides video icon) to post codes so that it is easy to view.
Great points from all of you--thanks. To WHRoeder's points
1. What I think is happening is that the OrderModify is being processed before the original order is filled via partial fills or one complete one. Thus so far it has worked. But once in the past I had what I now recognize as an order that was filled via two partial orders prior to OrderModify adding the SL/TP. One ticket had the SL/TP, the other had neither. I couldn't figure out what happened so I wrote a routine to check for zombie orders (orders or positions without a SL/TP) and close them.
2. I'll dig through your provided links. I am just getting going this morning.
3. An OrderSelect loop makes great sense. I don't remember the ticket number beyond the scope of the Buy/Sell subroutine. I do track the time each order is placed and limit the frequency an order can be placed. This is more to prevent multiple stop-outs on the same stale signal on an adverse news event.
4. RE ECN. This would be great. I will test to verify.
This is the code for opening Long positions, there is a very similar Sell function. I'll add an orderselect loop later today after reading through everything.
double vol = ORDER_VOL;
double slip = 3 / POINT_ADJUSTMENT;
double price = Ask;
double sl = 0;
double ps = 0;
int cmd = OP_BUY;
bool ord = true;
Alert("Sending order BUY on chart ",Period()," ", Symbol()," VOL=", vol, " ", price, slip, sl, ps);
int Ticket = OrderSend( Symbol(), cmd, vol, price, slip, sl, ps, NULL, MAGIC, 0, ACOL);
if(!OrderSelect( Ticket, SELECT_BY_TICKET))
Alert("Could not select order ", Ticket, " for TP/SL.");
double op = OrderOpenPrice();
ps = op + TP*Point;
if (TP==0) ps=0;
sl = op - TS*Point;
if (TS==0) sl=0;
if(!OrderModify( Ticket, op, sl, ps, 0, White)) Alert("Order Modify failed");
LAST_OPEN_TIME = TimeCurrent();
//IF Arrived here then error on trade
int LastError = GetLastError();
string LastDesc = ErrorDescription(LastError);
Print("Error Attempting to Buy=" + LastError);
Below are the trades on one of the demo accounts. These are market orders. The Lotsize is 2.9 but as you can see some of the orders are filled singly and some jointly.
I think that the order is being modified prior to it being filled as everything here has a SL/TP
To add comments, please log in or register