DataSeries PsychIndex(Bars bars, int period)
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 ( pibar <= Lower ) BuyAtMarket( bar+1 ); else if( pibar >= Upper ) ShortAtMarket( bar+1 ); } else { Position p = LastPosition; if( p.PositionType == PositionType.Long ) { if( pibar >= Upper ) { SellAtMarket( bar+1, p ); ShortAtMarket( bar+1 ); } } else if ( pibar <= Lower ) { CoverAtMarket( bar+1, p ); BuyAtMarket( bar+1 ); } } } } } }