I have a current TF and an estimated TF, the function should return the difference between the two TFs in any combinations, if the measurement were in bars
Calculation TF
15
15
15
60
60
60
240
240
240
Current TF
15
5
1
15
5
1
60
15
5
Difference in Nbar
1
3
15
4
12
60
4
16
48
How to implement this correctly?
I did it this way.
int TFk()
{
int K=0;
K=TF_transfer(TF)/TF_transfer(Period());
// Print(TF_transfer(TF)," ",TF_transfer(Period()));//Print (K);if (K<1)return(1);
elsereturn(K);
}
int TF_transfer(ENUM_TIMEFRAMES tf)
{
if (tf==PERIOD_CURRENT) return(0);
if (tf==PERIOD_M1) return(1);
if (tf==PERIOD_M5) return(5);
if (tf==PERIOD_M15) return(15);
if (tf==PERIOD_M30) return(30);
if (tf==PERIOD_H1) return(60);
if (tf==PERIOD_H4) return(240);
if (tf==PERIOD_D1) return(1440);
if (tf==PERIOD_W1) return(10080);
if (tf==PERIOD_MN1) return(43200);
if (tf==PERIOD_M2) return(2);
if (tf==PERIOD_M3) return(3);
if (tf==PERIOD_M4) return(4);
if (tf==PERIOD_M6) return(6);
if (tf==PERIOD_M10) return(10);
if (tf==PERIOD_M12) return(12);
if (tf==PERIOD_H2) return(120);
if (tf==PERIOD_H3) return(180);
if (tf==PERIOD_M6) return(360);
if (tf==PERIOD_H8) return(480);
if (tf==PERIOD_H12) return(720);
return(1);
}
The problem is, I need this happiness for the indicator, but it does not want to initialize itself correctly and to this code
int OnInit()
{
Print ("K=",TFk()," Период=",Period());
Can you please tell me what is the most reliableiBarShift function with two TFs right now ?
I have a task to find, for example, on a minute bar the indicator value from the upper TF, for example, M15. The timeframes can be any, which complicates the solution.
For an hour TF, I did through the structure, but if it is M15, then here I am confused...
Can you please tell me what is the most reliable iBarShift function with two TFs right now ?
I have a task to find, for example, on a minute bar the indicator value from the upper TF, for example, M15. The timeframes can be any, which complicates the solution.
For an hour TF, I did through the structure, but if it is M15, here I am confused...
So the thread is for beginners, that's why I didn't know about this feature, thanks for the tip.
Aleksey, mql4 has it a long time ago.
Aleksey Vyazmikin:
Can you please tell me what is the most reliable iBarShift function with two TFs right now ?
I have a task to find, for example, on a minute bar the value of the indicator from the upper TF, for example M15. The timeframes can be any, which complicates the solution.
For an hour TF, I did through the structure, but if it's M15, I'm confused here...
In this case you should try to forget about numbering of bars as it was in mql4. In mql5 everything is almost solved by bar time. In a pinch, you can use the Bars() function.
intBars(
string symbol_name, // имя символаENUM_TIMEFRAMES timeframe, // периодdatetime start_time, // с какой датыdatetime stop_time // по какую дату
);
Alexey Viktorov: Alexei, this has been available in mql4 for a long time.
Apparently this shows that I don't know mql4 well either, which I never claimed...
Alexey Viktorov:
And in this case try to forget about bar numbering as it was in mql4. In mql5 everything is almost solved by bar time. In a pinch, try to use the Bars() function.
Are you sure about rounding?
Suppose the time on m1 is 14:44, but I need 14:30 (first bar of M15).
Apparently this shows that I don't know mql4 very well either, which I never claimed...
Are you sure about the rounding?
Let's say the time on m1 is 14:44 and I need to get a time of 14:30 (first bar of m15).
This is something out of a different series. What do you need to get at 14:44 from the M15 bar period of 14:30? Take the function Copy**** in it put PERIOD_M15 and time 14:44 see what you get. And when the result is not what you expect, then the questions will be different.
It's something from another series. What do you need to get at 14:44 from the M15 bar period of 14:30? Take the function Copy**** in it put PERIOD_M15 and time 14:44 see what you get. And when the result is not what you expect, then the questions will be different.
Yes, that was the direction I was working in. Anyway, I got some help. Thank you, too.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Please help me with making up a function.
I have a current TF and an estimated TF, the function should return the difference between the two TFs in any combinations, if the measurement were in bars
How to implement this correctly?
I did it this way.
The problem is, I need this happiness for the indicator, but it does not want to initialize itself correctly and to this code
It reacts like this:
2017.09.22 14:23:27.742 donchian_channel_prognoz_MTF (Eu Splice,M5) K=3 Period=5
2017.09.22 14:23:27.776 donchian_channel_prognoz_MTF (Eu Splice,M5) test
2017.09.22 14:23:27.790 donchian_channel_prognoz_MTF (Eu Splice,M15) K=1 Period=15
The most confusing thing is that it prints a test that is already in the body of OnCalculate!
The first time the timeframe was defined correctly, but the second time it wasn't...
I don't know what's so strange...
I did it like this
The problem is, I need this happiness for the indicator, but it is strange and does not want to initialize correctly, in response to this code
It reacts like this:
2017.09.22 14:23:27.742 donchian_channel_prognoz_MTF (Eu Splice,M5) K=3 Period=5
2017.09.22 14:23:27.776 donchian_channel_prognoz_MTF (Eu Splice,M5) test
2017.09.22 14:23:27.790 donchian_channel_prognoz_MTF (Eu Splice,M15) K=1 Period=15
The most confusing thing is that it prints a test that is already in the body of OnCalculate!
The first time the timeframe was defined correctly, but the second time it wasn't...
I don't know what these wonders are.
Why do I have to go through all that trouble?
Isn't that easier?
What's with all the twists and turns?
Wouldn't that make it easier?
So the thread is for beginners, that's why I didn't know about this possibility, thanks for pointing it out.
Can you please tell me what is the most reliableiBarShift function with two TFs right now ?
I have a task to find, for example, on a minute bar the indicator value from the upper TF, for example, M15. The timeframes can be any, which complicates the solution.
For an hour TF, I did through the structure, but if it is M15, then here I am confused...
Can you please tell me what is the most reliable iBarShift function with two TFs right now ?
I have a task to find, for example, on a minute bar the indicator value from the upper TF, for example, M15. The timeframes can be any, which complicates the solution.
For an hour TF, I did through the structure, but if it is M15, here I am confused...
Spin this script:Searching Nearest Bar
Spin this script:Searching Nearest Bar
Thank you.
So the thread is for beginners, that's why I didn't know about this feature, thanks for the tip.
Can you please tell me what is the most reliable iBarShift function with two TFs right now ?
I have a task to find, for example, on a minute bar the value of the indicator from the upper TF, for example M15. The timeframes can be any, which complicates the solution.
For an hour TF, I did through the structure, but if it's M15, I'm confused here...
In this case you should try to forget about numbering of bars as it was in mql4. In mql5 everything is almost solved by bar time. In a pinch, you can use the Bars() function.
Alexei, this has been available in mql4 for a long time.
Apparently this shows that I don't know mql4 well either, which I never claimed...
And in this case try to forget about bar numbering as it was in mql4. In mql5 everything is almost solved by bar time. In a pinch, try to use the Bars() function.
Are you sure about rounding?
Suppose the time on m1 is 14:44, but I need 14:30 (first bar of M15).
Apparently this shows that I don't know mql4 very well either, which I never claimed...
Are you sure about the rounding?
Let's say the time on m1 is 14:44 and I need to get a time of 14:30 (first bar of m15).
This is something out of a different series. What do you need to get at 14:44 from the M15 bar period of 14:30? Take the function Copy**** in it put PERIOD_M15 and time 14:44 see what you get. And when the result is not what you expect, then the questions will be different.
It's something from another series. What do you need to get at 14:44 from the M15 bar period of 14:30? Take the function Copy**** in it put PERIOD_M15 and time 14:44 see what you get. And when the result is not what you expect, then the questions will be different.
Yes, that was the direction I was working in. Anyway, I got some help. Thank you, too.