| 
 PureBytes Links 
Trading Reference Links 
 | 
Hello,
Yo have double nested loop. The code can be written without any loop using Sum function.
Actually it is a single-liner.
function numUpDownBars( periods )
{
 return Sum( sign( Open - Close ) + sign( Close - Ref( Close, -1 ) ), periods );
}
Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message ----- 
From: "chwinc2000" <chwinc2000@xxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Monday, August 13, 2007 6:24 AM
Subject: [amibroker] using indicator in Script for backtesting
> Hello All,
> 
> I created a indicator which I called in my script during backtest. 
> When I am backtest it it runs extremely slow. I takes forever if I 
> try to optimize it.
> 
> I think it is because at each bar, I calls the function again and 
> again causing massive resource usage. Does anyone know how to access 
> it at a specific bar or recode to better use the function.
> 
> THanks,
> Chris
> 
> 
> 
> 
> function numUpDown(periods)
> {
>  for(t=0;t<BarCount;t++)
> {
> Value = 0;
> 
> if(t >= periods)
> {
> x = t;
> for(i=0; i<periods;i++)
> { 
> if( C[x] > O[x] )
> Value++;
> else if(C[x] < O[x] )
> Value--;
> 
> if( C[x] > C[x-1] )
> Value++;
> else if(C[x] < C[x-1] )
> Value--;
> 
> x--;
> }
> 
> }
> 
> result[t] = Value;
> 
> }
> 
> return result;
> }
> 
> upDown = numUpDown(10);
> 
> 
> Buy = AND (UpDown > 0);
> BuyPrice = O;
> Buy = (Ref(Buy, -1));
> 
> Sell = C>ref(c,-1);
> SellPrice =  O;
> Sell = Ref(Sell,-1); 
> 
> 
> 
> 
> 
> 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
> 
> 
> 
> 
>
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/
 
 |