In a live ea environment last week, I missed a couple entries at programmed time because of "Invalid Price" (error 129) which mostly came from the market moving away from my entry price beyond the slippage set.
The ea is programmed to trade only on condition and only within an allotted bar/minute, so it didn't resend the order to get a fill after the error 129.
How can I avoid this without accidentally getting more fills than intended?
The ea is programmed to send both a buy and sell at the same time. A few times, only one side got filled. I need it to fill both sides ALL THE TIME when a signal is generated.
Here is the basic buy side routine and changes I've made to resend an order upon error 129. (Sell side logic is the same).
I think it will work...HOWEVER, I am concerned that with this code there is a possibility that it could fill with 2 buys or 2 sells, instead of 1 each.
I understand that I can loop and look for a (OrderType() == OP_BUY), when I tried this, the original order was not sent or filled.
How can I get this to work as intended and always get filled with 1 buy and 1 sell upon error 129, and not accidentally get filled with 2 buys or 2 sells?
Code below:
***************************
void fBuy1()
{// RefreshRates();
while(IsTradeContextBusy()) Sleep(100);
RefreshRates();
int result = OrderSend(Trade,OP_BUY,Lots,Ask,MaxSlippage,0,0,"Open LONG 1B",Magic1B,0,Blue);
int check = GetLastError();
if(check != 0) { Print("Error Sending Order!!! Error code: ", check, " ", ErrorDescription(check)); if (((check == 129) || (check == 138) || (check == 4) || (check == 137)) && (OrdersTotal() < 2)) fBuy1();}
Print(NormalizeDouble(AccountMargin(),2), " MR", " // ", NormalizeDouble(AccountFreeMargin(),2), " FM Available", " // Approx AE: ", NormalizeDouble(AccountEquity(),2), " // M %: ", NormalizeDouble(AccountInfoDouble(ACCOUNT_MARGIN_LEVEL),2)," % " );
}
The ea is programmed to trade only on condition and only within an allotted bar/minute, so it didn't resend the order to get a fill after the error 129.
How can I avoid this without accidentally getting more fills than intended?
The ea is programmed to send both a buy and sell at the same time. A few times, only one side got filled. I need it to fill both sides ALL THE TIME when a signal is generated.
Here is the basic buy side routine and changes I've made to resend an order upon error 129. (Sell side logic is the same).
I think it will work...HOWEVER, I am concerned that with this code there is a possibility that it could fill with 2 buys or 2 sells, instead of 1 each.
I understand that I can loop and look for a (OrderType() == OP_BUY), when I tried this, the original order was not sent or filled.
How can I get this to work as intended and always get filled with 1 buy and 1 sell upon error 129, and not accidentally get filled with 2 buys or 2 sells?
Code below:
***************************
void fBuy1()
{// RefreshRates();
while(IsTradeContextBusy()) Sleep(100);
RefreshRates();
int result = OrderSend(Trade,OP_BUY,Lots,Ask,MaxSlippage,0,0,"Open LONG 1B",Magic1B,0,Blue);
int check = GetLastError();
if(check != 0) { Print("Error Sending Order!!! Error code: ", check, " ", ErrorDescription(check)); if (((check == 129) || (check == 138) || (check == 4) || (check == 137)) && (OrdersTotal() < 2)) fBuy1();}
Print(NormalizeDouble(AccountMargin(),2), " MR", " // ", NormalizeDouble(AccountFreeMargin(),2), " FM Available", " // Approx AE: ", NormalizeDouble(AccountEquity(),2), " // M %: ", NormalizeDouble(AccountInfoDouble(ACCOUNT_MARGIN_LEVEL),2)," % " );
}