Re: TradeStation Indicators

63
Mean reversion indicator

Code: Select all

// TASC JAN 2017
// Mean-Reversion Swing Trading
// Ken Calhoun

inputs:
	ChanLength( 20 ),
	MALength( 50 ) ;
	
variables:
	UpperBand( 0 ),
	LowerBand( 0 ),
	MidBand( 0 ),
	LongOK( false ),
	ShortOK( false ),
	LowRef( 0 ),
	HighRef( 0 ),
	TriggerLine( 0 ),
	MAValue( 0 ) ;
	
UpperBand = Highest( High, ChanLength ) ;
LowerBand = Lowest( Low, ChanLength ) ;
MAValue = Average( Close, MALength ) ;

if Low = LowerBand then
	begin
	LowRef = Low ;
	LongOK = false ;
	ShortOK = true ;
	end ;
	
if High = UpperBand then
	begin
	HighRef = High ;
	LongOK = true ;
	ShortOK = false ;
	end ;	

TriggerLine = .5 * ( HighRef + LowRef ) ;
	
Plot1( UpperBand, "UpperBand" ) ;
Plot2( LowerBand, "LowerBand" ) ;
Plot3( TriggerLine, "Trigger" ) ;
Plot4( MAValue, "Mov Avg" ) ;

if LongOK then
	begin
	SetPlotColor( 1, Green ) ;
	SetPlotColor( 2, Green ) ;
	end
else
	begin
	SetPlotColor( 1, Red ) ;
	SetPlotColor( 2, Red ) ;
	end ;	
These users thanked the author mladen for the post (total 2):
alexm, Khaal


Re: TradeStation Indicators

66

Code: Select all

Indicator: Correlation Divergence
// Correlation Divergence
// Markos Katsanos
// TASC JUL 2017

inputs:
	SEC2( Close of Data2 ),// FXY
	SEC3( Close of Data3 ),//SPY
	D1( 3 ), //ROC DAYS
	DIVDAYS( 50 ),// REGRESSION DAYS
	IMDAYS( 50 ),// DIVERGENCE MOMENTUM DAYS
	CR3CR( .8 ) ; //CORRELATION WITH SEC3
	
variables:
	IM2(0),
	DIV2(0),RS1(0),RS2(0),
	b2(0),PRED2(0),a2(0),
	RS3(0),CR2(0),CR3(0);

//REGRESSION
RS1 = ( Close / Close[D1] - 1 ) * 100 ;
RS2 = ( SEC2 / SEC2[D1] - 1 ) * 100 ;
RS3 = ( SEC3 / SEC3[D1] - 1 ) * 100 ;
CR2 = CorrelationMK( RS1, RS2, DIVDAYS ) ;
CR3 = CorrelationMK( RS1, RS3, DIVDAYS ) ;
b2 = CR2 * StandardDev( RS1, DIVDAYS, 1 ) 
	/ ( StandardDev( RS2, DIVDAYS, 1 ) + .001 ) ;
a2 = Average( RS1, DIVDAYS ) 
	- b2 * Average( RS2, DIVDAYS ) ;
PRED2 = b2 * RS2 + a2 ;
DIV2 = PRED2 - RS1 ;

IM2 = ( Average( DIV2 - 
	Lowest( DIV2, IMDAYS ), 2 ) * 100 ) /
	( Average( Highest( DIV2, IMDAYS ) - 
	Lowest( DIV2, IMDAYS ), 2 ) + .01 ) ;

Plot1( IM2, "RegDiv" ) ;
Plot2( 75, "Upper" ) ;
Plot3( 25, "Lower" ) ;


Function: Correlation MK
{ CORRELATIONMK : Pearson's 
Correlation Function
Copyright 2009, 
Markos Katsanos. 
All rights reserved.
For more information see 
Intermarket Trading Strategies, Wiley,
2009 }

Inputs:
	SEC1( NumericSeries ),
	SEC2( NumericSeries ),
	D1( NumericSimple ); // days for correlation

Variables:
	D2(20),Q1(0),Q2(0),
	Q3(0),Q2Q3(0),R(0);
if CurrentBar >= D1 then 
	begin
	Q1 = Summation((SEC1*(SEC2)),D1)
		-(Summation(SEC1,D1)
		* Summation(SEC2,D1)/D1);

	Q2 = Summation(((SEC2)*(SEC2)),D1) 
		- (Summation(SEC2,D1)
		* Summation(SEC2,D1)/D1);

	Q3 = Summation((SEC1*SEC1),D1) 
		- (Summation(SEC1,D1)
		* Summation(SEC1,D1)/D1);

	if Q2*Q3 > 0 then 
		Q2Q3=SquareRoot(Q2*Q3);
	if Q2Q3 <> 0 then 
		begin
		R=Q1/Q2Q3;
		if R <= 1 and  R >= -1 then
		CorrelationMK = R ;
		end ;
	end ;
	
These users thanked the author mladen for the post:
Khaal


Who is online

Users browsing this forum: No registered users and 4 guests