B
Use something like this
static datetime LastTradeBarTime; int init() { //---- LastTradeBarTime = Time[1]; // initialise the variable //---- return(0); } start() { // Do <any tick> code here such as trailing stops etc if (LastTradeBarTime == Time[0]) return(0); // Not <first detected tick> on this bar so quit else LastTradeBarTime = Time[0]; // and continue // Do <once per bar> trading stuff here return (0); }
OTTOMH
-BB-
BarrowBoy:
B
Use something like this
OTTOMH
-BB-
Great! I have inserted your solution into my EA and the problem was fixed. Thank You! The code now looks like this: static datetime LastTradeBarTime; int init() { LastTradeBarTime = Time[1]; // initialise the variable return(0); } start() { // Do <any tick> code here such as trailing stops etc if (LastTradeBarTime == Time[0]) return(0); // Not <first detected tick> on this bar so quit else // Start with open order instructions. // If a trade is open give this instruction LastTradeBarTime = Time[0]; // If a new trade is opened we give current time as new value for LastTradeBarTime. return (0); }
blackhawk:
Hi, I'm not sure where to add the above code into my EA? Would you be able to give me little guidance please?
Many thanks,
DM
danielmermina:
You are asking a question about a 3 year old post, maybe you will get an answer in 3 years time.
Hi, I'm not sure where to add the above code into my EA? Would you be able to give me little guidance please?

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi:
I need a solution for this problem.
Imagine a Simple Moving Average EA running on a 15 Minutes Chart with a tight Take Profit and Stop Loss.
Imagine than a new buy order has been activated because the 15 min. bar as closed above the Moving Average.
Imagine that prices are rising fast and the Take profit level is reached 5 minutes later in the same 15 min. bar. The Buy order is closed with a profit.
The problem now is that the EA will open immediately a new Buy Order on the same bar because the open rule is still active (The 15 Min. bar that has activated the rule as not changed yet).
I want to avoid opening new orders on the same bar.
How could I do it ?
Some link with a solution or examples ?
Thank you for your help.