Now I'm confused about
what is the code actually counting and what does "limit" actually means?
will someone please help to enlighten me?
int limit, counted_bars=IndicatorCounted(); if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars;
ma30= iMA (NULL,0,30,0,MODE_EMA,PRICE_MEDIAN,shiftma);that's your largest look back. The Decrement is unneeded.
#define LOOK_BACK 30 int int(){ : SetIndexDrawBegin(..., LOOK_BACK); } int start(){ int counted_bars=IndicatorCounted(); if (counted_bars < LOOK_BACK) counted_bars = LOOK_BACK; for(int i = Bars - 1 - counted_bars; i >= 0; i--){ :
Count down, you can't make use of future bar values only past ones (i+1) when computing bar i.
If you are using values from oneBuffer[i+1] in computing secondBuffer[i], then you have TWO Look back values, use two loops one for each buffer.
Hi,
did the suggested changes to my code and noticed that now i is counting backwards vs i counting forward in the previous code.
comparing results of both code side by side, noticed that besides "i" all else is the same meaning
ExtMapBuffer1[i]=mafilter (i); ExtMapBuffer2[i]=trendstrength (i);
results are the same. both buffers depended on "i" but when "i" changes their results doesn't change according . I would be expecting them to be opposite at least.
further investigation if i were to plot "i" using forward counting and backward counting, they both yields the result . Why is so?
did the suggested changes to my code and noticed that now i is counting backwards vs i counting forward in the previous code.
>comparing results of both code side by side, noticed that besides "i" all else is the same meaning
ExtMapBuffer1[i]=mafilter (i); ExtMapBuffer2[i]=trendstrength (i);
results are the same. both buffers depended on "i" but when "i" changes their results doesn't change according . I would be expecting them to be opposite at least.
ExtMapBuffer2[limit]=trendstrength (limit);
so unless you changed it that won't work.
You macount will never work, it increments each tick.
Yes I've change the code to :
int start() { int counted_bars=IndicatorCounted();
if(counted_bars<look_back) counted_bars = look_back;
for(int i=Bars-1-counted_bars; i>=0; i--){
ExtMapBuffer1[i]=mafilter (i);
ExtMapBuffer2[i]=trendstrength (i);
ExtMapBuffer3[i]=macount(i);
}
//----
//----
return(0);
}
Now All three buffers are showing up as expected. WHen I tried to draw "i" onto the chart it is the same regardless of whether I'm counting backwards or forward .
I can't figure out why.
in this following code,
for(int i=Bars-1-counted_bars; i>=0; i--){
"i" will always be 0 since bars is always '1' ahead of counted_bars.
if the aim is to set i to be "0" why do i need the for lop to do that? I can just set all buffer to be buffer[0] manually
The first time or after a chart refresh, counted_bars will be zero and you do all bars. After that it will usually be just zero.
After a disconnect, counted_bars will be one behind the old Bars value. On reconnect Bars will have incremented by the number of new bars. You'll execute on the last bar zero with the final close value, and all new bars.
Your original code was
so unless you changed it that won't work.
You macount will never work, it increments each tick.
I've modified the code to add a loop for macount
double macount (double ped) { int count = ped; int counted_bars=IndicatorCounted(); if(counted_bars<ped) counted_bars = look_back; for(int i=Bars-1-counted_bars; i>=0; i--){ if (mafilter(count+1)==1) { countma++; return (countma); }//end if if (mafilter(count+1)==-1) { countma =0; return (countma);
But still this doesn't stop macount from counting every tick. You've mentioned about having a loop for each of the buffers calculation did i place the loop in the wrong place?
Hi
I'm back with my newly modified code.
for(int i= Bars-counted_bars-1; i>=0; i--) { Print ("i in for loop is " , i); ExtMapBuffer1[i]=mafilter (i); ExtMapBuffer2[i]=trendstrength (i); int macount; if (mafilter(i+1) ==1) { macount ++; Print ("macount add 1. macount is now." ,macount); } if (mafilter(i+1) ==-1) { macount=0; Print ("macount reset to 0. macount is now." ,macount); } ExtMapBuffer3[i]=macount; } //end for
when i'm counting the number of bars when mafilter is 1, when it comes to the lastest bar, bar(0),
the count automatically reset to 1. and no longer increment. I;m sure that the code went thru the increment part but the result just get reset to 1.
Why the program behaving this way at bar(0)?
in your pervious post you mentioned i need to have 2 loops . can you elaborate further?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I have coded an indicator (macount) to count the number consecutive high of another indicator(mafilter). but it behave very strangely. it look into the future bar for counting..
Now I'm confused about
what is the code actually counting and what does "limit" actually means?
My full code:
will someone please help to enlighten me?