using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { int period = 20; DataSeries linreg = LinearReg.Series( Close, period ); SMA MovAvg = SMA.Series( Close, period ); PlotSeries( PricePane, linreg, Color.Navy, WealthLab.LineStyle.Solid, 3 ); PlotSeries( PricePane, MovAvg, Color.Gray, WealthLab.LineStyle.Solid, 1 ); for(int bar = 100; bar < Bars.Count; bar++) { for (int pos = ActivePositions.Count - 1; pos >= 0; pos--) { Position p = ActivePositions[pos]; if( p.PositionType == PositionType.Long ) { if( !SellAtStop( bar+1, p, p.EntryPrice * 0.8, "Stop" ) ) SellAtLimit( bar + 1, p, linreg[bar], "Limit" ); } else { if( !CoverAtStop( bar+1, p, p.EntryPrice * 1.2, "Stop" ) ) CoverAtLimit( bar + 1, p, linreg[bar], "Limit" ); } } if( Close[bar] > SMA.Series( Close,100)[bar] ) if( linreg[bar] / Close[bar] > 1.04 ) if( BuyAtMarket( bar + 1 ) != null ) LastPosition.Priority = -Close[bar]; if( Close[bar] < SMA.Series( Close,100)[bar] ) if( Close[bar] / linreg[bar] > 1.08 ) if( ShortAtMarket( bar + 1 ) != null ) LastPosition.Priority = Close[bar]; } } } }