I'm having a problem with this EA. It is supposed to close all pending orders when a stop loss is modified, however, it is closing all my orders before the stop loss is being modified. Hence, I don't even know if the stop order modifications work correctly.
//+------------------------------------------------------------------+
//| Millionaire.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//|
http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#include <stdlib.mqh>
#include <WinUser32.mqh>
extern double Price1;
extern double HighPrice = 0;
int start()
{
if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==true)
{
Price1 = OrderOpenPrice();
if(Bid>HighPrice==true)
{
HighPrice = Bid;
}
{
if(((HighPrice - OrderOpenPrice()) > (40 * Point)) && (OrderStopLoss() < (HighPrice - (20 * Point)))==true)
{
OrderModify(
0,
OrderOpenPrice(),
HighPrice - (20 * Point),
HighPrice + (100 * Point),
0,
CLR_NONE);
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type)
{
//Close pending orders
case OP_BUYLIMIT :
case OP_BUYSTOP :
case OP_SELLLIMIT :
case OP_SELLSTOP : result = OrderDelete( OrderTicket() );
}
if(result == false)
{
Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
Sleep(3000);
}
}
}
}
}
return(0);
}