.
Anyone?
Pleeeassseee... I'm stuck in this... :(
.
.
Still doesnt know how I get this.. :(
Anyone please... ?
.
Use iCustom
code below is not tested nor compiled.
int number = 5, count = 0, pos; double data_1, data_2; for (pos = 0 ; pos < Bars ; pos ++) { data_1 = iCustom (NULL, 0, "..." , ... , buffer, pos); data_2 = iCustom (NULL, 0, "..." , ... , buffer, pos + 1); if (data_1 > 0 && data_2 <= 0) { count ++; // draw object Vertical line on Time [pos + 1] } else { if (data_1 < 0 && data_2 >= 0) { count ++; // draw object Vertical line on Time [pos + 1] } } if (count == number) break; }
.
Thank you very much phi.nuts! :)
But.. I'm afraid that your code doesn't help me because I need the values of the last five crosses to use after..
In my code I have 5 FOR cylcles in order to get the 5 values (Distances A, B, C, D and E).
.
.
Thank you very much phi.nuts! :)
But.. I'm afraid that your code doesn't help me because I need the values of the last five crosses to use after..
In my code I have 5 FOR cylcles in order to get the 5 values (Distances A, B, C, D and E).
.
.
Sory RaptorUK but I don't know how can a While loop help me in here!
After the cycle I need to have those 5 distances (see the big blue arrows in 1st post picture) like this:
DIST_A = xx
DIST_B = xx
DIST_C = xx
DIST_D = xx
DIST_E = xx
The only way I see to get it is with those for loops:
1st FOR (starting in actual candle)
2nd FOR (starting in actual minus DIST_A)
3th FOR (starting in actual minus DIST_B)
and so on...
But this is my newbie programmer brain working... :(
.
Sory RaptorUK but I don't know how can a While loop help me in here!
After the cycle I need to have those 5 distances (see the big blue arrows in 1st post picture) like this:
DIST_A = xx
DIST_B = xx
DIST_C = xx
DIST_D = xx
DIST_E = xx
The only way I see to get it is with those for loops:
1st FOR (starting in actual candle)
2nd FOR (starting in actual minus DIST_A)
3th FOR (starting in actual minus DIST_B)
and so on...
But this is my newbie programmer brain working... :(
Just thinking aloud . . . .
int index = 0, CrossAt[5], ArrayIndex = 0; while(ArrayIndex <= 5) { // code to find cross at bar number index // if cross found CrossAt[ArrayIndex] = index; ArrayIndex++; index++; }
.
I think I understand your idea.. less code lines indeed.. : )
But I Still can't get those distance values... : (
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Custom indicator iteration function // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int start() { int Barras; int counted_bars=IndicatorCounted(); //---- check for possible errors if (counted_bars<0) return(-1); //---- last counted bar will be recounted if (counted_bars>0) counted_bars--; Barras=Bars-counted_bars; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Calculate distances A,B,C,D,E // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int index, CrossAt[5], ArrayIndex = 0; while(ArrayIndex <= 5) { // code to find cross at bar number index for(index=0; index<Barras; index++) { DIF_MA[index]=(iMA(NULL,0, Fast_Period, 0, 0, 0, index)) - (iMA(NULL,0, Slow_Period, 0, 0, 0, index)); // if cross found if( (DIF_MA[index]>0 && DIF_MA[index+1]<0) || (DIF_MA[index]<0 && DIF_MA[index+1]>0) ) { CrossAt[ArrayIndex] = index; ArrayIndex++; index++; } } } // after that... int DIST_A = CrossAt[1]; int DIST_B = CrossAt[2]; int DIST_C = CrossAt[3]; int DIST_D = CrossAt[4]; int DIST_E = CrossAt[5]; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
.
I think I understand your idea.. less code lines indeed.. : )
But I Still can't get those distance values... : (
I don't do much with Indicators so I might be very rusty . . . but, to identify a cross don't you need to check the situation at 3 positions, the index bar, the bar before and the bar after ? to look for the change of state ?
There are several problems in your code . . . index++; is not dependant of there being a cross . . . take it out of that if statement, what is the for loop for ? and why are you using index in the for loop, you need to use a different variable . . .
to identify a cross don't you need to check the situation at 3 positions, the index bar, the bar before and the bar after ? to look for the change of state ?
My thought is:
( Before below zero ) & ( Present above zero ) => There was a zero cross!
( Before above zero ) & ( Present below zero ) => There was a zero cross!
index++; is not dependant of there being a cross . . . take it out of that if statement
Absolutely right!
what is the for loop for ?
I can only say that I might be "FOR loop adicted"!!! :P
and why are you using index in the for loop, you need to use a different variable . . .
I'm not used to the WHILE loop. Sory about the confusion...
- 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,
Im making an indicator that needs this distances:
The indicator in the picture is the difference between two Moving Averages (MA_4 and MA_150).
And the idea was to retrieve the distances to the last 5 "zeros" in the indicator.. :(
I've wrote this piece of code but it gives me DistA = DistB = DistC = DistD = DistE = 0 !!
Can someone help me here please!