log in     sign up for free
 
My attitude is: Never risk your family's security.
Marty Schwartz
 
 
Home
systems (285)
 
 
Special offer: buy AmiBroker and EOD+Real-Time Data
 

Buy

MetaStock

     (special offer)
 
 
 

Buy

EOD data for MetaStock

     (special offer)
 
 
 

Buy

Realtime data for MetaStock

     (special offer)
 
 
Formula Library
 
AmiBroker
MetaTrader
MetaStock
TradeStation
Wealth-Lab
NinjaTrader
 
add your formula
System Library
 
 
Account login
Your email:
Password:
 
Log in
New to s4t? Sign up.
If you forgot your password click here.
Search the Web
 
Custom Search

NLR Volatility

System for: TradeStation

 

 

Views:  1626

Added: August 02, 2008
 
Rate this code:  Rate: 1 Rate: 2 Rate: 3 Rate: 4 Rate: 5
This formula has not been rated yet
 
 

email this link

 
 
Tags: TradeStation, system
 


The NLR Indicator uses non-linear regression analysis to estimate a curve through price data. Potential applications include but are not limited to:
1) estimates of next price(s)
2) price envelopes and/or channels
3) moving average replacements



Type : Function, Name : NLR

{ NLR Function WAV 11/28/03

NonLinear Regression Analysis
y = A + B*X + C*X*X (2nd order)

y price
x bar (time)
A,B,C coefficients to determine

Standard deviation (S) of price from
calculated price for length data is returned

price for desired bar (either a past or future one)
is returned

}
InPuts: Length(NumericSimple), price(NumericSeries),
DesiredBar(NumericSimple),oNLRPrice(NumericRef),oStdDev(NumericRef);

vars: AvgX(0),AvgY(0),N(0),XM(0),YM(0),XM2(0),SXX(0),SXY(0),SYY(0),
SSYY(0),SXX2(0),SX2X2(0),SYX2(0),ACoeff(0),BCoeff(0),CCoeff(0),
X(0),Y(0), MaxLength(100),s(0),TX(0),TY(0),RV(0),ERR(0);

array: YValue[100](0),XValue[100](0);

if BarNumber = 1 then
begin
N = length;
{ be sure array size is protected }
if N > MaxLength then
N = MaxLength;
if N < 2 then
N = 2;
end;

{ fill arrays }
for value1 = 1 to N
begin
XValue[value1] = value1-1;
YValue[value1] = Price[value1-1];
end;

{ calc averages of x,y pairs }
AvgX = 0; AvgY = 0;
for value1 = 1 to N
begin
AvgX = AvgX + XValue[value1];
AvgY = AvgY + YValue[value1];
end;
if N <> 0 then
begin
AvgX = AvgX / N;
AvgY = AvgY / N;
end;

{ do regression and calc 3 coefficients }
SXX = 0; SXY = 0;SYY = 0;SXX2 = 0;SX2X2 = 0;SYX2 = 0;
for value1 = 1 to N
begin
XM = XValue[value1] - AvgX;
YM = YValue[value1] - AvgY;
XM2 = XValue[value1]*XValue[value1] - AvgX*AvgX;
SXX = SXX + XM*XM;
SXY = SXY + XM*YM;
SYY = SYY + YM*YM;
SXX2 = SXX2 + XM*XM2;
SX2X2 = SX2X2 + XM2*XM2;
SYX2 = SYX2 + YM*XM2;
end;

value99 = SXX*SX2X2 - SXX2*SXX2;
if value99 <> 0 then
begin
BCoeff = ( SXY*SX2X2 - SYX2*SXX2 ) / value99 ;
CCoeff = ( SXX*SYX2 - SXX2*SXY ) / value99;
end;

ACoeff = AvgY - BCoeff*AvgX - CCoeff*AvgX*AvgX;

{calc estimated price for desired bar
DesiredBar: use + for past and - for future
eg., for next bar in future:
DesiredBar = -1 }
oNLRPrice = ACoeff + BCoeff*DesiredBar+
CCoeff*DesiredBar*DesiredBar;

{calc std dev}
S = 0; AvgY = 0;
for value1 = 1 to N
begin
TY = YValue[value1];
TX = XValue[value1];
RV = ACoeff + BCoeff*XValue[value1]+
CCoeff*XValue[value1]*XValue[value1];
ERR = TY - RV;
AvgY = AvgY + TY;
S = S + ERR*ERR;
end;
if N-1 <> 0 then
if S /(N-1) > 0 then
S = SquareRoot(S /(N-1));

oStdDev = s;

NLR = 1;




The standard deviation of price versus calculated price (from NLR curve data) is easily determined. Interestingly, when the price calculation is close to the actual for several bars in a row (ie., low std dev) a significant price move sometimes occurs soon after demonstrating a possible new volatility measurement. See pic below for paintbar examples.

Code has been updated to use the new NLR function.



Type : PaintBar, Name : NLR_Volatility

{ NLR_Volatility PaintBar WAV 11/27/03

NonLinear Regression Analysis
y = A + B*X + C*X*X (2nd order)

y price
x bar (time)
A,B,C coefficients to determine

When Std Dev (S) is less
than MaxS bars are painted.

uses NLR function 11/28/03

}
InPuts: Length(6), price(High - (range/2)),
MaxS(0.08);

