Forex
Google

Go Back   Forex Trading > Discussion Areas > Metatrader 4
Forex Forum Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


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 04-13-2007, 01:47 PM
anthonyrae anthonyrae is offline
Junior Member
 
Join Date: Dec 2006
Posts: 6
anthonyrae is on a distinguished road
How to open 1 trade per bar

Hello,

I was wondering if there is anyone kind enough to tell me how you would program an expert advisor to open one trade only per bar. What I mean for this is, I have programmed an expert advisor that opens a buy trade when the current MACD is greater than the previous MACD, but opens a trade every time the price moves. I only want it to open 1 trade per bar, (the important bit is the 1 trade per bar, as I want it to open a trade for the next bar)

ie)

if trade < 1 for current bar ( open trade )
else
( do nothing )


If anyone can help, it would be much appreciated !

Cheers, Anthony
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-13-2007, 01:51 PM
Kalenzo's Avatar
Kalenzo Kalenzo is offline
Senior Member
 
Join Date: Dec 2005
Location: Bydgoszcz - Poland
Posts: 692
Kalenzo is on a distinguished road
You can use OrdersTotal() function and magic number and for or while loop.
Combine those and check if your magic number currently exists, if the answer will be true, then you should say to ea - do not open any trades now (eg. with "if")
__________________
You need proffesional mql coder? Contact me! I will help you!
........................................
http://www.fxservice.eu/
........................................
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-14-2007, 01:18 AM
anthonyrae anthonyrae is offline
Junior Member
 
Join Date: Dec 2006
Posts: 6
anthonyrae is on a distinguished road
hi,

thanks for your help, but I couldn't figure out how to do it with what you suggested. however i have made a similar solution by saying only open a new trade if the time of the last trade was 15 mins ago (ie 1 trade every bar for the 15 min timeframe).

It seems to work, but it's not as accurate.

If anyone can give an example of code, it would be appreciated !

Cheers, Anthony
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-14-2007, 01:53 AM
ralph.ronnquist's Avatar
ralph.ronnquist ralph.ronnquist is offline
Senior Member
 
Join Date: Oct 2006
Posts: 280
ralph.ronnquist is on a distinguished road
PHP Code:
bool opened_on_current_bar false;

for (
int i OrdersTotal() - 1>=0i-- ) {
    if ( ! 
OrderSelectiSELECT_BY_POS ) )
        continue;
    if ( 
OrderOpenTime() >= Time] ) {
        
opened_on_current_bar true;
        break;
    }
}
// Here the variable opened_on_current_bar is set appropriately 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-14-2007, 11:21 AM
Kalenzo's Avatar
Kalenzo Kalenzo is offline
Senior Member
 
Join Date: Dec 2005
Location: Bydgoszcz - Poland
Posts: 692
Kalenzo is on a distinguished road
Quote:
Originally Posted by ralph.ronnquist
PHP Code:
bool opened_on_current_bar false;

for (
int i OrdersTotal() - 1>=0i-- ) {
    if ( ! 
OrderSelectiSELECT_BY_POS ) )
        continue;
    if ( 
OrderOpenTime() >= Time] ) {
        
opened_on_current_bar true;
        break;
    }
}
// Here the variable opened_on_current_bar is set appropriately 
Nice code but the condition OrderOpenTime() >= Time[0] will not work.
First some basic information:
OrderOpenTime() and Time[] are int's and they are like timestamp.
Time[0] is the current time value.

But lets say that we will use normal hours just for education purposes.
Assuming that we are currently on bar 12.00 on 1h chart, we open trade at 12.01, and lets say that we are 1 minute after that time (12.02).

Now lets check this condition:
if 12.01 >= 12.02 opened_on_current_bar = true;

will this code work ? I don't think so. And where is the magic number condition? Hm... try again
__________________
You need proffesional mql coder? Contact me! I will help you!
........................................
http://www.fxservice.eu/
........................................
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-14-2007, 12:06 PM
lowphat's Avatar
lowphat lowphat is offline
Senior Member
 
Join Date: Sep 2005
Posts: 199
lowphat is on a distinguished road
could you do something like this or would it be bad practice?

Code:
if (NewBar() == true) allowtrade=true;

if (allowtrade)//entry
   {
   if(logic)buy;
   if(logic)sell;
   allowtrade=false;
   }

}
Code:
bool NewBar()
{
   static datetime lastbar = 0;
   datetime curbar = Time[0];
   if(lastbar!=curbar)
   {
      lastbar=curbar;
      return (true);
   }
   else
   {
      return(false);
   }
}

Last edited by lowphat : 04-14-2007 at 12:10 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-14-2007, 02:02 PM
ralph.ronnquist's Avatar
ralph.ronnquist ralph.ronnquist is offline
Senior Member
 
Join Date: Oct 2006
Posts: 280
ralph.ronnquist is on a distinguished road
Time[0] is the opening time of the current bar.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-14-2007, 04:22 PM
Kalenzo's Avatar
Kalenzo Kalenzo is offline
Senior Member
 
Join Date: Dec 2005
Location: Bydgoszcz - Poland
Posts: 692
Kalenzo is on a distinguished road
Quote:
Originally Posted by ralph.ronnquist
Time[0] is the opening time of the current bar.
No, Time[0] is the current time.
__________________
You need proffesional mql coder? Contact me! I will help you!
........................................
http://www.fxservice.eu/
........................................
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-14-2007, 05:27 PM
ralph.ronnquist's Avatar
ralph.ronnquist ralph.ronnquist is offline
Senior Member
 
Join Date: Oct 2006
Posts: 280
ralph.ronnquist is on a distinguished road
RTFM

http://docs.mql4.com/predefined/variables/time
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-15-2007, 11:21 AM
antone antone is offline
Senior Member
 
Join Date: Oct 2006
Posts: 102
antone is on a distinguished road
Code:
datetime OneTradePerBar; 

if(OneTradePerBar== iTime(NULL,TimeFrame,0)) return(0); else OneTradePerBar = iTime(NULL,TimeFrame,0);
that should do the Job.. instead of doing those other codes.. just add it before the trade codes..

Last edited by antone : 04-15-2007 at 11:37 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Gannswing to open trade gee Expert Advisors - Metatrader 4 1 02-15-2007 09:00 PM
Restarting EA with current open trade dwmcqueen Metatrader 4 5 01-26-2007 04:29 AM
script open trade BrunoFX Tools and utilities 6 05-21-2006 11:08 PM


All times are GMT. The time now is 10:24 PM.