Register FAQ Calendar Mark Forums Read

 Indicators & Systems Compendium of Code

05-03-2014, 02:56 AM
 CoderTrader Regulars Join Date: Dec 2010 Posts: 219 Thanks: 76 Thanked 194 Times in 109 Posts

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 );```
 The Following 2 Users Say Thank You to CoderTrader For This Useful Post:
05-03-2014, 01:03 PM
 kkseal Hip-py Join Date: Apr 2009 Posts: 4,966 Thanks: 6,545 Thanked 9,535 Times in 4,111 Posts

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
 The Following User Says Thank You to kkseal For This Useful Post:
07-05-2014, 11:41 AM
 veepsirtt Newbie Join Date: Jun 2009 Posts: 7 Thanks: 0 Thanked 3 Times in 1 Post
Back testing NIFTY and BANKNIFTY pair

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

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 );

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" )
{
Sell = ExitSignal;
Short= Sell;

SetPositionSize( 100, spsShares );
}

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

SetPositionSize( 50, spsShares );
}

_SECTION_END();

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are Off Pingbacks are On Refbacks are On Forum Rules

All times are GMT +5.5. The time now is 08:16 PM.