PureBytes Links
Trading Reference Links
|
I'm trying to create a simple indicator that tells me the number of
days a stock has closed above or below a pivot point moving average.
At least it sounded simple when I started. Everything works great
except for the portion of the indicator that computes the total number
of days.
Basically, if a stock closes above a pivot point MA that's 1 day. If
the stock closed above the pivot point MA the previous day that would
be todays value (1 day) Plus yesterdays value (1 day)=2 days. If on
the third day the stock closed above the pivot point MA that would be
yesterdays value (2 in this case) plus 1 for today =3.
So, here's the code: (I left out the indicator portion of the code)
*************************************
day_h=H[BarCount-1];
day_l=L[BarCount-1];
day_c=C[BarCount-1];
ConsDays[1]=0; //initialize the consecutive days array...first value is 0
Temp1=0;
Temp2=0;
/*--------------------------------------*/
// day
DH=day_h;
DL=day_l;
DC=day_c;
// DAY PIVOT Calculation
pd = ( H+ L + C )/3;
sd1 = (2*pd)-H;
sd2 = pd -H + L;
rd1 = (2*pd)-L;
rd2 = pd +H -L;
ppMA=MA(pd,3);
AboveBelowMA=IIf(C>=Ref(ppMA,-1),(C-Ref(ppMA,-1)),(C-Ref(ppMA,-1)));
//AboveBelowpp=IIf(C>=Ref(pd,-1),(C-Ref(pd,-1)),(Ref(pd,-1)-C));
/*The following code takes the data from the array above and adds a +1
to the ConsDays array from yesterday
if the AboveBelowMA is positive. If the value for ConsDays (from
yesterday) is a positive value and today the value is below the MA
(resulting from a reversal or a price move that results in a close
below the MA) then the ConsDays value is reset to 0
*/
ConsDays=Ref(ConsDays,-1)+IIf(AboveBelowMA>=0,1,-1);
**************************
For whatever reason the AFL is seeing the Ref(ConsDays,-1) as Zero
each time...I'm not sure why it's doing that. For whatever reason
trying to add a value from yesterday to a value from today is not
functioning.
Any ideas?
Paul
Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.37/682 - Release Date: 2/12/2007 1:23 PM
|