Forex
Google
New signals service!

Go Back   Forex Trading > Downloads > Expert Advisors - Metatrader 4


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-18-2007, 02:55 PM
Junior Member
 
Join Date: Apr 2007
Posts: 6
bkgridley is on a distinguished road
Closing Pending Orders

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);
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-11-2007, 05:47 AM
ryanklefas's Avatar
Senior Member
 
Join Date: Apr 2006
Location: USA
Posts: 439
ryanklefas is on a distinguished road
It looks to me like you have statements for closing orders IMMEDIATELY after the statements for modifying them, which would cause what you are getting. By the way, why are you trying to modify a stop AND THEN delete the order? Makes no sense to me. While we're thinking along these lines, I just made an EA that can modify stops and close orders. You can check it out below. Maybe it will help you, maybe it won't. At the very least, you can check the code as a programming example:

Swiss Army EA (Automatic order management)
__________________
"Don't work harder, work smarter." -- my Java professor

Coder for Hire:
http://www.firecell-fx.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing all orders EA? InTrance Expert Advisors - Metatrader 4 10 08-19-2007 01:13 AM
MT4 pending orders fx_geezer Metatrader 4 5 06-15-2007 09:36 PM
modify orders and close pending orders bkgridley Questions 8 05-23-2007 09:49 PM
EA Help Needed - Closing Existing Orders SuzanneFX Metatrader 4 1 12-26-2006 02:28 PM
Pending orders TheExponential Questions 4 11-25-2005 12:36 AM


All times are GMT. The time now is 06:46 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.