DataSeries NewMax( DataSeries series, 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 { public class NewMaxStrategy : WealthScript { private StrategyParameter paramperiod; private StrategyParameter paramexit_limit; public NewMaxStrategy() { paramperiod = CreateParameter( "period", 24, 5, 50, 5 ); paramexit_limit = CreateParameter( "exit_limit", 95, 90, 100, 1 ); } protected override void Execute() { LineStyle ls = LineStyle.Solid; int period = paramperiod.ValueInt; double exit_limit = paramexit_limit.Value; // Indicators NewMax new_high_s = NewMax.Series( High,period ); NewMax new_low_s = NewMax.Series( Low,period ); // Graphics HideVolume(); ChartPane newm_p = CreatePane( 50, false, true ); SetPaneMinMax(newm_p, -100, 100); PlotSeries( newm_p, new_high_s, Color.Green, ls, 1 ); // New High PlotSeries( newm_p, new_low_s, Color.Red, ls, 1 ); // New Low // Trading for(int bar = 20; bar < Bars.Count; bar++) { if (!IsLastPositionActive) { if( new_high_sbar >= 100.0 ) ShortAtMarket( bar+1, "new high" ); if( new_low_sbar <= -100.0 ) BuyAtMarket( bar+1, "new low" ); } else { Position p = LastPosition; if( ( p.PositionType == PositionType.Long ) & ( new_high_sbar >= -exit_limit ) ) SellAtMarket( bar+1, p, "end of uptrend" ); if( ( p.PositionType == PositionType.Short ) & ( new_low_sbar <= exit_limit ) ) CoverAtMarket( bar+1, p, "end of downtrend" ); } } } } }