You'll find these useful I think...
Time to string
https://docs.mql4.com/convert/TimeToStr
Finding new bars...
int start() { Fun_New_Bar(); if (New_Bar) { //DO new bar stuff } } void Fun_New_Bar() { static datetime New_Time = 0; New_Bar = false; if (New_Time!= Time[0]) { New_Time = Time[0]; New_Bar = true; } }
hth
V
Yeah, cool. It doesn't matter how many times you read it in the book you can't beat real feedback.
Thanks
V
ha ha, don't assume I'm some guru or something, that was an honest question! I just so happen to be shopping for a better new-bar detection scheme versus my current implementation and I stumbled across your post. So...seriously is there any reason not to use a bool function like what I proposed? Is there a known weakness to this approach? Is it less robust than an alternative implementation? Eager minds await the answer!
ha ha, don't assume I'm some guru or something, that was an honest question! I just so happen to be shopping for a better new-bar detection scheme versus my current implementation and I stumbled across your post. So...seriously is there any reason not to use a bool function like what I proposed? Is there a known weakness to this approach? Is it less robust than an alternative implementation? Eager minds await the answer!
You're a guru in my eyes Phil, but don't let it go to your head... Gordon and CB have God status :)
I picked that function up from the book I think or maybe something Russel posted... I do remember at the time trying to call it within the If but had trouble... I think that trouble may have been to do with the fact the function was declared as VOID rather than as you have done as a BOOL. I got it to work as I posted and thought no more of it.
However, to offer an opinion on which is more efficient... The flow of my code swaps from using tick to new bar information in 3 or 4 seperate places. I call Fun_New_Bar to set New_Bar as true or false at the head of start and then simply test if(New_Bar)... Presumably if I were to call the full function every time for something I already knew the answer to, this would be less efficient, but if it was being called once, then I think your method is crisper.
V
bool newBar; int start() { static datetime Time0; newBar = Time[0] > Time0; if (newBar) { Time0 = Time[0]; double barClosePrice = Close[1];
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, Learning MQ4.. so need help on some basic things
Following is what I need to find:
1. I need to find bar close price only when the bar is closed.
2. How do I identify the time in Mq4 in this format : HH:MM:SS ?
1) To achieve the first one - I coded like this,, does this really provide the close price of the last candle, that just closed ?
extern int StartHour = 10;
extern int GMToffset = 2;
extern int EndHour = 14;
In start section:
liHour = Hour();
if (liHour == EndHour + GMToffset)
double lclose = iClose(Symbol(),0,0); // getting the closed price of 7 AM (PST)candle;
2) Now I need to implement some other logic as soon as the new bar starts
I was thinking of using seconds parameter along with minutes and hour ..(if that is good) buy only after the last bar close.. If I simply use "
Please help..