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 = ActivePositionspos; if( p.PositionType == PositionType.Long ) { if( !SellAtStop( bar+1, p, p.EntryPrice * 0.8, "Stop" ) ) SellAtLimit( bar + 1, p, linregbar, "Limit" ); } else { if( !CoverAtStop( bar+1, p, p.EntryPrice * 1.2, "Stop" ) ) CoverAtLimit( bar + 1, p, linregbar, "Limit" ); } } if( Closebar > SMA.Series( Close,100)bar ) if( linregbar / Closebar > 1.04 ) if( BuyAtMarket( bar + 1 ) != null ) LastPosition.Priority = -Closebar; if( Closebar < SMA.Series( Close,100)bar ) if( Closebar / linregbar > 1.08 ) if( ShortAtMarket( bar + 1 ) != null ) LastPosition.Priority = Closebar; } } } }