Forex
Google
New signals service!

Go Back   Forex Trading > Discussion Areas > Suggestions for Trading Systems


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-08-2007, 12:26 PM
Junior Member
 
Join Date: Dec 2006
Posts: 11
n7drazen is on a distinguished road
Need help in Expert

I am the beginer in MQL programing and I need som help.

I have two separate experts, one for long and another for short positions.

When I put that experts(code) together my results are different.

This is the code for opening the trades.
Max number of open positions is 2 – one Buy – one Sell, so we can't open two Buy or two Sell positions.


//************************************************** **********************************


if( Condition for Long position is meet )
{
if (OrdersTotal()==1)
{
OrderSelect(1, SELECT_BY_POS , MODE_TRADES);
if(OrderType()== OP_SELL) //If alredy open position is Sell then open Buy position
{
ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,0,Ask-xx*Point,Ask+yy*Point,"",16384,0,Green);
{
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
}
}
if (OrdersTotal()==0) // If there is no open position then open the Buy position.
{
ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,0,Ask-xx*Point,Ask+yy*Point,"",16384,0,Green);
{
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
}
}
//***********************************************


else
{
if( Condition for Short position is meet)
{
if (OrdersTotal==1)
{
OrderSelect(1, SELECT_BY_POS , MODE_TRADES);
if(OrderType()== OP_BUY) // If open position is Buy then open Sell position
{
ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,0,Bid+xx *Point,Bid-yy*Point,"",16384,0,Green);
{
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
}
}
if (OrdersTotal==0) // If there is no open positions then open Sell position
{
ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,0,Bid+xx *Point,Bid-yy*Point,"",16384,0,Green);
{
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
}

}
//************************************************** ********************************************

.......


What is wrong with this code?
Can someone provide different code for this chase.
Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-09-2007, 10:24 AM
Member
 
Join Date: Aug 2006
Posts: 56
JosTheelen is on a distinguished road
Is the 4th bracket "{" OK?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-09-2007, 12:26 PM
Nicholishen's Avatar
Senior Member
 
Join Date: Dec 2005
Posts: 531
Nicholishen is on a distinguished road
There are more than a few errors. Please compair code to find them. I hope this helps.

PHP Code:
if( Condition for Long position is meet 

   if (
OrdersTotal()==1)
   { 
      
OrderSelect(1SELECT_BY_POS MODE_TRADES);
      if(
OrderType()== OP_SELL//If alredy open position is Sell then open Buy position
      

         
ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,0,Ask-xx*Point,Ask+yy*Point,"",16384,0,Green);
         if(
ticket<0)
         {
            Print(
"OrderSend failed with error #",GetLastError());
            return(
0);
         } 
      }
   } 
   if (
OrdersTotal()==0// If there is no open position then open the Buy position.
   

      
ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,0,Ask-xx*Point,Ask+yy*Point,"",16384,0,Green); 
      if(
ticket<0)
      {
         Print(
"OrderSend failed with error #",GetLastError());
         return(
0);
      }
   } 


else if( 
Condition for Short position is meet)

   if (
OrdersTotal==1
   { 
      
OrderSelect(1SELECT_BY_POS MODE_TRADES);
      if(
OrderType()== OP_BUY// If open position is Buy then open Sell position 
      
{
         
ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,0,Bid+xx *Point,Bid-yy*Point,"",16384,0,Green);
         if(
ticket<0)
         {
            Print(
"OrderSend failed with error #",GetLastError());
            return(
0);
         } 
      }
   }
   if (
OrdersTotal==0// If there is no open positions then open Sell position
   
{
      
ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,0,Bid+xx *Point,Bid-yy*Point,"",16384,0,Green);
      if(
ticket<0)
      {
         Print(
"OrderSend failed with error #",GetLastError());
         return(
0);
      } 
   }

__________________
"Anyone who has never made a mistake has never tried anything new." -Albert Einstein
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-09-2007, 12:36 PM
Nicholishen's Avatar
Senior Member
 
Join Date: Dec 2005
Posts: 531
Nicholishen is on a distinguished road
ALso, make sure to change the BID, ASK, TP, SL in the OrderSend method to appropriate settings for the order type.
__________________
"Anyone who has never made a mistake has never tried anything new." -Albert Einstein
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-09-2007, 01:54 PM
Junior Member
 
Join Date: Dec 2006
Posts: 11
n7drazen is on a distinguished road
Nicholishen, thank you very much for your advice and help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-09-2007, 02:01 PM
Junior Member
 
Join Date: Dec 2006
Posts: 11
n7drazen is on a distinguished road
Nicholishen, thank you very much for your advice and help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-09-2007, 09:06 PM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 280
ralph.ronnquist is on a distinguished road
Buy and sell at same time?

I'm not sure if it's intentional or a basic trading rule or something, but the overall code structure rules out the possibility of making short trade whenever the conditions for long are met, regardless of whether there is along trade or not. In particular, even when a long position is open, the EA won't consider making a short trade if the conditions for long are met.

If the EA is formed by using independent logics for long and short trading, maybe this should be combined independently? A good software design for that would be to preserve all the code of two trading directions, but add a prefix like "long_" and "short_" to their identifiers. The combined EA would then have an outline:

//-----------+
int init() {
long_init();
short_init();
return(0);
}

int deinit() {
long_deinit();
short_deinit();
return(0);
}

int start() {
long_start();
short_start();
return(0);
}
//-----------------+

This approach of course relies on that the two sub systems don't hog the thread in Sleep calls. There is also a preference for long trades that may have an impact when the equity is low.

... just a thought
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 01-10-2007, 07:49 AM
Junior Member
 
Join Date: Dec 2006
Posts: 11
n7drazen is on a distinguished road
I modified the expert but problem persist.
Expert opens total 925 positions - 698 Short and 227 Long.
When I set Long condition to unattainable then expert, of course, opens only Short positions and number of Short trades trades is the same - 698. But when I set Short condition to unattainable number of Long positions is 358(this is correct number of trades) . So total number of trades must be 1056, not 925. What is the problem in above code?
Btw, opening conditions depends(among others) on time. So, short positions are opened in the forenoon (GMT) and Long positions in the afternoon. I assume Long positions cannot be open when Short position is open. Why?

Last edited by n7drazen; 01-10-2007 at 08:38 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 01-10-2007, 08:53 AM
Junior Member
 
Join Date: Dec 2006
Posts: 11
n7drazen is on a distinguished road
Quote:
...
I assume Long positions cannot be open when Short position is open. Why?
I just check the results in Strategy Tester Report and that is not the case – Expert opens Long positions when Short is open.

In some cases Expert opens Short positions even if one Short position is already open - but code says - open Short position if(OrderType()== OP_BUY) or if OrdersTotal()==0.
Now I am confused.

Last edited by n7drazen; 01-10-2007 at 09:06 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 01-10-2007, 09:55 AM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 280
ralph.ronnquist is on a distinguished road
missing parentheses?

Well, the code you submitted as well as Nicholishen's corrected code has the conditions like
: if ( OrdersTotal == 1 ) ...
and
: if ( OrdersTotal == 0 ) ...
in the short trade logic. That is, it lacks the parentheses "OrdersTotal()". It seems peculiar that it compiles, but perhaps "OrdersTotal" without parentheses gets treated as a variable with value 0 ?
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
Expert Question and Expert mj10 Expert Advisors - Metatrader 4 24 03-27-2006 01:31 PM


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



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