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 08-07-2006, 01:18 PM
Member
 
Join Date: May 2006
Posts: 30
skorcht is an unknown quantity at this point
Can't get EA to close 2 Open positions???

I have an EA that is suppose to close 2 open buys or sells when the conditions are right (one of the EA's functions)

I used the EA generator at that one website.

Anyways, it works alot of the time but sometimes it only closes 1 buy.
I even put in a short delay between closes because I thought it was a timing issue.

Is there a function to close ALL open buys or Sells in one shot? The Generator goes through 1 by 1 and closes them.

I can't think of why this won't close both all the time

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-07-2006, 04:06 PM
Roets's Avatar
Senior Member
 
Join Date: Nov 2005
Location: North West South Africa
Posts: 118
Roets is on a distinguished road
Wink Have fun.

Quote:
Originally Posted by skorcht
I have an EA that is suppose to close 2 open buys or sells when the conditions are right (one of the EA's functions)

I used the EA generator at that one website.

Anyways, it works alot of the time but sometimes it only closes 1 buy.
I even put in a short delay between closes because I thought it was a timing issue.

Is there a function to close ALL open buys or Sells in one shot? The Generator goes through 1 by 1 and closes them.

I can't think of why this won't close both all the time


if (................Your condition to close the orders.................)
{
total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type)
{
case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 1, Aqua ); break;
case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 1, Tomato );
}
if (UseSound) PlaySound(NameFileSoundClose);
}
}

Place this code at the end of the "int start()".
__________________
Pro FX Experts for Professional Meta Trader Experts
Automate your manual method!
We accept all major credit cards with no upfront payment required!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-07-2006, 05:13 PM
Member
 
Join Date: May 2006
Posts: 30
skorcht is an unknown quantity at this point
i should have posted the EA GENERATOR CODE..
it's almost the same as what you posted Yet I still have problems with both BUYS or SELLS not being closed at the same time..just 1 of them

for (int i = 0; i < Total; i ++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
IsTrade = True;
if(OrderType() == OP_BUY) {

if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage,MediumSeaGreen);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;

ELSE --- the close sell code wich is same as close buy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-07-2006, 05:26 PM
Senior Member
 
Join Date: Mar 2006
Posts: 787
Maji is on a distinguished road
Your problem maybe the way the loop is counted.

You have
for (int i = 0; i < Total; i ++)

It is a very poor style of coding, because the positions are renumbered as the first one gets deleted/closed. Thus, the last position will not get deleted/close.

Use the countdown method outlined by Roets...

total = OrdersTotal();
for(int i=total-1;i>=0;i--)

That is the right way to loop when trying to close/delete orders.

Good luck.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-07-2006, 10:15 PM
Member
 
Join Date: May 2006
Posts: 30
skorcht is an unknown quantity at this point
OK..

but why would it Not work only once in awhile?
Seems like it the COde was faulty..it wouldn't work every time.

i hate problems like thi
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
EA to close positions after profit/loss hit james2ko Expert Advisors - Metatrader 4 1 05-22-2007 04:03 AM
Open/close trade on same bar's close? WNW Expert Advisors - Metatrader 4 2 03-29-2007 05:37 AM
Close all open positions jonjonau Expert Advisors - Metatrader 4 6 07-12-2006 05:01 AM
Close All Open Positions? lonespruce Metatrader 4 9 06-22-2006 07:20 AM


All times are GMT. The time now is 07:15 PM.



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