public static Bars GetAllDataForSymbol(this string symbol, BarScale scale, int barInterval) public static Bars GetAllDataForSymbol(this string symbol, string dataSet, BarScale scale, int barInterval)
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() { //Bars b = Bars.Symbol.GetAllDataForSymbol( Bars.Scale, Bars.BarInterval ); Bars b = Bars.Symbol.GetAllDataForSymbol( "Dow 30", Bars.Scale, Bars.BarInterval ); DataSeries sma = SMA.Series( b.Close, 200 ); sma = Synchronize( sma ); PlotSeries( PricePane, sma, Color.Blue, LineStyle.Solid, 2 ); for(int bar = 1; bar < Bars.Count; bar++) { if (IsLastPositionActive) { if( CrossUnder( bar, Close, sma ) ) SellAtMarket( bar+1, LastPosition ); } else { if( CrossOver( bar, Close, sma ) ) BuyAtMarket( bar+1 ); } } } } }
/* Example of how to work with "full history" Weekly bars in a Weekly chart derived from a Daily Bars source */ // GetAllDataForSymbol doesn't return scaled bars Bars basebars = Bars.Symbol.GetAllDataForSymbol( this.GetDataSetName(), Bars.Scale, Bars.BarInterval ); PrintDebug(basebars.Count); // Rescale to weekly Bars bars = new Bars(Bars.Symbol, Bars.Scale, Bars.BarInterval); DateTime dt = basebars.Date[0]; double o = basebars.Open[0]; double h = basebars.High[0]; double l = basebars.Low[0]; double c = basebars.Close[0]; double v = basebars.Volume[0]; for (int bar = 1; bar < basebars.Count; bar++) { if (basebars.Date[bar].DayOfWeek < dt.DayOfWeek) { bars.Add(dt, o, h, l, c, v); dt = basebars.Date[bar]; o = basebars.Open[bar]; h = basebars.High[bar]; l = basebars.Low[bar]; c = basebars.Close[bar]; v = basebars.Volume[bar]; } else { dt = basebars.Date[bar]; c = basebars.Close[bar]; if (basebars.High[bar] > h) h = basebars.High[bar]; if (basebars.Low[bar] < l) l = basebars.Low[bar]; v += basebars.Volume[bar]; } } bars.Add(dt, o, h, l, c, v); // Now you can create indicator(s) based on full-history Weekly data DataSeries sma20 = SMA.Series(bars.Close, 20); // Synchronize with the chart sma20 = Synchronize(sma20); PlotSeries(PricePane, sma20, Color.Blue, LineStyle.Solid, 2);