for(int bar = 20; bar < Bars.Count; bar++) { // do something with the variable bar } if( bar == 100 ) DrawLabel( PricePane, "We hit bar " + bar.ToString() ); }
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() { SMA hSMA1 = SMA.Series( Close, 10 ); SMA hSMA2 = SMA.Series( Close, 20 ); PlotSeries( PricePane, hSMA1, Color.Blue, LineStyle.Solid, 1 ); PlotSeries( PricePane, hSMA2, Color.Red, LineStyle.Solid, 1 ); for(int bar = 20; bar < Bars.Count; bar++) { if (!IsLastPositionActive) { if( CrossOver( bar, hSMA1, hSMA2 ) ) BuyAtMarket( bar+1 ); } else { Position p = LastPosition; if( CrossUnder( bar, hSMA1, hSMA2 ) ) SellAtMarket( bar+1, p ); } } } } }