Hello,
As an exercise in Basic Metastock Programming, is it possible to use
the MSFL to create the Parabolic SAR from scratch?
Yes, I do realize MSFL has the SAR() function, MS has the SAR indicator,
and there are probably many DLLs out there, and I have studied the MSFL functions in the User's Guide until I am cross-eyed.
If it is possible to program the SAR, perhaps someone in this forum
might use this as an example to demonstrate the power of the MSFL to us
less-experienced basic programmers? PREV and Ref()? If it
cannot be done, perhaps this would a good place to explain the restrictions?
If anyone is interested, here is the attempt with lots of commented documentation.
Thanks!
=======================================================
{ SAR METASTOCK LANGUAGE }
{ }
{ POS = 1
means Long Position; 0 means Short. }
{ We start
with Long }
{ Use Long
and Short Booleans to improve code readability }
{ Start with
the maximum Acceleration Factor}
{ Start with
SAR equal to the Low}
{ Start with
the Extreme Price equal to the High}
{ Calculate
the Acceleration Factor First{ If the
position changes, reset AF to 0.02{ If the
position does not change: }
{ }
{ }
{
AND H>Ref(H,-1) ) OR (Short AND L<Ref(L,-1)),
{ increment, but don’t exceed max AF}
{If Long,
the Extreme Price is the highest high }
{If Short,
it is the lowest low. If(long AND H>PREV, H, If(short AND
L<PREV, L, PREV));
{ Calculate
SAR from yesterday’s values{ This had
to be broken down into NewSAR{ to avoid
MSFL binary overflow. :=
{Now we have
a new SAR, do we need a new position?}
{ Switch to Short
If(Short AND MySAR<H,1, { Switch to LongPREV)); { Otherwise don't change }
{ Change
Short and Long as appropriate for new position.Long
:= If(POS,1,0);
|