_Normalizer_Auto.p

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

_Normalizer_Auto.p

Postby progster » Sun May 03, 2009 9:53 pm

Here is the TradeStation EL code that creates the RadarScreen displays shown here .

Code: Select all

[LegacyColorValue = true];

{
   Indicator:      _NORMALIZER_Auto.p
   
   Progster's version of TRO's _NORMALIZER_Auto

   Added coloring for RadarScreen.

   4/3/2008   Added Plot5 of Sum.

   Available named indicator bundles are:

   WS
    x1Ind = rsi(close,2);
    x2Ind = rateofchange(close,5);
    x3Ind = macd(close,5,20);
    x4Ind = 0;
   
   WARM
    x1Ind = percentr(10);
    x2Ind = accumdist(volume);
    x3Ind = rsi(close,2);
    x4Ind = momentum(close,12);

   EMA5
   x1Ind = xaverage(close,5);
    x2Ind = detrend(close,5);
    x3Ind = macd(close,5,20);
    x4Ind = rsi(close,2);

   MOMO
   x1Ind = xaverage(close,5);
    x2Ind = momentum(close,12);
    x3Ind = macd(close,5,20);
    x4Ind = rsi(close,2);


}
{ _NORMALIZER_Auto  }


{iMode = "auto" is auto mode - sets xPeriods based on chart interval}

{iMode not =  "auto" is manual mode - sets xPeriods to iPeriods }



inputs:   
   
iMode("auto"),   { if "auto" code sets xPeriods, if not "auto" code uses iPeriods}
iPeriods(60),   { number of periods to normalize over}
iMult(100),     { multiplier if 100 then chart scale is 0 - 100, if 1 then scale 0 - 1 }
   
promptA("none, ws, warm, ema5, momo"),
iDefault("none"),

i1Ind(rsi(close,2)),
i1IndColor( CYAN),

i2Switch(true),
i2Ind(detrend(close,5)),
i2IndColor( darkmagenta),

i3Switch(true),
i3Ind(macd(close,5,20)),
i3IndColor( yellow),

i4Switch(true),
i4Ind(xaverage(close,5)),
i4IndColor(white),

RadarHighLine(90),
RadarLowLine(10),

idummy("");

variables:
   
xPeriods(60),
xInterval(0),

sFirstPass(true),

Normal1(0),
Normal2(0),
Normal3(0),
Normal4(0),   

NormalSum(0),         //   sbj:  4/3/2008
NormalSumColor(0),

xRange(0),
xPosition(0),

x1Ind(0),
x2Ind(0),
x3Ind(0),
x4Ind(0),

x1Switch(true),
x2Switch(true),
x3Switch(true),
x4Switch(true),

x1IndColor (CYAN),
x2IndColor( red),
x3IndColor( yellow),
x4IndColor( green),

x1FGColor(black),
x2FGColor(black),
x3FGColor(black),
x4FGColor(black),

x1BGColor(black),
x2BGColor(black),
x3BGColor(black),
x4BGColor(black),

x1_RadarHighLine(RadarHighLine),
x2_RadarHighLine(RadarHighLine),
x3_RadarHighLine(RadarHighLine),
x4_RadarHighLine(RadarHighLine),

x1_RadarLowLine(RadarLowLine),
x2_RadarLowLine(RadarLowLine),
x3_RadarLowLine(RadarLowLine),
x4_RadarLowLine(RadarLowLine),

xdummy("");

{first time through}

if sFirstPass
then begin
   
sFirstPass = false;

{bar test}

If bartype = 4
   then xInterval = 94
else
If bartype = 3
   then xInterval = 93
else
If bartype = 2
   then xInterval = 92
else
If bartype = 1
then begin
   xInterval = BarInterval;
end; { If bartype = 1  }

{mode test}

If iMode <> "Auto" and iMode <> "auto" and iMode <> "AUTO"
    then xPeriods = iPeriods
   else xPeriods = _fModePeriods(xInterval);

end; {if sFirstPass}


{ Load defaults }

