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

Re: [amibroker] VERY slow code



PureBytes Links

Trading Reference Links

Keith,
Moving array operations outside the loop seems to have made things 
faster.  I found some syntax errors for UI so you need to check if my 
assumption about the formula is correct. See below:
-------------------------code begins---------------------------
// just between the poles
Counta = 0;
SumR2 = 0;
ddmax = 0;
ddmaxdate = 0;
_highest = 0;
ratio = 0;
adate = DateTime();
_highest = HHV(H, BarIndex() - BeginValue(BarIndex()));

for(i = BeginValue(BarIndex())+1; i <= EndValue(BarIndex()); i++){

   ratio[i] = (_highest[i] - L[i])/_highest[i];
   if(ratio[i] > ddmax[i-1]){
     ddmax[i] = ratio[i];
     ddmaxdate[i] = adate[i];

   }else{
     ddmax[i] = ddmax[i-1];
     ddmaxdate[i] = ddmaxdate[i-1];
   }
   SumR2 = ratio[i]^2 + Ref(SumR2[i], -1);
   Counta++;
}

ui = 100 * (SumR2[i-1]/Counta)*0.5;
Maxdd = 100 * ddmax[i-1];
Maxdddate = ddmaxdate[i-1];

PlotOHLC(O,H,L,C,"",colorBlack,styleCandle);
Value = SelectedValue(C);
Title = Name() + " = " + Value
     + "      %UI = " + ui + "        Max%DD = " + Maxdd
     + "  on  " + NumToStr(Maxdddate, formatDateTime);
--------------------------code ends-------------------------

Regards,
Ed

keithmccombs wrote:
> 
> The following code displays the %UI and %MaxDD over a period of time 
> defined by the 'marker' poles.  The default (no marker poles 
> present), displays %UI and %MaxDD over all bars in the data base.
> 
> This code works, but is terribly slow.  It is fine for monthly bars, 
> but with 15 years of daily bars you will think it died (in fact Task 
> Manager will think so too).
> 
> I'm pretty sure the problem is with the arrays in the 'for' loop, but 
> don't know what to do about it.  
> 
> Any and all help and suggestions are appreciated.
> TIA.
> -- Keith
> =============================
> // just between the poles
> Count = 0;
> SumR2 = 0;
> ddmax = 0;
> ddmaxdate = 0;
> _highest = 0;
> ratio = 0;
> adate = DateTime();
> 
> for(i = BeginValue(BarIndex())+1; i <= EndValue(BarIndex()); i++){
>   _highest = HHV(H, BarIndex() - BeginValue(BarIndex()));
>   ratio[i] = (_highest[i] - L[i])/_highest[i];
>   if(ratio[i] > ddmax[i-1]){
>     ddmax[i] = ratio[i];
>     ddmaxdate[i] = adate[i];
> 
>   }else{
>     ddmax[i] = ddmax[i-1];
>     ddmaxdate[i] = ddmaxdate[i-1];
>   }
>   SumR2 = ratio[i]^2 + Ref(SumR2[i], -1);
>   Count++;
> }
> 
> ui = 100 * (SumR2[i-1]/Count)^0.5;
> Maxdd = 100 * ddmax[i-1];
> Maxdddate = ddmaxdate[i-1];
> 
> PlotOHLC(O,H,L,C,"",colorBlack,styleCandle);
> Value = SelectedValue(C);
> Title = Name() + " = " + Value
>     + "      %UI = " + ui + "        Max%DD = " + Maxdd
>     + "  on  " + NumToStr(Maxdddate, formatDateTime);
> 
> 
> 
> 
> 
> 
> 
> 
> 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 other support material please check also:
> http://www.amibroker.com/support.html
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 
> 
> 


------------------------ Yahoo! Groups Sponsor --------------------~--> 
In low income neighborhoods, 84% do not own computers.
At Network for Good, help bridge the Digital Divide!
http://us.click.yahoo.com/EpW3eD/3MnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

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 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/

<*> 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/