Progster's Detrend Ribbon

EasyLanguage and other code for TradeStation
User avatar
progster
Posts: 948
Joined: Thu Jul 26, 2007 7:20 pm
Contact:

Progster's Detrend Ribbon

Postby progster » Sat May 30, 2009 3:34 pm

TradeStation provides a 'Mov Avg Exp Ribbon', and a 'Detrended Price Osc', but does not have a built-in detrended ribbon indicator.

I thought it would be nice-to-have. Enjoy!

DetrendRibbon02.png

Code: Select all

{
   Indicator:   Detrend Ribbon

   Ribbon display (multiple lines) of detrended data, as per the TradeStation Detrend() function,
   across multiple calculation lengths.

   The lengths used for each ribbon calculation may be observed in the Commentary window.

}
{   Coded by progster@CodeForTraders.com   http://www.CodeForTraders.com  Copyright 2009
   This code may be freely distributed and used, so long as the origin/copyright notice remains intact.
}

inputs:
   Price( Close ),
   BaseLength( 10 ),
   ArithOrGeom_1or2( 1 ),
   IncrementOrMultiplier( 10 ),    //   to be added or multiplied, per the algorithm choice
   FastColor( Yellow ),
   SlowColor( Red ) ;

variables:
   Counter( 0 ) ,
   RibbonCount( 8 );   //   enlarge, along with array sizes, if more ribbons are desired

arrays:
   //   Set these array sizes to match the Ribbon Count.
   //   Name the arrays so that the names differ from common unadorned words (e.g. Length, Color, Detrend)
   aLength[8]( 0 ),
   aColor[8]( 0 ),
   aDetrend[8]( 0 );

//   On the first bar, initialize the Length, Color, and Detrend arrays
if (CurrentBar = 1) then begin
    aLength[1] = BaseLength ;
   aDetrend[1] = Detrend( Price, aLength[1] ) ;

   aColor[1] = GradientColor( 1, 1, 8, FastColor, SlowColor ) ;
   for Counter = 1 to (RibbonCount - 1) begin
         
      //   Calculate the ribbon lengths
      if ArithOrGeom_1or2 = 1 then
         aLength[ Counter + 1 ] = aLength[Counter] + IncrementOrMultiplier
      else
         aLength[ Counter + 1 ] = aLength[Counter] * IncrementOrMultiplier ;

      aDetrend[ Counter + 1 ] = Detrend( Price, aLength[ Counter + 1 ] ) ;

      aColor[ Counter + 1 ] = GradientColor( Counter + 1, 1, 8, FastColor, SlowColor ) ;

   end ;
end
else begin
   
   { calculate all exponential moving average values }
   for Counter = 1 to RibbonCount begin
      aDetrend[Counter] = Detrend( Price, aLength[ Counter ] ) ;
   end ;

end;

//   plot the Detrended values
Plot1( aDetrend[1], "Detrend1", aColor[1] ) ;
Plot2( aDetrend[2], "Detrend2", aColor[2] ) ;
Plot3( aDetrend[3], "Detrend3", aColor[3] ) ;
Plot4( aDetrend[4], "Detrend4", aColor[4] ) ;
Plot5( aDetrend[5], "Detrend5", aColor[5] ) ;
Plot6( aDetrend[6], "Detrend6", aColor[6] ) ;
Plot7( aDetrend[7], "Detrend7", aColor[7] ) ;
Plot8( aDetrend[8], "Detrend8", aColor[8] ) ;

Plot99( 0, "ZeroLine" ) ;

// If CommentaryEnabled Then Begin
If AtCommentaryBar Then Begin
   for Counter = 1 to RibbonCount begin
      CommentaryCl( "Detrend[", NumToStr(aLength[Counter], 0),  "]: ", NumToStr(aDetrend[Counter], 4) );
   end ;
end;
You do not have the required permissions to view the files attached to this post.

Return to “TradeStation Code”

Who is online

Users browsing this forum: No registered users and 1 guest