public InSyncIndex(Bars bars, string description) public static InSyncIndex Series(Bars bars)
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 InSyncDemo : WealthScript { private StrategyParameter param1; private StrategyParameter param2; public InSyncDemo() { param1 = CreateParameter("Threshold 1", 5, 5, 35, 5); param2 = CreateParameter("Threshold 2", 95, 65, 95, 5); } protected override void Execute() { int t1 = param1.ValueInt; int t2 = param2.ValueInt; InSyncIndex i = InSyncIndex.Series( Bars ); ChartPane iPane = CreatePane( 30, true, false ); PlotSeries( iPane, i, Color.Blue, LineStyle.Solid, 1); DrawHorzLine( iPane, t1, Color.Black, LineStyle.Dashed, 1 ); DrawHorzLine( iPane, t2, Color.Black, LineStyle.Dashed, 1 ); HideVolume(); for(int bar = i.FirstValidValue * 3; bar < Bars.Count; bar++) { bool buy = (ibar > t1) && (ibar-1 < t1); bool sell = (ibar < t2) && (ibar-1 > t2); // The first trade if (Positions.Count == 0){ if ( buy ) BuyAtMarket( bar + 1 ); else if( sell ) ShortAtMarket( bar + 1 ); } // Subsequent trades else { Position p = LastPosition; if ( p.PositionType == PositionType.Long ) { if ( sell ) { SellAtMarket( bar + 1, p ); ShortAtMarket( bar + 1 ); } } else if ( buy ) { CoverAtMarket( bar + 1, p ); BuyAtMarket( bar + 1 ); } } } } } }