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)
|
Not quite. ValueWhen(1,stoch(5,3) > 75,close) will give you the closing price on the last instance when the criteria was true. By example todoy, the stoch is below 75, so the code returns the close the last time the stoch was above 75 (this might have been some time ago). On the next bar the stoch moves above 75, so the code returns the close on that bar. This is good. The next bar the stoch is still above 75, so the code ruturns the close on that bar, but we only want when the stoch moves above 75 for the first time.
Use some more code to trigger when the stoch moves from below the 75 line to above it. You could use the Cross() function, but I think the following code is better and more flexible:
x:=stoch(5,3);
y:=x>75 and alert(x<=75,2);
this says the stoch today is aboove 75 and in the last two days the stoch has been equal to or below 75 (if today is > 75 then yesterday must have been <= 75, hence the crossing)
You now measure the close on this event:
valuewhen(1,y,c)
But remember, this will still return the value of the close on the first instance when the stoch crossed the 75 line, even though on the latest bar the stoch may have fallen below 75. You can make up another criteria that says, if the stoch is still above 75 then return the price the first time is moved up, or if the stoch is below 75 return another number (0, -1 , or something else?)
(x>75)*valuewhen(1,y,c);
or another way:
if(x>75, valuewhen(1,y,c), -1)
Hope this helps.
wabbit :D
|