


scfx:.
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; //(no1) 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 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 Based on the 1st table, indicator calculate 99 bar (as it loop from 1 to 99). int pcal=prev_calculated; if(prev_calculated>0) pcal; int limit=rates_totalpcal; for(int i=1;i<=limit ;i++) //it is <= //OR  int limit=rates_totalprev_calculated1; if(limit<=0) limit=2; //NOT limit for(int i=1;i<=limit ;i++) //it is <= I hope it helps.
SCFX 

prev_calculated == rates_total scfx:
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. Alert("rt = ",rates_total," pc = ",prev_calculated); You will see rates_total is the current amount of bars. prev_calculated is the amount of bars there were at the previous tick.


SDC: 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.
In the link posted before, they said that if :BUT if it is not the first calling of start(), the value equal to Bars1 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 prevcalculated 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.






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