Psychological Index: Indicator Documentation
Syntax
DataSeries PsychIndex(Bars bars, int period)
Parameter Description
bars |
A Bars object |
period |
Lookback period |
Description
The Psychological Index is an overbought/oversold indicator described in the June 2000 Futures Magazine. The article described the standard lookback period as 12 bars with a level of 75% or higher being an indication of an overbought market and 25% or lower being an oversold market.
Example
A system in this example is always in the market. It goes long and short by the Psychological Index's readings:
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using Community.Indicators;
namespace WealthLab.Strategies
{
// Psychological Index
public class PsychIndex : WealthScript
{
private StrategyParameter paramLookback;
private StrategyParameter paramUpper;
private StrategyParameter paramLower;
public PsychIndex()
{
paramLookback = CreateParameter( "Lookback", 12, 3, 30, 1 );
paramUpper = CreateParameter( "Upper", 75, 0, 100, 1 );
paramLower = CreateParameter( "Lower", 25, 0, 100, 1 );
}
protected override void Execute()
{
int Lookback = paramLookback.ValueInt;
int Upper = paramUpper.ValueInt;
int Lower = paramLower.ValueInt;
PsychologicalIndex pi = PsychologicalIndex.Series( Bars, Lookback );
pi.Description = "Psychological Index";
ChartPane PsychIndexPane = CreatePane( 25, true, true );
PlotSeries( PsychIndexPane, pi, Color.Green, LineStyle.Solid, 2 );
DrawHorzLine( PsychIndexPane, Upper, Color.Blue, LineStyle.Solid, 2 );
DrawHorzLine( PsychIndexPane, Lower, Color.Red, LineStyle.Solid, 2 );
for(int bar = Lookback; bar < Bars.Count; bar++)
{
if ( Positions.Count == 0 )
{
if ( pi[bar] <= Lower )
BuyAtMarket( bar+1 ); else
if( pi[bar] >= Upper )
ShortAtMarket( bar+1 );
}
else
{
Position p = LastPosition;
if( p.PositionType == PositionType.Long )
{
if( pi[bar] >= Upper )
{
SellAtMarket( bar+1, p );
ShortAtMarket( bar+1 );
}
} else
if ( pi[bar] <= Lower )
{
CoverAtMarket( bar+1, p );
BuyAtMarket( bar+1 );
}
}
}
}
}
}