Forex
Google
New signals service!

Go Back   Forex Trading > Discussion Areas > 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 01-25-2007, 09:32 PM
Member
 
Join Date: Dec 2006
Posts: 80
dwmcqueen is on a distinguished road
Restarting EA with current open trade

Is there anything special I need to do with an EA when restarting if there is a current trade open on the currency pair?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-26-2007, 12:42 AM
Senior Member
 
Join Date: Jan 2006
Posts: 1,119
omelette is on a distinguished road
Quote:
Originally Posted by dwmcqueen
Is there anything special I need to do with an EA when restarting if there is a current trade open on the currency pair?
It's the responsibility of the EA to check for open orders and re-initialise any variables that may need updating. So yes, a lot needs to be done........
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-26-2007, 01:15 AM
Member
 
Join Date: Dec 2006
Posts: 80
dwmcqueen is on a distinguished road
Is there any 'template code' that accomplishes at least 90% of this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-26-2007, 01:45 AM
Senior Member
 
Join Date: Jan 2006
Posts: 1,119
omelette is on a distinguished road
Quote:
Originally Posted by dwmcqueen
Is there any 'template code' that accomplishes at least 90% of this?
It depends on the complexity of the EA. You will at least have to scan all open trades, locate the trade with your magic number, get it's trade ticket and check if the SL and TP variables need updating...........
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-26-2007, 02:06 AM
Member
 
Join Date: Dec 2006
Posts: 80
dwmcqueen is on a distinguished road
My EA is basic - just needs to know if trade is there. No trailing stop or anything.

I have language like this:

int trade;
for(trade=OrdersTotal()-1;trade>=0;trade--)
{
if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)==f alse)
continue;

if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=Ma gicNumber)
continue;

if(OrderSymbol()==Symbol()&&OrderMagicNumber()==Ma gicNumber)
if(OrderType()==OP_BUY)
OrderClose(OrderTicket(),OrderLots(),Bid,Slippage, Blue);
}//for

Will that catch previously opened trades?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-26-2007, 04:29 AM
Senior Member
 
Join Date: Mar 2006
Posts: 787
Maji is on a distinguished road
The following when called will detect the number of open and pending orders.
Code:
int CountTrades()
{
 int count=0;
 int trade;
 for(trade=OrdersTotal()-1;trade>=0;trade--)
 {
  OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);
  
  if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
   continue;
   
  if(OrderSymbol()==Symbol() && OrderMagicNumber()== MagicNumber)
  {
  if((OrderType()==OP_SELL) || (OrderType()==OP_SELLSTOP) || (OrderType()==OP_SELLLIMIT) ||
     (OrderType()==OP_BUY) || (OrderType()==OP_BUYSTOP) || (OrderType()==OP_BUYLIMIT))
   count++;
  }
 }//for
 return(count);
}
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
How to open 1 trade per bar anthonyrae Metatrader 4 26 10-07-2007 10:27 AM
Using Gannswing to open trade gee Expert Advisors - Metatrader 4 1 02-15-2007 09:00 PM
how can i trade at the curren second price before the current stick reach it close ti huaxia009 Metatrader 4 2 05-29-2006 04:06 AM


All times are GMT. The time now is 01:28 AM.



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