If iDefault = "none"
or iDefault = "NONE"
then begin
   
    x1Ind = i1Ind;
    x2Ind = i2Ind;
    x3Ind = i3Ind;
    x4Ind = i4Ind;

   x2Switch = i2Switch ;
   x3Switch = i3Switch ;
   x4Switch = i4Switch ;

   x1IndColor = i1IndColor;
    x2IndColor = i2IndColor;
   x3IndColor = i3IndColor;
    x4IndColor = i4IndColor;
   
end;   


If iDefault = "WS"
or iDefault = "ws"
then begin
    x1Ind = rsi(close,2);
    x2Ind = rateofchange(close,5);
    x3Ind = macd(close,5,20);
    x4Ind = 0;
   
   x2Switch = true ;
   x3Switch = true ;
   x4Switch = false ;

   x1IndColor = CYAN;
    x2IndColor = red;
   x3IndColor = yellow;
    x4IndColor = green;

end;


If iDefault = "WARM"
or iDefault = "warm"
then begin
    x1Ind = percentr(10);
    x2Ind = accumdist(volume);
    x3Ind = rsi(close,2);
    x4Ind = momentum(close,12);
   
   x2Switch = true ;
   x3Switch = true ;
   x4Switch = true ;

   x1IndColor = magenta;
    x2IndColor = red;
   x3IndColor = cyan;
    x4IndColor = green;

end;


If iDefault = "EMA5"
or iDefault = "ema5"
then begin
   
   x1Ind = xaverage(close,5);
    x2Ind = detrend(close,5);
    x3Ind = macd(close,5,20);
    x4Ind = rsi(close,2);

   x2Switch = true ;
   x3Switch = true ;
   x4Switch = true ;

   x1IndColor = white;
    x2IndColor = darkmagenta;
   x3IndColor = yellow;
    x4IndColor = cyan;

end;   


If iDefault = "MOMO"
or iDefault = "momo"
then begin
   
   x1Ind = xaverage(close,5);
    x2Ind = momentum(close,12);
    x3Ind = macd(close,5,20);
    x4Ind = rsi(close,2);

   x2Switch = true ;
   x3Switch = true ;
   x4Switch = true ;

   x1IndColor = white;
    x2IndColor = green;
   x3IndColor = yellow;
    x4IndColor = cyan;

end;

{ calculations }

if (IsRadarScreen = False) then begin
   
   Normal1 = _fNormalizer(x1Ind, xPeriods ) * imult;
   Plot1( Normal1, "Ind1", x1IndColor ) ;
   
   if x2Switch
   then begin
      Normal2 = _fNormalizer(x2Ind, xPeriods ) * imult;
      Plot2( Normal2, "Ind2", x2IndColor ) ;
   end;
   
   
   if x3Switch
   then begin
      Normal3 = _fNormalizer(x3Ind, xPeriods ) * imult;
      Plot3( Normal3, "Ind3", x3IndColor ) ;
   end;
   
   if x4Switch
   then begin
      Normal4 = _fNormalizer(x4Ind, xPeriods ) * imult;
      Plot4( Normal4, "Ind4", x4IndColor ) ;
   end
   else begin
      Plot4( .50 * iMult, "Ind4", x4IndColor ) ;
   end;

end;   //   end of:      if (IsRadarScreen = False)

