|
Please Help with this Pending Orders Code if you can
// I am trying to use this Pending order code in NN EA that i am still trying to code. It is far from over i just started. Any help Please.
int CheckOpenPendingOrders() {
for (int i = 0; i < OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol() == Symbol() && OrderType() == OP_SELL || OrderType() == OP_BUY)
if (StringSubstr(OrderComment(), 0, 4) == "Open") return (OrderTicket());
}
}
return (0);
}
int CheckPendingOrders() {
for (int i = 0; i < OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol() == Symbol() && OrderType() == OP_SELLSTOP || OrderType() == OP_BUYSTOP)
if (StringSubstr(OrderComment(), 0, 4) == "Pending") return (OrderTicket());
}
}
return (0);
}
// The Below Code does not seem to work it goes into a LOOP after after a few trades.
void ClosePendingOrders() {
double PendingOrderOpenPrice;
int ParentTicket;
int PendingTicket = CheckPendingOrders();
int OpenPendingOrderTicket = CheckOpenPendingOrders();
if (PendingTicket > 0 ) //Scan to see if there exists pendings Orders that needs to be cancelled
{
OrderSelect(PendingTicket, SELECT_BY_TICKET);
PendingOrderOpenPrice = OrderOpenPrice();
ParentTicket = OriginalOrderTicket(PendingTicket);
OrderSelect(ParentTicket, SELECT_BY_TICKET);
if (OrderCloseTime() > 0)
{
if (OrderProfit() <= 0.0 )return; // it should activate the Pending order ( into an open Sellstop or buystop) if the Parent order was a LOSS trade
// i.e the STOP LOSS was hit
// does not seem to work correctly it causes a LOOP. it is able to activate the pending order but
// then it starts to go into LOOP
OrderDelete(PendingTicket); // Deletes the Pending Order if the Parent order was a WIN
if (!(Outcome)) return;
return;
}
}
}
Last edited by progressapama; 01-24-2009 at 02:38 PM.
|