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

Re: [amibroker] Drawdown Calculation


  • Date: Fri, 05 Mar 2010 13:38:11 +0100
  • From: Tomasz Janeczko <groups@xxxxxxxxxxxxx>
  • Subject: Re: [amibroker] Drawdown Calculation

PureBytes Links

Trading Reference Links



Hello,

You should better use array functions.

dtstart = StrToDateTime(From);
dtend =
StrToDateTime(To);

dt = DateTime();
mask = dtstart >= dt AND dt <= dtend;

hh = Highest( IIF( mask, array, 0 ) );
ll = Lowest( IIF( mask, array, 99999 ) );

dd = (ll - hh )/ hh;

MaxDD = LastValue( dd );

Best regards,
Tomasz Janeczko
amibroker.com

On 2010-03-05 06:09, ta wrote:


I have written the following function to calculate the drawdown between two dates. Does anybody know how eliminate the loop or make it run faster? TIA

 

function MaxDDFromTo(Array, From, To)
{
   Last =
LastValue(BarIndex());
   Start =
LastValue(ValueWhen(DateTime() == StrToDateTime(From), BarIndex()));
   End =
LastValue(ValueWhen(DateTime() == StrToDateTime(To), BarIndex()));

   Price = Array;
   MaxPrice = DD = MaxD = Bars =
0;
   
for( i = Start; i < End; i++ )
   {
      Bars = Bars +
1;
      MaxPrice =
Max(MaxPrice, HHV( Price, Bars ));
      DD =
100 * ( Price[i] - MaxPrice ) / MaxPrice;
      MaxD =
Min(MaxD, LLV( DD, Bars ));
   }
   
return MaxD;
}

_TRACE("from: " + "12/29/2000" + " To:  " + "12/31/2009" + " MaxDD: " + MaxDDFromTo(C, "12/29/2000", "12/31/2009") );





__._,_.___


**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

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





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___