PureBytes Links
Trading Reference Links
|
On Apr 14, 8:05pm, Phil wrote:
> Subject: Help with code?
> I got the following full moon code from a friend. I am trying to study
> different codes to try to understand them so I can learn more about how to
> write code on my own. I would like someone to explain what each line does
> and means in the code below?
this is probably not the best example to start cutting your teeth on,
but here goes:
Datetojulian(d), converts d expresses as yymmdd into a single
number that is the "Julian Date". 29.531 (more/less) is the
number of days in a full lunar cycle. 27503.3 is the julian
date for a particular date (and time) when there was a full moon.
>
> begin
> var:z(0);
> If currentbar=1 then begin
> z=27303.3;
> While z<=datetojulian(date) begin
> z=z + 29.531;
> end;
> end;
So the loop above starts at known point, and keeps advancing 'z'
until z is the date/time (expressed as a julian date) of the
_next_ full moon after the date of the first bar (notice the
if on currentbar = 1).
below, intportion simply throws away the fractional part of
number so intportion(29.5) is 29, for example. the if statement
is testing if the current date is the day of the next full moon.
If it is, then z is advanced to the date/time of the next full
moon.
>
> if intportion(z)=datetojulian(date) then begin
> z=z+ 29.531;
> end;
>
the if below tests to see if this bar's date follows a full, and
the full moon date/time has not yet advanced. I think this if
is to cover the situation where the full moon occurred over a
weekend or trading holiday.
> if z-1<datetojulian(date) then z=z+29.531;
the if below compares this bar's 'z' value (the date/time of the next
full moon, expressed as a julian date) has increased, which means
this bar is the bar following a full moon.
> if z>z[1] then begin
>
> plot1( high, "Full Moon");
> plot2 (low," Full Moon");
The plot statements above plots today's high/low when its a full moon.
Not sure what the author had in mind here.
>
> end;
>
> END;
>
--
| Gary Funck, Intrepid Technology, gary@xxxxxxxxxxxx, (650) 964-8135
|