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
Hi SDC,
I got it. Many thanks.
if there is 100 bar, total rates starts from 0 to 99.
At the beginning, pre_cal =0 --> limit=100 bar - 0 =100.
for(int=1 to limit=100; I++)
at the very end, I=100(index value) and there is no such bar 100.
Therefore to make the max I=99, I put limit -1;
I wonder if there is any better way.
Moreover, what make me confused is that in many other indicator, I use same approach and there is no such out of range problem.
Also, thank you for the Expert tab.
SCFX
Moreover, what make me confused is that in many other indicator, I use same approach and there is no such out of range problem.
before B600 out of range wasn't a critical error
Therefore to make the max I=99, I put limit -1;
I wonder if there is any better way.
Your code will now draw the chart history from bar 1 up without error but it wont draw for any new bars. There are many ways to code it depending what you want it to do. Look at the included indicators in metaeditor to see how the MQ coders do it. When you can read their code and understand the reason for each line you will have no problem creating indicators.
I got it now SDC.
Personally speaking, it is difficult to imagine when I read the document. Still I am not sure why prev_calculated= Total_rates -1.
So I make numerical example here. I hope it could help someone new like me.
Normally we see:
Limit= rates_total- prev_calculated; //(no-1)
OR
for(i=1;i<limit;i++) or for(i=1;i<=limit;i++)
The important thing is to make sure LIMIT >=1. In my situation, LIMIT=0 and therefore, indicator is not REFESHED when new tick coming in.
Why, let see. (I think the cause is the prev_calculated at least in my case)
Assuming that I attach the indicator when there are 100 bar on chart. Here are variables values:
First table of value
Variable
Total_rates 100
Index of bar 0-99
prev_calculated 0
Limit 100
Loop i value 1-99
Everything is good. Value will show up first time from bar 1 to the beginning of chart.How many bar already calculated? It is critical point to my mistake and I am not 100% clear.
When new bar start, on chart now 101 bar. Indicator is not updated on the already closed bar, which is now bar 1.
Second Table of value
Variable
Total_rates 101
Index of bar 0-100
prev_calculated 99 OR 100 (see below)
Limit 2 OR 1
Loop i value 1to1 OR 1 to 0
Based on the 1st table, indicator calculate 99 bar (as it loop from 1 to 99).
So the solution is quite clear: Make for(i=1; ___ this one here must be greater than 1 for (<) or greater than or equal to 1 for (<=)___; i++). In my last code, it equal to 0.However, from the document it says: “BUT if it is not the first calling of start(), the value equal to Bars-1 will be returned). So it will return 101-1=100.
This one bar different cause trouble. If system return 100 as prev_calculated.
You see that, if prev_calculated=99, the loop will work.
However, look like prev_calculated = 100 and therefore loop will not work as limit =0 or -1 depends.
Can anyone help me see the logic behind the prev_calculated= Bars-1 in this case?
I hope it helps.
SCFX
prev_calculated == rates_total
I got it now SDC.
Personally speaking, it is difficult to imagine when I read the document. Still I am not sure why prev_calculated= Total_rates -1.
SCFX
Create a new indicator put this code in the start function, attach it to a 1 minute chart and watch the alerts as the ticks arrive.
You will see rates_total is the current amount of bars.
prev_calculated is the amount of bars there were at the previous tick.
prev_calculated == rates_total
Create a new indicator put this code in the start function, attach it to a 1 minute chart and watch the alerts as the ticks arrive.
You will see rates_total is the current amount of bars.
prev_calculated is the amount of bars there were at the previous tick.
wow that's weird.
In the link posted before, they said that if :BUT if it is not the first calling of start(), the value equal to Bars-1 will be returned.
How come it return Bars (Rate_totals).
yes I know they say that but its not entirely accurate.
what actually happens is this.
rates_total == total amount of bars when the current tick arrived. prev_calculated == total amount of bars when the previous tick arrived.
Therefore you have 3 main states of prev-calculated vs rates_total. Indicator loaded, mid bar ticks, new bar first tick.
prev_calculated == 0 on first run because there was no previous tick since the indicator loaded.
Also if chart is changed or history added, prev_calculated resets back to zero.
The return value from OnCalculate is not used but it is best to use the default return(rates_total) in case they ever fix that.
I know what the new docs say. If you do it their way you have to test prev_calculated for non-zero and adjust rates_total - prev_calculated down one. That is going back to decrement indicator_counted confusion.
There is no point doing return( rates_total - 1 ) the value of prev_calculated is that as if it was return(rates_total) regardless of what you told it to return.