It's just a tiny little indicator to check the local existence of the bars that is started on GBPUSD H1 of the MQ-Demo account:
this prints:
So why is
- _Period = 16385 instead of 60 (min) for H1
- TERMINAL_MAXBARS == 11 <= this is a joke isn't it?
_Period on a H1 chart (PERIOD_H1) has never been 60 with mql5. Never use the numeric value when there is symbolic constant associated.
TERMINAL_MAXBARS usage is :
TerminalInfoInteger(TERMINAL_MAXBARS)
_Period on a H1 chart (PERIOD_H1) has never been 60 with mql5. Never use the numeric value when there is symbolic constant associated.
TERMINAL_MAXBARS usage is :
Thanks - I got it!
Now it prints:
Wow: 100'000'000 H1 bars = ~ 11'500 years of historic quotes - the currency was flint stone that time right?
But do you know hoe do I get the correct value for _Period: EnumToString(PERIOD_CURRENT) prints PERIOD_CURRENT .
I am blocked due to the conventions of MQ4 :(
Thanks - I got it!
But do you know hoe do I get the correct value for _Period: EnumToString(PERIOD_CURRENT) prints PERIOD_CURRENT .
I am blocked due to the conventions of MQ4 :(
Use EnumToString(ChartPeriod()).
Thank you!
Let me continue and call this indicator by a tiny simple script:
The (corrected) indicator:
//+------------------------------------------------------------------+ //| HaveAllQuotes.mq5 | //+------------------------------------------------------------------+ #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 #property indicator_type1 DRAW_NONE #property indicator_label1 "AllQts" //--- input parameters input int NoBars=0; int _NoBars; double B[]; int OnInit() { _NoBars = NoBars <= 0 ? 100000 : NoBars; //--- buffer mapping SetIndexBuffer(0,B,INDICATOR_DATA); PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,0); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { //--- Print("HaveAllQts Sym: ",_Symbol," Per: ",EnumToString(ChartPeriod())," tL: ",TimeToString(TimeLocal(),TIME_DATE|TIME_SECONDS)," TermMax: ",TerminalInfoInteger(TERMINAL_MAXBARS), " _NoBars ",_NoBars," rts_Tot: ",rates_total," prvClc ",prev_calculated, " => ",(rates_total<_NoBars) ); if ( rates_total < _NoBars ) return(0); return(rates_total); }
And the script calling it:
//+------------------------------------------------------------------+ //| Test_HaveAllQuotes.mq5 | //+------------------------------------------------------------------+ void OnStart() { //--- int Hdl = iCustom(_Symbol,_Period, "HaveAllQuotes",0, 0,0 ), nB = BarsCalculated(Hdl); Print("Hdl ",Hdl," nB ",nB," er: ",_LastError ); }
This prints in the Expert log:
2018.10.20 22:44:27.863 Test_HaveAllQuotes (GBPUSD,H1) Hdl 10 nB -1 er: 4806 (= ERR_INDICATOR_DATA_NOT_FOUND)
Any idea?
Let me continue and call this indicator by a tiny simple script:
The (corrected) indicator:
And the script calling it:
This prints in the Expert log:
Any idea?
You have to call CopyBuffer first.
Let me continue and call this indicator by a tiny simple script:
The (corrected) indicator:
And the script calling it:
This prints in the Expert log:
Any idea?
As nicholishen said, 2 steps are needed.
Please search the site, there are a lot of resources on how to use custom indicators (iCustom) with mql5.
I guess not as CopyBuffer is needed to get the values of an indicator (which I am not interested in) - see this indicator:
#define RESET 0 ... int OnCalculate(const int rates_total, // number of bars in history at the current tick const int prev_calculated,// number of bars calculated at previous call const int begin, // bars reliable counting beginning index const double &price[]) // price array for calculation of the indicator { //---- checking the number of bars to be enough for the calculation if(BarsCalculated(BandsHandle)<rates_total || BarsCalculated(BearsHandle)<rates_total || BarsCalculated(BullsHandle)<rates_total || rates_total<min_rates_total) return(RESET); ...
To me BarsCalculated() returns what the indicator's function OnCalculate() has returned. And my 'indicator' returns either 0 or rates_total - so...?
I guess not as CopyBuffer is needed to get the values of an indicator (which I am not interested in) - see this indicator:
To me BarsCalculated() returns what the indicator's function OnCalculate() has returned. And my 'indicator' returns either 0 or rates_total - so...?
You are right on CopyBuffer(). The problem is due to the indicator not yet calculated when you call BarsCalculated(). iCustom() is asynchronous. You have to deal with it (there is at least 1 topic with solution about this somewhere on the forum).
Do you remember additional terms I can search for?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
It's just a tiny little indicator to check the local existence of the bars that is started on GBPUSD H1 of the MQ-Demo account:
this prints:
2018.10.20 21:25:19.234 HaveAllQuotes (GBPUSD,H1) HaveAllQts Sym: GBPUSD Per: 16385 tL: 2018.10.20 21:25:19 TermMax: 11 _NoBars 11 rts_Tot: 101825 prvClc 0
So why is