Forex
Google
New signals service!

Go Back   Forex Trading > Programming > Metatrader Programming


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 07-14-2008, 11:22 AM
Junior Member
 
Join Date: May 2008
Posts: 26
payback is on a distinguished road
How to open two indipendent orders?

Hi all again! I'm sorry to hassle you with questions that may stupid, but i need your help!
My problem is that i wanted to add an hedging subsystem in my EA (originally from coderguru),
so here is the point:

I have an order X if X goes under (e.g.) 25 pips i open order Y

so if was only one order "y" it is no problem because i can use a counter like this

PHP Code:
  //+------------------------------------------------------------------+
//| FUNCTION : NUMBER OF ORDER BASE ON SYMBOL AND MAGIC NUMBER       |
//| SOURCE   : n/a                                                   |
//| MODIFIED : FIREDAVE                                              |
//+------------------------------------------------------------------+
int subTotalTrade()
{
   
int
      cnt

      
total 0;

   for(
cnt=0;cnt<OrdersTotal();cnt++)
   {
      
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(
OrderType()<=OP_SELL &&
         
OrderSymbol()==Symbol() &&
         
OrderMagicNumber()==MagicNumbertotal++;
   }
   return(
total);
}

//+------------------------------------------------------------------+
//| FUNCTION : OPEN ORDER BASE ON SYMBOL AND MAGIC NUMBER            |
//| SOURCE   : n/a                                                   |
//| MODIFIED : FIREDAVE                                              |
//+------------------------------------------------------------------+
string subCheckOpenTrade()
{
   
int
      cnt         
0;
   
string
      lasttrade   
"None";      

   for(
cnt=0;cnt<OrdersTotal();cnt++)
   {
      
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(
OrderType()<=OP_SELL &&
         
OrderSymbol()==Symbol() &&
         
OrderMagicNumber()==MagicNumber)
      {
         if(
OrderType()==OP_BUY lasttrade "BUY";
         if(
OrderType()==OP_SELLlasttrade "SELL";
      }         
   }
   return(
lasttrade);


and then limit to 1 the open order

like this

PHP Code:

//+------------------------------------------------------------------+
//| NEW TRADE - ENTRY                                                |
//+------------------------------------------------------------------+
   
if(subTotalTrade()<&& (BuyCondition  || SellCondition  ) && AllowEntry
   { 
but in this way i can open only one hedging order so what about if
X closes Y still open
X1 goes -25 now i'd like to open Y1 order and i can't!

How can i solve this problem?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-14-2008, 11:35 AM
Senior Member
 
Join Date: Apr 2006
Posts: 131
InTrance is on a distinguished road
Change the MagicNumber for each system in OrderSend and then for your counting
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-14-2008, 11:44 AM
Junior Member
 
Join Date: May 2008
Posts: 26
payback is on a distinguished road
what is the logic behind? i want to open multiple "Y" orders like this
X and Y, x closes
X1 and Y
X1 and Y, Y1
and so on
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-14-2008, 12:03 PM
Senior Member
 
Join Date: Nov 2006
Posts: 215
luxinterior is on a distinguished road
I'd like to try to help you but your question isn't very clear.

Lux
__________________
Build An Expert Advisor. FREE E-course As Seen On TV
ForexArea.com
Users of Gap Trader from 'Forex-Assistant' MUST Read This
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-14-2008, 12:47 PM
Junior Member
 
Join Date: May 2008
Posts: 26
payback is on a distinguished road
Ok i'll try to explain better....
I have an ea, it performs well, but it still have false signals but it's not a problem
For example my signal is buy is buy right ? (X)
if OrderProfit < -25 open hedge order
the hedge order is a sell order (Y) with it's paramaters.

If X closes Y must still open until take profit
and so on X1 Y
X1 Y Y1 etc
is it a little bit more clear?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 07-15-2008, 01:33 AM
Junior Member
 
Join Date: May 2008
Posts: 26
payback is on a distinguished road
still no ideas or suggestions? please help! your are the best on the net!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-15-2008, 04:12 PM
Senior Member
 
Join Date: Apr 2006
Posts: 131
InTrance is on a distinguished road
You could have a binary variable and reset when the first order closes so when you have an X order and it goes -25 and reset=false you open Y. Then set reset=true until X is gone

Hope it makes sense

Last edited by InTrance; 07-15-2008 at 04:17 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 07-15-2008, 05:27 PM
Junior Member
 
Join Date: May 2008
Posts: 26
payback is on a distinguished road
thx! at first look it seems it could work it out! i will try tomorrow because today i'm very busy!
but thx anyway!
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
Close all open orders EA nubika Expert Advisors - Metatrader 4 15 10-25-2008 04:30 AM
EA to close pending and open orders!! criss73 Expert Advisors - Metatrader 4 6 10-31-2007 09:42 PM
close all open orders script forextrend General Discussion 2 12-17-2006 07:16 AM
Script to close open orders... babarmughal Expert Advisors - Metatrader 4 1 12-13-2006 05:50 PM
Using Arrays to track info for All Open Orders deeforex Questions 6 09-12-2006 07:01 PM


All times are GMT. The time now is 02:50 AM.



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