| 
 
  
  
  
Hi Dennis - I don't know that it works in every situation,  I would guess that maybe VarSet/Get handles the conversion internally? 
  
Steve 
  
----- Original Message -----  
From: Dennis Brown  
To: amibroker@xxxxxxxxxxxxxxx  
Sent: Saturday, June 13, 2009 2:25 PM 
Subject: Re: [amibroker] How to code a Adaptive StDev() 
  
Steve,  
  
I did not realize that I could append a number to a string in AFL without converting it first with NumToStr( i, 0.0).   
It looks like I have been missing a big shortcut all this time. 
  
BR, 
Dennis 
  
  
On Jun 13, 2009, at 1:26 PM, Steve Dugas wrote: 
  
  
  
  
  
Oops!  Just saw a typo, should be this insread... 
  
  
function xStDev( priceArray, Periods) // Periods < 25 
{ 
   global BBTop, BBBot; 
   Periods = Max( 2, Min( 25, Periods ) ); 
   BreakPoint = Min( 25, Highest( Periods )); 
   for( i = 2; i <= BreakPoint; i++ ) 
   { 
      VarSet( "SD" + i, StDev( PriceArray, i ); 
   } 
   AdaptSD = 0; 
   for( i = 2; i <= BreakPoint; i++ ) 
   { 
      CurrSD = VarGet( "SD" + i ); 
      AdaptSD = IIF( Periods == i, CurrSD, AdaptSD ); 
   } 
    return AdaptSD; 
} 
  
  
----- Original Message ----- 
From: Steve Dugas 
To: amibroker@xxxxxxxxxxxxxxx 
Sent: Saturday, June 13, 2009 1:20 PM 
Subject: Re: [amibroker] How to code a Adaptive StDev() 
  
Hi Herman - Not sure how fast it would be but possibly something along these lines? 
  
  
function xStDev( priceArray, Periods) // Periods < 25 
{ 
   global BBTop, BBBot; 
   Periods = Max( 2, Min( 25, Periods ) ); 
   BreakPoint = Min( 25, Highest( Periods )); 
   for( i = 2; i <= BreakPoint; i++ ) 
   { 
      VarSet( "SD" + i, StDev( PriceArray, i ); 
   } 
   AdaptSD = 0; 
   for( i = 2; i <= BreakPoint; i++ ) 
   { 
      CurrSD = VarGet( "SD" + i ); 
      AdaptSD = IIF( Periods == i, CurrSD, AdaptStDev ); 
   } 
    return AdaptSD; 
} 
Would anyone have coded an adaptive StDev? I am using the solution below but is is VERY slow and the number of max period value is limited. 
  
My math is just not up to this and any help would be very much appreciated! 
  
have a great day, 
Herman 
  
function xStDev( priceArray, Periods) // Periods < 25 
{ 
   global BBTop, BBBot; 
   Periods = Min( 25, periods ); 
   Periods = Max( 2, Periods); 
   Deviation = 
   IIf( Periods == 2, StDev( PriceArray, 2 ), 
   IIf( Periods == 3, StDev( PriceArray, 3 ), 
   IIf( Periods == 4, StDev( PriceArray, 4 ), 
   IIf( Periods == 5, StDev( PriceArray, 5 ), 
   IIf( Periods == 6, StDev( PriceArray, 6 ), 
   IIf( Periods == 7, StDev( PriceArray, 7 ), 
   IIf( Periods == 8, StDev( PriceArray, 8 ), 
   IIf( Periods == 9, StDev( PriceArray, 9 ), 
  
   IIf( Periods == 10, StDev( PriceArray, 10 ), 
   IIf( Periods == 11, StDev( PriceArray, 11 ), 
   IIf( Periods == 12, StDev( PriceArray, 12 ), 
  
   IIf( Periods == 13, StDev( PriceArray, 13 ), 
   IIf( Periods == 14, StDev( PriceArray, 14 ), 
   IIf( Periods == 15, StDev( PriceArray, 15 ), 
  
   IIf( Periods == 16, StDev( PriceArray, 16 ), 
   IIf( Periods == 17, StDev( PriceArray, 17 ), 
   IIf( Periods == 18, StDev( PriceArray, 18 ), 
  
   IIf( Periods == 19, StDev( PriceArray, 19 ), 
   IIf( Periods == 20, StDev( PriceArray, 20 ), 
   IIf( Periods == 21, StDev( PriceArray, 21 ), 
  
   IIf( Periods == 22, StDev( PriceArray, 22 ), 
   IIf( Periods == 23, StDev( PriceArray, 23 ), 
   IIf( Periods == 24, StDev( PriceArray, 24 ), 
   StDev( PriceArray, 25 )))))))))))))))))))))))); 
   return Deviation; 
} 
  
  
  
  
  
  
 
 |