indiTraders - Forum for the Active Indian Trader  

Go Back   indiTraders - Forum for the Active Indian Trader > Technical > Indicators & Systems

Indicators & Systems Compendium of Code

DPonline
Reply
 
Bookmark and Share LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-03-2014, 02:56 AM
CoderTrader CoderTrader is offline
Regulars
 
Join Date: Dec 2010
Posts: 219
Thanks: 76
Thanked 194 Times in 109 Posts
CoderTrader will become famous soon enoughCoderTrader will become famous soon enoughCoderTrader will become famous soon enough
black Pair Trading with Stress Indicator

Perry Kaufman has come up with a new approach to trading pairs called the stress indicator.

Calculation
1. Calculate n period stochastic of Stock 1.
2. Calculate n period stochastic of Stock 2.
3. Calculate the difference between the first two results.
4. Calculate the n period stochastic of the difference.

Interpretation.

When the indicator is below 10 then Stock 1 is oversold. At 50, the stocks are considered in sync.

Chart



Code

Amibroker Code

Code:
LISTING 1.
function PJKStress( High2, Low2, Close2, period ) 
{ 
range1 = HHV( High, period ) - LLV( Low, period ); 
range2 = HHV( High2, period ) - LLV( Low2, period ); 
stoch1 = ( Close - LLV( Low, period ) )/range1; 
stoch2 = ( Close2 - LLV( Low2, period ) )/range2; 
VarSet("sstoch1", 100 * stoch1 ); 
VarSet("sstoch2", 100 * stoch2 ); 
diff = stoch1 - stoch2; 
range1 = HHV( diff, period ) - LLV( diff, period ); 
return 100 * ( diff - LLV( diff, period ) )/range1; 
} 
momper = 60; 
Hedgeper = 60; 
SetForeign("SPY"); 
// store index data in High2/Low2/Close2 variables 
High2 = High; 
Low2 = Low; 
Close2 = Close; 
RestorePriceArrays(); 
stress = PJKStress( High2, Low2, Close2, momper ); 
Plot( stress, "Stress", colorRed, styleThick ); 
Plot( sstoch1, "Stoch1", colorGreen ); 
Plot( sstoch2, "Stoch2", colorBlue );
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following 2 Users Say Thank You to CoderTrader For This Useful Post:
  #2 (permalink)  
Old 05-03-2014, 01:03 PM
kkseal kkseal is offline
Hip-py
 
Join Date: Apr 2009
Posts: 4,940
Thanks: 6,517
Thanked 9,489 Times in 4,086 Posts
kkseal has a reputation beyond reputekkseal has a reputation beyond repute
kkseal has a reputation beyond reputekkseal has a reputation beyond reputekkseal has a reputation beyond reputekkseal has a reputation beyond reputekkseal has a reputation beyond reputekkseal has a reputation beyond reputekkseal has a reputation beyond reputekkseal has a reputation beyond reputekkseal has a reputation beyond reputekkseal has a reputation beyond reputekkseal has a reputation beyond reputekkseal has a reputation beyond reputekkseal has a reputation beyond repute
Default

No context? To what extent the two move in sync is a needed priori i think.
__________________
'Growth & Value are joined at the hip' - Warren buffet
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to kkseal For This Useful Post:
  #3 (permalink)  
Old 07-05-2014, 11:41 AM
veepsirtt veepsirtt is offline
Newbie
 
Join Date: Jun 2009
Posts: 7
Thanks: 0
Thanked 3 Times in 1 Post
veepsirtt is on a distinguished road
Default Back testing NIFTY and BANKNIFTY pair

How to get the 5 years back test results of the NIFTY and BANKNIFTY pair?

_SECTION_BEGIN("Pair Trading");
SetChartOptions(0,0,chartGrid30|chartGrid70);

_N( Symbol1= ParamStr("Symbol1", "^NSEI") );


SetForeign( Symbol1 );
C1 = C;
H1 = H;
L1 = L;
O1 = O;
V1 = V;
RestorePriceArrays();

_N( Symbol2= ParamStr("Symbol2", "^NSEBANK") );


SetForeign( Symbol2 );
C2 = C;
H2 = H;
L2 = L;
O2 = O;
V2 = V;
RestorePriceArrays();

Color = ParamColor( "Color", colorDefault );
Style = ParamStyle( "Style", styleLine, maskPrice );


PlotOHLC( O2/O1, H2/H1, L2/L1, C2/C1, "(" + Symbol2+" / "+Symbol1 + ") spread", Color, style );

AddToComposite(C2/C1, "~Pair", "X" );

SetForeign( "~Pair" );
C3 = C;
H3 = H;
L3 = L;
O3 = O;
V3 = V;
RestorePriceArrays();

EntrySignal = Cross(EMA(C3,2),C3);
ExitSignal = Cross(C3,EMA(C3,2));

if( Name() == "^NSEI" )
{
Buy = EntrySignal;
Sell = ExitSignal;
Short= Sell;
Cover = Buy;

SetPositionSize( 100, spsShares );
}

if( Name() == "^NSEBANK" )
{
Short = EntrySignal;
Cover = ExitSignal;
Buy = Cover;
Sell = Short;

SetPositionSize( 50, spsShares );
}

_SECTION_END();
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

indiTraders - Forum for the Active Indian Trader > Technical > Indicators & Systems


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


DPonline

All times are GMT +5.5. The time now is 10:19 AM.


vBulletin Copyright by vBulletin

Content Relevant URLs by vBSEO 3.3.2