record time and check its change (with new time), only get prices when the time have 16 mins change
for example:
datetime lasttime = NULL; int start() { if ((lasttime != NULL ) && ((Time[0] - lasttime) < Period( ) )) return; //only go when time has passed period lasttime = Time[0]; Barcurrentopen=(iOpen("EURUSD",PERIOD_M15,0)); Barcurrentclose=(iClose("EURUSD",PERIOD_M15,0)); Barsize=(Barcurrentopen-Barcurrentclose)*10000; Print(Barsize);
Current bar openprice is fixed when the new bar is created. But closeprice changes because current closeprice is the current lastprice tick for that bar, and it will eventually be fixed with the final price tick for that bar.
This is a newbie question but I've been looking now for hours and hours trying to figure this out before posting.
I'm writing a simple learning EA where I only want to issue a BuyStop when the High of the current day exceeds some fixed amount of the previous day's close.
1. Previous Day's bar closes
2. Calculate a breakout amount for next day.
3. Issue a buy stop at start of the next day.
Intuitively (which is leading me astray), I am trying to work with daily bars and would think the start() routine would only be called once for the day but clearly that is not happening.
My question, is how would I code this in general terms so that I only recognize and issue conditional OrderSend for the day?
Alternatively, how would I know when I am looking at the first bar of a new trading day?
Thanks in advance for any help.
Rollin
This is a newbie question but I've been looking now for hours and hours trying to figure this out before posting.
Alternatively, how would I know when I am looking at the first bar of a new trading day?
Thanks in advance for any help.
Rollin
Rollin,
Yes it is very basic question that have been discussed before on the forum.
The solution is simply to keep the last bar open time and check it with current bar open time.
If the two are different, then you have a new bar.
datetime barTime; // global variable int start() { ... if( barTime < Time[0] ) { // we have a new bar opened barTime = Time[0]; // keep the new bar open time ...<do whatever you want with the new bar> } ... }
I tried this code, and get the following error message: "{ not allowed in global scope"
Please help.
Thanks Fireflies.
I can see how this will work. What continues to twist my mind is that I am (in
this case) working with daily bars with a strategy tester and it appears that within
the start routine I am getting 35 "sub bars." The strategy tester is
set to period Daily and the Model is Control points.
While your suggested routine above or a variation therof will help me easily sort
out the first bar of the new day, I'm curious as to why 35 intervals per calendar
day.
As a reference, I am coming over from the stocks side of the business and am a
VB programmer with a fair amount of backtesting experience. The syntax is throwing
me a little but not much but bars within bars is new. Overtly spanning multiple
time frames is one thing but having to do so within the time frame chosen seems
odd.
I appreciate your time (pun intended).
Rollin
The 'sub bars' has nothing to do with forex in particular, it is how metatrader tries to simulate realmarket during backtesting.
Some people here, including myself, see that even this is not realistic enough.
We prefer to have actual ticks are used during backtesting, although it is rather imposible due to hugh amount of prepared input data.
If you don't want the changes of price during a bar development, and only fully created bars, then I suggest you use the previous bar instead.
ie. Use Close[1], Open[1], etc.
TO Detect when NEW period Starts (High/low prices of that chosen timeframe):

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am a newbee in this and have a simple question...
I'm trying to write a simple EA witch should calc the current bar.
Using it on a 15 min chart.
To get both openprice closeprice on the current 15 min bar chart I use "Every tick" in the model for backtesting.
But it seems to me that openprice and closeprice on a current bar is updated on every tick....
Barcurrentopen=(iOpen("EURUSD",PERIOD_M15,0));
Barcurrentclose=(iClose("EURUSD",PERIOD_M15,0));
Barsize=(Barcurrentopen-Barcurrentclose)*10000;
Print(Barsize);
I expected that the printed output was only changed every 15 min, instad of every tick
Any help would be appriciated..
Thanks
Allan