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 TASC201405Pendergast : WealthScript { protected override void Execute() { const char tab = '\u0009'; string item = "z Zacks Adjusted Earnings"; IList fList = FundamentalDataItems(item); DataSeries e = FundamentalDataSeries(item); ChartPane ep = CreatePane( 20, true, true ); PlotFundamentalItems(ep, item, Color.Green, WealthLab.LineStyle.Invisible, 1); DrawLabel(ep, "Earnings by Zacks"); if( fList.Count == 0 ) { DrawLabel( PricePane, "Update Zacks Adjusted Earnings data before running the Strategy"); Abort(); } DrawLabel(PricePane, Bars.Symbol + tab + tab + "Earnings count: " + fList.Count); DrawLabel(PricePane, "Date" + tab + tab + "EPS" + tab + "Estimate" + tab + "Surprise"); foreach (FundamentalItem fi in fList) { DrawLabel(PricePane, fi.Date.ToShortDateString() + tab + fi.Value.ToString() + tab + fi.GetDetail("estimate") + tab + fi.GetDetail("surprise")); } Bars spx = GetExternalSymbol("^GSPC", true); // Yahoo data Beta beta = Beta.Series( Bars, spx,200); ChartPane pb = CreatePane( 20, true, true ); PlotSeries( pb, beta, Color.DarkMagenta, LineStyle.Solid, 2 ); DrawHorzLine( pb, 1.0, Color.DarkMagenta, LineStyle.Dashed, 1 ); DataSeries smaAvgVol = SMA.Series(Volume, 10); PlotSeries( VolumePane, smaAvgVol, Color.Red, LineStyle.Solid, 2 ); DataSeries ema = EMA.Series(Close,200,EMACalculation.Modern); DataSeries ema6 = EMA.Series( Close,6,EMACalculation.Modern); PlotSeries( PricePane, ema, Color.Blue, LineStyle.Solid, 2 ); PlotSeries( PricePane, ema6, Color.Red, LineStyle.Solid, 1 ); DataSeries rsi = RSI.Series(Close,2); ChartPane pr = CreatePane( 20, true, true ); PlotSeries( pr, rsi, Color.BlueViolet, LineStyle.Solid, 2 ); DrawHorzLine( pr, 5, Color.Red, LineStyle.Dashed, 1 ); for(int bar = 2; bar < Bars.Count; bar++) { if ( rsibar < 5 ) SetSeriesBarColor( bar, rsi, Color.Red ); if ( betabar > 1 ) SetSeriesBarColor( bar, beta, Color.Blue ); } bool SetupValid = false; for(int bar = GetTradingLoopStartBar(200); bar < Bars.Count; bar++) { if (IsLastPositionActive) { SellAtTrailingStop( bar+1, LastPosition, Lowest.Series( Low, 20 )bar, "Trailing Stop" ); } else { if( !SetupValid ) { bool rsi2 = rsibar < 5; bool ema200 = Closebar > emabar; bool avgVol = smaAvgVolbar >= 1000000; bool surprise = false; for(int i = fList.Count-1; i >= 0; i--) { if( bar > fListi.Bar ) { surprise = ( Double.Parse( fListi.GetDetail("surprise").Replace("+","").Replace("$","") ) > 0 ); break; } } bool bet = betabar > 1.0; if( surprise ) SetBackgroundColor( bar, Color.FromArgb(30,Color.Green) ); if( rsi2 && ema200 && avgVol && surprise && bet ) SetupValid = true; } if( SetupValid ) { if( CrossOver( bar, rsi, 5 ) ) if( BuyAtMarket(bar+1) != null ) SetupValid = false; } } } } } }