vars: oNLRPrice(0), oS(0);

value1 = NLR(length, price, 0, oNLRPrice, oS);

if oS < MaxS then
begin
plotPB(h,l,o,c,"NLRVolat");
alert("NLR Volatility alert");
end;


 

 



Code:

Type : Function, Name : NLR

{ NLR Function WAV 11/28/03

NonLinear Regression Analysis
y = A + B*X + C*X*X (2nd order)

y price
x bar (time)
A,B,C coefficients to determine

Standard deviation (S) of price from
calculated price for length data is returned

price for desired bar (either a past or future one)
is returned

}
InPuts: Length(NumericSimple), price(NumericSeries),
DesiredBar(NumericSimple),oNLRPrice(NumericRef),oStdDev(NumericRef);

vars: AvgX(0),AvgY(0),N(0),XM(0),YM(0),XM2(0),SXX(0),SXY(0),SYY(0),
SSYY(0),SXX2(0),SX2X2(0),SYX2(0),ACoeff(0),BCoeff(0),CCoeff(0),
X(0),Y(0), MaxLength(100),s(0),TX(0),TY(0),RV(0),ERR(0);

array: YValue[100](0),XValue[100](0);

if BarNumber = 1 then
begin
N = length;
{ be sure array size is protected }
if N > MaxLength then
N = MaxLength;
if N < 2 then
N = 2;
end;

{ fill arrays }
for value1 = 1 to N
begin
XValue[value1] = value1-1;
YValue[value1] = Price[value1-1];
end;

{ calc averages of x,y pairs }
AvgX = 0; AvgY = 0;
for value1 = 1 to N
begin
AvgX = AvgX + XValue[value1];
AvgY = AvgY + YValue[value1];
end;
if N <> 0 then
begin
AvgX = AvgX / N;
AvgY = AvgY / N;
end;

{ do regression and calc 3 coefficients }
SXX = 0; SXY = 0;SYY = 0;SXX2 = 0;SX2X2 = 0;SYX2 = 0;
for value1 = 1 to N
begin
XM = XValue[value1] - AvgX;
YM = YValue[value1] - AvgY;
XM2 = XValue[value1]*XValue[value1] - AvgX*AvgX;
SXX = SXX + XM*XM;
SXY = SXY + XM*YM;
SYY = SYY + YM*YM;
SXX2 = SXX2 + XM*XM2;
SX2X2 = SX2X2 + XM2*XM2;
SYX2 = SYX2 + YM*XM2;
end;

value99 = SXX*SX2X2 - SXX2*SXX2;
if value99 <> 0 then
begin
BCoeff = ( SXY*SX2X2 - SYX2*SXX2 ) / value99 ;
CCoeff = ( SXX*SYX2 - SXX2*SXY ) / value99;
end;

ACoeff = AvgY - BCoeff*AvgX - CCoeff*AvgX*AvgX;

{calc estimated price for desired bar
DesiredBar: use + for past and - for future
eg., for next bar in future:
DesiredBar = -1 }
oNLRPrice = ACoeff + BCoeff*DesiredBar+
CCoeff*DesiredBar*DesiredBar;

{calc std dev}
S = 0; AvgY = 0;
for value1 = 1 to N
begin
TY = YValue[value1];
TX = XValue[value1];
RV = ACoeff + BCoeff*XValue[value1]+
CCoeff*XValue[value1]*XValue[value1];
ERR = TY - RV;
AvgY = AvgY + TY;
S = S + ERR*ERR;
end;
if N-1 <> 0 then
if S /(N-1) > 0 then
S = SquareRoot(S /(N-1));

oStdDev = s;

NLR = 1;





Type : PaintBar, Name : NLR_Volatility

{ NLR_Volatility PaintBar WAV 11/27/03

NonLinear Regression Analysis
y = A + B*X + C*X*X (2nd order)

y price
x bar (time)
A,B,C coefficients to determine

When Std Dev (S) is less
than MaxS bars are painted.

uses NLR function 11/28/03

}
InPuts: Length(6), price(High - (range/2)),
MaxS(0.08);

vars: oNLRPrice(0), oS(0);

value1 = NLR(length, price, 0, oNLRPrice, oS);

if oS < MaxS then
begin
plotPB(h,l,o,c,"NLRVolat");
alert("NLR Volatility alert");
end;


 




 

Code to difficult? Find somebody to help you with coding here.

 


Source: https://www.tradestation.com

 

View similar:

Delayed Channel Breakout
Keltner TSI
SHARK-32 System
SystemE
SystemB
Pathfinder Currency
Fox31
NLR Volatility
Kase 30
E2 Bonder
...
 
 
all systems for TradeStation
all systems

 

 

Email to friend

Top

 

     
However we try to maintain hiqhest possible level of service - most formulas, oscillators, indicators
and systems are submitted by anonymous users.
Therefore S4T™ does not take any responsibility for it's quality.
If you use any of this information, use it at your own risk. You are responsible for your own trading decisions.
Be sure to verify that any information you see on these pages is correct, and is applicable to your particular trade.
In no case will S4T™ be responsible for your trading gains or losses.
PayPalSecure payments by PayPal S4T™ is a part of TAURO EDUCATION NETWORK
 
Privacy note | (c) copyrights systems4trading.com 2006-2009