Cancel open orders when price invalidates trade.

Back to topics list To post a new topic, please log in or register
brad 2014.06.11 16:00

Thanks for your assistance.

I placed orders to open short on the NZDUSD daily TF.

The entry was just below the bar low and I wanted my code to close the orders if price invalidated the trade by moving above the bar high.

It appeared that my code closed the orders before price moved above the bar high.

Below is a screen shot of where I think the orders were closed.


The red horizontal line shows the invalidation level.

The orange arrow shows the bar that price almost touched but didn't on the 15 min chart until later.

My code closed the orders at this time and I had to reopen the positions again which were soon closed again.

Here is some code:.

else TradeInvalidatedValue=High[BarShift];

         for(int i=OrdersTotal();OrdersTotal()>0;i--)
            if(DeleteOrder==false)Print("An error occurred trying to delete an order: ",GetLastError());
            }//End for loop
         }//End if(Ask<TradeInvalidatedValue)

Did this happen because of the spread?

Should I amend the code something like..




deysmacro 2014.06.12 02:56 #
Should I amend the code something like..

It is better you run and see what happens. Never asks unless it would not run like it should.

However, what I see here is more to logic solutions rather than problems.

WHRoeder 2014.06.12 15:38 #
brad:I placed orders to open short on the NZDUSD daily TF.
for(int i=OrdersTotal();OrdersTotal()>0;i--)
  1. You can only delete pending orders. You don't check if the ticket has opened.
  2. You are looping on your array, but checking for the total number of open orders. They are not the same in the presence of other EAs on other charts and manual trading.
    for(int i=nTickets; i>0; i--)
Back to topics list  

To add comments, please log in or register