correction:
the loop counter i should start from 2 as the latest cross down completed in previous bar
:8 another correction:
the last cross-cross number 4 is UP and not down
calculate CondArray-s in advance, then you can check if a new loop started by checking for example:
( CondArray1[i]>CondArray2[i]) && ( CondArray1[i+1]<=CondArray2[i+1])
then you can reset your counter(s).
for(int i=1;i<=200;i--)
with this it will never work, write i++ instead of i--
that's another correction :D.yeh it ll never work.what a mistake/mistype.....you hv given the crossing condition check but i want the number of bars in the 3(three) loop formed due to 4(four) crosses.
can you clarify how to reset the counter while 'saving' the count of bar numbers in each loop for future use.if ther is another implementation idea other than this,you are highly welcome to share ..thnx
that's another correction :D.yeh it ll never work.what a mistake/mistype.....you hv given the crossing condition check but i want the number of bars in the 3(three) loop formed due to 4(four) crosses.
can you clarify how to reset the counter while 'saving' the count of bar numbers in each loop for future use.if ther is another implementation idea other than this,you are highly welcome to share ..thnx
I think of something like this below. It is not tested, maybe you will see up instead of down or bar count +1 higher.
double CondArray1[], CondArray2[]; int j,k; for(int i=1;i<=200;i++) { CondArray1[i]=iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,i); CondArray2[i]=iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,i); } int bar_cnt=0; int loop_cnt=0; for(i=1;i<=(200-1);i++) { if (( CondArray1[i]>CondArray2[i]) && ( CondArray1[i-1]<=CondArray2[i-1])) { Print("new loop #",loop_cnt," dir UP. previous loop bars count: ", cnt); bar_cnt=0; loop_cnt++; } if (( CondArray1[i]<CondArray2[i]) && ( CondArray1[i-1]>=CondArray2[i-1])) { Print("new loop #",loop_cnt," dir DOWN. previous loop bars count: ", cnt); bar_cnt=0; loop_cnt++; } bar_cnt++; }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have a problem regarding counting the number of bars that satisfied certain conditions..
conditions are
1. ema(C,8) cross down ema(C,13) in the previous bar.
2.ema(C,8) cross above ema(C,13) M number of bars back before the cross in 1.
3.ema(C,8) cross down ema(C,13) N number of bars back before the cross in 2.
4. ema(C,8) cross down ema(C,13) P number of bars back before the cross in 3.
the question is how to design a routine that does the counting of bar numbers between crosses.the graph when plotted will look like the MACD histogram.the total cross is
4(four),UP,DOWN,UP and then DOWN.Please enlightened.below are partial codes to implement the problem