PureBytes Links
Trading Reference Links
|
At 2:59 PM -0500 3/7/99, Sentinel Trading wrote:
>In using a start date to turn a system on will placing the start date in front
>of a moving average of 50 days for example cause the system to start
>calculating
>the 50 day moving average after the start date?
>
>Ex. If Date > StartDate then begin if Close Crosses above Average(Close,50)
>Then Buy High + 1 point Stop;
>
>If so then would it be correct to place the start date after all other
>conditions need more bars back that the start date would allow?
>
>Ex. If Close Crosses Above Average(Close,50) Then Begin If Date > Start Date
>Then Buy High + 1 Point Stop;
>
>Thanks for any help.
This is a fairly complicated issue with TradeStation. The simplest solution
is to equate the "Average" to a variable so that you know it is being
calculated on each bar. The following two versions are equivalent and make
sure the Average function is calculated properly.
Ave1 = Average(Close, 50);
If Date > StartDate then begin
if Close Crosses above Ave1 then
Buy High + 1 point Stop;
end;
If Close Crosses Above Ave1 then begin
If Date > StartDate then
Buy High + 1 Point Stop;
end;
The complicated answer to your question gets pretty involved. You will
notice that TradeStation has what are called Series functions and Simple
functions. Series functions are actually pulled out of the code and
evaluated separately on each bar, even if your code does not call them on
each bar. Simple functions are evaluated as they are called and thus would
not be evaluated on every bar in your example.
Normally, you can tell which kind of function you are using because when
you write the code for the function, you can specify its type in the
"Properties" dialog box. But is your case, you called the "Average"
function and you will notice that this function (as well as many others) is
available in both Series and Simple versions. Now TradeStation uses some
method to decide which version to use when you call the Average function. I
don't know how it decides this and probably wouldn't trust it even if I
knew. So in your example, I cannot tell which version it would use. Perhaps
someone knows and could enlighten us.
This is one of those things that TradeStation did to make it "easy" for
non-programmers to use the language. Often it works fine. Sometimes it
doesn't work correctly and the user doesn't discover it until the code
doesn't work as expected. But in some cases like the one in your example,
there is ambiguity.
I have learned to ALWAYS equate every TradeStation function to a variable
and then use the variable in a subsequent expression if I want to be sure
the function works as I want it to (as per my example above). There are
many examples of where functions work one way in some expressions and work
another way in other expressions (especially in Print statements).
Bob Fulks
|