Forex



Go Back   Forex Trading > Downloads > Expert Advisors - Metatrader 4
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 04-18-2007, 03: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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 05-11-2007, 06:47 AM
ryanklefas's Avatar
Senior Member
 
Join Date: Apr 2006
Location: USA
Posts: 438
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

Advertise on The All New FireCell Network
"Where online investing makes sense"

Coder for Hire:
http://firecell.info
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 02:13 AM
MT4 pending orders fx_geezer Metatrader 4 5 06-15-2007 10:36 PM
modify orders and close pending orders bkgridley Questions 8 05-23-2007 10:49 PM
EA Help Needed - Closing Existing Orders SuzanneFX Metatrader 4 1 12-26-2006 03:28 PM
Pending orders TheExponential Questions 4 11-25-2005 01:36 AM


All times are GMT. The time now is 04:09 AM.



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