|
|||||||
| 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 |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
|
||||
|
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/ ........................................ |
|
|||
|
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 |
|
||||
|
Quote:
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/ ........................................ |
|
||||
|
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. |
|
||||
|
Quote:
__________________
You need proffesional mql coder? Contact me! I will help you! ........................................ http://www.fxservice.eu/ ........................................ |
|
|||
|
Code:
datetime OneTradePerBar; if(OneTradePerBar== iTime(NULL,TimeFrame,0)) return(0); else OneTradePerBar = iTime(NULL,TimeFrame,0); Last edited by antone : 04-15-2007 at 11:37 AM. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |