Ken,

 

I missed that. Hopefully this is somewhat on track with your request :-)

 

Try using BarsSince(Buy,1) as the length of your HHV lookback. You may
further want to qualify and only calculate this only on a Sell signal. It
would look something like this:

 

X = IIf(Sell,HHV(CurEq2, BarsSince(Buy,1), 0);

 

Then to pick the highest from within these choices:

 

MaxEq2 = Highest(MaxEq2);

 

Without testing, it seems that the net of this is the same as your original
statement, just without the intermediate step of computing the highest value
during each buy period. 

 

If you want the DD in % since a Buy, then add a calculation to compute the
DD during the buy periods first:

 

PeriodDD = (CurEq2 - ValueWhen(Buy, CurEq2,1)) / ValueWhen(Buy, CurEq2,1); 

X        = IIf(Sell,HHV(PeriodDD, BarsSince(Buy,1), 0); 

MaxEq2   = Highest(MaxEq2);

--

Terry

-----Original Message-----
From: amibroker@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf
Of Ken Close
Sent: Saturday, January 20, 2007 10:23
To: amibroker@yahoogroups.com
Subject: RE: [amibroker] Logic for MaxDD while in a Buy Period

 

Terry: thanks for commenting, but that is not what I want.  As I said, I am
trying to determine the Largest (Max) drawdown from within all of the Buy
periods.  Each Buy period will see some amount of drawdown while the Buy is
on.   I want to determine the largest of these drawdowns from within each
Buy period.  See my other reply to Fred for still another way of describing
what I am trying to calculate.

 

Ken

 

  _____  

From: amibroker@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf
Of Terry
Sent: Saturday, January 20, 2007 11:39 AM
To: amibroker@yahoogroups.com
Subject: RE: [amibroker] Logic for MaxDD while in a Buy Period

Highest includes the current bar and all past bars for each bar. If it
included the NEXT bar you would be looking into the future which, unless you
are on the last bar of data, is not "known" yet. However, if this is what
you want just do this:

 

MaxEq2      =     LastValue(Highest(CurEq2));

 

--

Terry

-----Original Message-----
From: amibroker@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf
Of Ken Close
Sent: Saturday, January 20, 2007 08:06
To: amibroker@yahoogroups.com
Subject: [amibroker] Logic for MaxDD while in a Buy Period

 

I can not get the logic written to take care of a special case.

 

My objective is to determine the MaxDD in an equity curve (or the Close
Price line) while a signal is on a Buy.

 

I have used the following code snippit:

 

CurEq2      =     Gain2chrt;

MaxEq2      =     Highest(CurEq2);

CurDD2      =     IIf(BIR, 100 * (MaxEq2 - CurEq2) / MaxEq2, 0);

MaxDD2      =     Highest(CurDD2);

 

 

In most cases this is producing the correct answer, but I have discovered
certain cases where it delivers the wrong answer.

 

If the price (or Equity curve) has a down period in the NEXT buy period, the
code will still have as the HIGHEST value, the value from the PREVIOUS buy
period. This produces an incorrect value.   The Highest function is looking
for the highest value in the array MaxEq2 no matter when it occurred.   I
have not been able to figure out how to use the HHV function as the length
of the buy periods varies. 

 

How can I write this logic so that the MaxEq2 variable will "reset" after
each Buy period expires, and be ready to determine the largest value in each
new Buy Period?

 

Thanks for any help.

 

Ken

 

 

 

 

Reply via email to