Questions from Beginners MQL5 MT5 MetaTrader 5 - page 530
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
Please help! (MQL4)
I need to get the opening time of the Day on M15 chart taking into account each bar - for the indicator.
I decided to calculate in seconds, taking into account the current bar (0), but I must be mistaken.
D_Shift=(Open_time-pos*15*60-(Open_time-Open_timeTF))/1440*60;
If for the indicator, then:
But: this code will be executed each time OnCalculate() is entered - depending on your needs, you can add bool flag or place code in separate function.
If for indicator, then:
But: this code will be executed each time OnCalculate() - depending on your needs, or add a bool flag or place the code in a separate function.
Thanks, but at every tick to do recalculation is not good - I need to analyze your code, however, while I want to understand why my code does not work, in the log are returned strange numbers
it turns out that there is a difference of 479 bars between the first bar of the day and the current bar - why is that?
Thanks, but recalculating on every tick is not good - I need to think about your code, however, while I want to understand why my code does not work, the log returns strange numbers
it turns out that there is a difference of 479 bars between the first bar of the day and the current bar - why is that?
I did indicate that I'm not psychic and that's why:
But: this code will be executed each time OnCalculate() is entered- here depending on your needs either add abool flagor put the code in a separate function.
I did point out that I'm not psychic and that's why:
Karputov Vladimir, I don't understand your code - I'm a beginner in this business and Ihaven't used functionOnCalculate before, so I can't understand whatrates_totalis calculated there and, more importantly, where it should be returned to? I don't understand how to make it all into a separate function either... it's hard to understand without comments.
Here is the full code of the MQL4 indicator:
Algorithm of its work: When you start indicator, you set timer time interval (for example, 10 seconds) - it means that every 10 seconds timer will be triggered:
and theIsDefineTime variable is assigned the value true. What is it for? When IsDefineTime=true we can, in OnCalculate(), enter a loop to determine the start time of the day:
In this loop We start traversing the time[] array (this array stores the opening time values) from the rightmost bar (its index is "0"). When the beginning of the day is found, we unset its value and assign to the variableIsDefineTime the valuefalse - in this way we protect ourselves from further entering into the cycle of determining the starting time of the day, until the timer runs again.
Karputov Vladimir , thanks for the clarification, however, how does this solve the problem?
Roughly speaking we need to know the bar of the current timeframe that corresponds to the bar at the beginning of the day. We need to know on each bar and calculate and draw the indicator accordingly.
Karputov Vladimir , thanks for the clarification, however, how does this solve the problem?
Roughly speaking we need to know the bar of the current timeframe that corresponds to the bar at the beginning of the day. You need to know it on every bar and calculate and draw the indicator accordingly.
That's how you asked and that's how you were answered :) . And if you want not the time of the first bar of this day, but the index of this bar - it is here, when you print the beginning of the day:
You use the index [i-1] - this is the number of the first bar of the day.
As you asked, you got your answer :) . And if you need not the time of the first bar of the day, but the index of this bar, it is here, when you print the beginning of the day:
You use the index [i-1] - this is the number of the first bar of the day.
I agree - I asked confusingly.
There's an indicator in the app that I made, but it doesn't count correctly. I'm terribly dumb and do not understand, even after your explanations, how to make it correctly determine the index corresponding to the first bar at the beginning of the day.
I apologize for the insolence, but maybe you can show me how to combine your code and mine?
-Aleks-:
How do I get it to correctly detect the index corresponding to the first bar at the start of the day?
It's a bit of a mess: