I am trying to build a script that will recognize:
-- the highest high in the last "N" bars,
-- the Low of that "Highest High" bar and then
-- a subsequent Close below the Low of that bar as an Event.
I have tried the following (which does not work):
PriorHighBar:= Ref(HHV(H,N),1);
LowOfHighBar:= if(H > PriorHighBar, Low, 0);
LX:= C > 0 & C < LowOfHighBar;
Event: LX;
In Amibroker I would use the ValueWhen function for this purpose. for example:
SYNTAX ValueWhen(EXPRESSION, ARRAY, n = 1)
RETURNS ARRAY
FUNCTION Returns the value of the ARRAY when the EXPRESSION was true on the n -th most recent occurrence. Note: this function allows also 0 and negative values for n - this enables referencing future
EXAMPLE valuewhen( cross( close, ma(close,5) ) ,macd(), 1)
Is there a similar function in EdgeRater for this purpose or is there another way to achieve my goal?
Any assistance you can provide will be gratefully received.
Many thanks,
Fred
LowerCandleClose Event
Moderator: Chris White
-
- Posts: 212
- Joined: Mon Nov 29, 2010 9:21 pm
Re: LowerCandleClose Event
Here's an EdgeRater ChartScript that would do the job (I've used a fixed value of 20 instead of adding a parameter, but you can easily modify it to use a parameter):
The HighestHighCond line uses HHVBARS which gives the number of bars since the highest high of the last 20 bars. If the value is zero it means this bar is the highest high bar.
The LowVal line uses VALUEWHEN to get the value of L when the highest high condition was true.
Then the Event line checks for a cross of the LowVal and the Close price. The arguments are reversed so that it detects a cross below.
That should do it for you!
Chris.
Code: Select all
HighestHighCond:= HHVBARS(H, 20) == 0;
LowVal:= VALUEWHEN(L, HighestHighCond);
Event: CROSS(LowVal, C);
The LowVal line uses VALUEWHEN to get the value of L when the highest high condition was true.
Then the Event line checks for a cross of the LowVal and the Close price. The arguments are reversed so that it detects a cross below.
That should do it for you!
Chris.
Re: LowerCandleClose Event
Thank you, Chris. Very much appreciated!
Fred
Fred