[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Help with coding PREV alternative



PureBytes Links

Trading Reference Links

Paul/Graham, have tried both suggestions and I cannot get it to work.

Let me explain in more detail as I did a pretty poor job last time:      
:-(

I have a metastock formula for a 21 day initial high entry trigger that 
I am trying to convert. In words the logic is:

"If the HIGH of 20 days ago is >= to the highest value in the last 20 
periods then use the highest high
else
If the HIGH of 20 periods ago is < highest high in the last 20 periods 
then use the prior bars high."

In other words it is looking for 20 days where the all the highs are 
lower than the high of 21 days ago. It is looking for the initial high 
reversal.

the metastock formula is

IH = Input("Initial High", 1, 300, 21);
HH = IH - 1;
if(Ref(HIGH,-HH)>=HHV(HIGH,HH),HHV(HIGH,HH),if(Ref(HIGH,-HH)<HHV(HIGH,HH),PREV,0));

My attempt at converting this, including Graham's suggestion is as follows:

IH_Periods = Param("Initial High", 21, 10, 100,1);
HH = IH_Periods - 1;

A = Ref(H,-HH);   // High of 20 periods ago
B = HHV(H,HH);  // Highest High in 20 periods
Z = HHV(H,HH);

PREV = Z;
for(i=1;i<BarCount;i++)
{
if(A[i] < B[i]) PREV[i] = Z[i];
else PREV[i] = Z[i-1]; // PREV is previous value of Z.
}

High_DOTS = IIf(A >= B, B, IIf(A < B,prev, 0));

Plot(High_DOTS, " DOTS", colorBlack, 8+16);
Plot(C, "Price", ColorBlack, StyleBars);

The problem is that it (see attachment) bar at A is less than 20 days 
(13 days) from Y therefore the dots should have continued at the X level 
and not stepped up to the higher value. B (14 days) and C (15 days) 
should also be at the X level.

Appreciate the help.

Keith
ps. this is my first attempt at a loop and also converting a Metastock 
formula.



Paul Ho wrote:
> you have assign z = 0; the whole z array equal to 0, so z[i -1] is of 
> course 0;
> try z[0] = 0 instead and use prev[i] instead of constant PREV.
>
> ------------------------------------------------------------------------
> *From:* amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] 
> *On Behalf Of *Keith Osborne
> *Sent:* Tuesday, 20 February 2007 2:54 PM
> *To:* amibroker@xxxxxxxxxxxxxxx
> *Subject:* [amibroker] Help with coding PREV alternative
>
> Hi, I am attempting to convert a Metastock formula with a PREV
> statement. I have read a number of messages in Amibroker database and my
> attempt is as follows.
>
> IH_Periods = Param("Initial High", 21, 10, 100,1);
>
> HH = IH_Periods - 1;
>
> Z = HHV(H,HH);
> Z = 0; // Initialize
> for(i=1;i<BarCount;i++)
> {
> PREV = Z[i-1]; // PREV is previous value of Z.
> }
>
> When I use PREV in a AB formula such as iif(A > B, XX, PREV) I get 0
> (Zero) when A<B.......rather than the previous value of Z. Can I assign
> a HHV to Z?)
>
> I hope I have explained this.
>
> Any help would be appreciated.
>
> TIA .... Keith
>
>  


Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

PNG image