Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 10/28/2004(UTC) Posts: 3,111 Location: Perth, Western Australia
Was thanked: 16 time(s) in 16 post(s)
|
Amory, Lets say we have a condition: Code:
condition:=
CLOSE > Ref(LOW,-1) AND
CLOSE > Ref(CLOSE,-1) AND
CLOSE > OPEN;
We can find if the condition is true on the very last bar (in an exploration, but this can be used in indicator functions too) without using the Alert() function: Code:
condition:=
CLOSE > Ref(LOW,-1) AND
CLOSE > Ref(CLOSE,-1) AND
CLOSE > OPEN;
{this is the important bit}
condition;
The 'condition' variable returns a boolean or binary value, TRUE or 1 if the criteria are met, or FALSE or 0 if the criteria are not met. The important bit says, "The value of the 'condition' variable must be TRUE or not-zero", so our filter will return all those stocks where the condition is met on the last bar of data. What happens prior to the last bar is not regarded in this filter. You can extend any condition using the Alert() function.
If we want to find the stocks where the condition is met in the last, say 5 bars, we can use the Alert() function: Code:
condition:=
CLOSE > Ref(LOW,-1) AND
CLOSE > Ref(CLOSE,-1) AND
CLOSE > OPEN;
{this is the important bit}
Alert(condition,5);
The long way of writing out what the Alert() function is doing in this case is like: Code:
condition=1 OR
Ref(condition, -1)=1 OR
Ref(condition, -2)=1 OR
Ref(condition, -3)=1 OR
Ref(condition, -4)=1;
Using the Alert() function, we dont care WHEN with the lookback period the event happened, we only care that it happened, so the event must have happened AT LEAST once in the period. (There are other methods that will tell us if the condition EXACTLY x-many times) To now get to the state when we need to know the condition on the last bar, we can use the Alert() function, but we add the final condition too: Code:
condition:=
CLOSE > Ref(LOW,-1) AND
CLOSE > Ref(CLOSE,-1) AND
CLOSE > OPEN;
{this is the important bit}
condition=0 AND Alert(condition,5);
We can do this in this case because we want the condition on the last bar to be false. What would happen if we said the condition had to be true on the last bar? If the condition is true on the last bar, then the Alert() function would also be true! To find for example a system when the condition must have been true on the last bar AND the condition must have been true in the preceeding bars we can use the Alert() function set back using the Ref() function: Code:
condition:=
CLOSE > Ref(LOW,-1) AND
CLOSE > Ref(CLOSE,-1) AND
CLOSE > OPEN;
{this is the important bit}
condition AND Ref(Alert(condition,4),-1);
Note we changed the lenght of the Alert function to account for the lookback period. Like with all things computing there is another way to find when a condition has happened in a defined period, or even how many times the event has happened in a deined period, or find out when events in defined periods using the Sum() function as a counter! Code:
condition:=
CLOSE > Ref(LOW,-1) AND
CLOSE > Ref(CLOSE,-1) AND
CLOSE > OPEN;
{this is the important bit}
Sum(condition,5)>1;
would find those stocks which met the condition EXACTLY once in the last 5 bars Code:
condition:=
CLOSE > Ref(LOW,-1) AND
CLOSE > Ref(CLOSE,-1) AND
CLOSE > OPEN;
{this is the important bit}
Sum(condition,5)>=1;
would find those stocks which met the condition AT LEAST once in the last 5 bars. Code:
condition:=
CLOSE > Ref(LOW,-1) AND
CLOSE > Ref(CLOSE,-1) AND
CLOSE > OPEN;
{this is the important bit}
conditon=0 AND Sum(condition,5)>=1;
would find those stocks where the condition was not met on the last bar, but was met at least once in the last 5 bars... Code:
condition:=
CLOSE > Ref(LOW,-1) AND
CLOSE > Ref(CLOSE,-1) AND
CLOSE > OPEN;
{this is the important bit}
condition=1 AND Ref(Sum(condition,4),-1)=1;
would find those stocks where the condition was true on the last bar and the condition only happened once in the 4 bars previous to thelast bar (ie the last 5 bars)... etc etc etc Hope this helps. wabbit [:D]
|