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.Date0; double o = basebars.Open0; double h = basebars.High0; double l = basebars.Low0; double c = basebars.Close0; double v = basebars.Volume0; for (int bar = 1; bar < basebars.Count; bar++) { if (basebars.Datebar.DayOfWeek < dt.DayOfWeek) { bars.Add(dt, o, h, l, c, v); dt = basebars.Datebar; o = basebars.Openbar; h = basebars.Highbar; l = basebars.Lowbar; c = basebars.Closebar; v = basebars.Volumebar; } else { dt = basebars.Datebar; c = basebars.Closebar; if (basebars.Highbar > h) h = basebars.Highbar; if (basebars.Lowbar < l) l = basebars.Lowbar; v += basebars.Volumebar; } } 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);