if (IsRadarScreen = True) then begin
   
   //   default to black background for RadarScreen
   x1FGColor = white ;
   x2FGColor = white ;
   x3FGColor = white ;
   x4FGColor = white ;

   x1BGColor = black ;
   x2BGColor = black ;
   x3BGColor = black ;
   x4BGColor = black ;

   Normal1 = _fNormalizer(x1Ind, xPeriods ) * imult;

   //   Plot black text if not at extreme, else darkgray
   if (Normal1 > x1_RadarHighLine) then    x1FGColor = black   
   else if (Normal1 < x1_RadarLowLine) then x1FGColor = black
   else x1FGColor = darkgray ;

   if (Normal1 > x1_RadarHighLine) then    x1BGColor = green       
   else if (Normal1 < x1_RadarLowLine) then x1BGColor = red
   else x1BGColor = black ;
   SetPlotBGColor(1, x1BGColor);

   Plot1( Normal1, "Ind1", x1FGColor ) ;

   
   if x2Switch then begin
      Normal2 = _fNormalizer(x2Ind, xPeriods ) * imult;

      //   Plot black text if not at extreme, else darkgray
      if (Normal2 > x2_RadarHighLine) then    x2FGColor = black   
      else if (Normal2 < x2_RadarLowLine) then x2FGColor = black
      else x2FGColor = darkgray ;

      if (Normal2 > x2_RadarHighLine) then x2BGColor = green
      else if (Normal2 < x2_RadarLowLine) then x2BGColor = red
      else x2BGColor = black ;
      SetPlotBGColor(2, x2BGColor);

      Plot2( Normal2, "Ind2", x2FGColor ) ;
   
   end;
   
   
   if x3Switch then begin
      Normal3 = _fNormalizer(x3Ind, xPeriods ) * imult;

      //   Plot black text if not at extreme, else darkgray
      if (Normal3 > x3_RadarHighLine) then    x3FGColor = black   
      else if (Normal3 < x3_RadarLowLine) then x3FGColor = black
      else x3FGColor = darkgray ;

      if (Normal3 > x3_RadarHighLine) then x3BGColor = green
      else if (Normal3 < x3_RadarLowLine) then x3BGColor = red
      else x3BGColor = black ;
      SetPlotBGColor(3, x3BGColor);

      Plot3( Normal3, "Ind3", x3FGColor ) ;

   end;
   
   if x4Switch then begin
      Normal4 = _fNormalizer(x4Ind, xPeriods ) * imult;

      //   Plot black text if not at extreme, else darkgray
      if (Normal4 > x4_RadarHighLine) then    x4FGColor = black   
      else if (Normal4 < x4_RadarLowLine) then x4FGColor = black
      else x4FGColor = darkgray ;

      if (Normal4 > x4_RadarHighLine) then x4BGColor = green
      else if (Normal4 < x4_RadarLowLine) then x4BGColor = red
      else x4BGColor = black ;
      SetPlotBGColor(4, x4BGColor);

      Plot4( Normal4, "Ind4", x4FGColor ) ;

   end;

   NormalSum = Normal1 + Normal2 + Normal3 + Normal4 ;

   // NormalSumColor = NormGradientColor( NormalSum, False, iPeriods, red, green ) ;
   NormalSumColor = GradientColor( NormalSum, 100, 400, white, green ) ;

   // Plot5( NormalSum, "Sum", white ) ;
   Plot5( NormalSum, "Sum", NormalSumColor ) ;


end;   //   end of:      if (IsRadarScreen = True)


Here is the _fNormalizer function:

Code: Select all

[LegacyColorValue = true];

{ _fNORMALIZER }

{

IndPosition = _fNormalizeR(iInd, iPeriods)
  }   
inputs:
iInd(numericseries),      
iPeriods(numericsimple );


variables:


xInd(0),
xPosition(0),
xRange(0),

xMROHi( 0 ),
xMROLo( 0 ),
xIndMin( 0 ),
xIndMax( 0 ),
   
vdummy("");

{ calculations }
 

xInd = iInd;

xIndMin = LOWEST(xInd,iPeriods);

xIndMax = HIGHEST(xInd,iPeriods);
   
xRange = xIndMax - xIndMin;

if xRange <> 0
then begin
xPosition = (xInd - xIndMin) / xRange;
xPosition = round(xPosition, 4) ;
end;

_fNORMALIZER = xPosition ;


The function _fModePeriods () is also used:

Code: Select all

[LegacyColorValue = true];

{ _fModePeriods }
   
inputs:     

iInterval(numericsimple );

variables:
   
xPeriods(60);


{ calculations }
 

If iInterval < 5
    then xPeriods = 10
else
If iInterval < 10
    then xPeriods = 12
else
If iInterval = 10
    then xPeriods = 6
else
If iInterval = 15
    then xPeriods = 4
else
If iInterval = 30
    then xPeriods = 4
else
If iInterval = 60
    then xPeriods = 70
else
If iInterval > 60
    then xPeriods = 60;

_fModePeriods = xPeriods;


The code can be applied to a chart as well:

NormOnChart.png

Thanks to TRO for the original implementation!
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