using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class TradersTips_Nov2020 : WealthScript { protected override void Execute() { int Period = 21; var ls = LineStyle.Solid; HideVolume(); // Access the symbol from a DataSet whose base scale is intraday. Do not synch yet! Bars i60 = GetExternalSymbol("Tiingo (Minute,60)", Bars.Symbol, false); // Apply the indicator in the intraday scale DataSeries sto_60 = StochK.Series(i60, Period); sto_60.Description = "60-minute"; SetScaleDaily(); DataSeries sto_d = StochK.Series(Bars, Period); sto_d.Description = "Daily"; SetScaleWeekly(); DataSeries sto_w = StochK.Series(Bars, Period); sto_w.Description = "Weekly"; SetScaleMonthly(); DataSeries sto_m = StochK.Series(Bars, Period); sto_m.Description = "Monthly"; RestoreScale(); DataSeries sto_q = StochK.Series(BarScaleConverter.ToQuarterly(Bars), Period); DataSeries sto_y = StochK.Series(BarScaleConverter.ToYearly(Bars), Period); sto_q.Description = "Quarterly"; sto_y.Description = "Yearly"; sto_60 = Synchronize( sto_60); sto_d = Synchronize( sto_d); sto_w = Synchronize( sto_w); sto_m = Synchronize( sto_m); sto_q = Synchronize( sto_q); sto_y = Synchronize( sto_y); //Determine the first valid bar var start = Math.Max(sto_60.FirstValidValue, Math.Max(sto_d.FirstValidValue, Math.Max(sto_w.FirstValidValue, Math.Max(sto_m.FirstValidValue, Math.Max(sto_q.FirstValidValue, sto_y.FirstValidValue))))); ChartPane sPane = CreatePane( 20, false, true); PlotSeries( sPane, sto_60, Color.Peru, ls, 1); PlotSeries( sPane, sto_d, Color.Chartreuse, ls, 1); PlotSeries( sPane, sto_w, Color.Gainsboro, ls, 1); PlotSeries( sPane, sto_m, Color.Sienna, ls, 1); PlotSeries( sPane, sto_q, Color.IndianRed, ls, 1); PlotSeries( sPane, sto_y, Color.NavajoWhite, ls, 1); DataSeries buyVote = new DataSeries(Bars, "Buy Voting"); DataSeries sellVote = new DataSeries(Bars, "Sell Voting"); for (int bar = 1; bar < Bars.Count; bar++) { if (sto_60[bar] < 20) buyVote[bar]++; if (sto_d[bar] < 20) buyVote[bar]++; if (sto_w[bar] < 20) buyVote[bar]++; if (sto_m[bar] < 20) buyVote[bar]++; if (sto_q[bar] < 20) buyVote[bar]++; if (sto_y[bar] < 20) buyVote[bar]++; if (sto_60[bar] > 80) sellVote[bar]++; if (sto_d[bar] > 80) sellVote[bar]++; if (sto_w[bar] > 80) sellVote[bar]++; if (sto_m[bar] > 80) sellVote[bar]++; if (sto_q[bar] > 80) sellVote[bar]++; if (sto_y[bar] > 80) sellVote[bar]++; } ChartPane vPane = CreatePane( 40, false, true ); PlotSeries( vPane, buyVote, Color.Blue, ls, 1); PlotSeries( vPane, sellVote, Color.Red, ls, 1); DrawHorzLine( vPane, 20, Color.Blue, LineStyle.Dashed, 1); DrawHorzLine( vPane, 80, Color.Red, LineStyle.Dashed, 1); bool setup = false; int setupBar = -1; //Start trading only after all DataSeries are complete for (int bar = start; bar < Bars.Count; bar++) { bool buySetup = buyVote[bar] >= 5 && sellVote[bar] == 0; bool buyTrigger = sellVote[bar] > 0; for (int pos = ActivePositions.Count - 1; pos >= 0; pos--) { Position p = ActivePositions[pos]; if (buyVote[bar] == 0) SellAtMarket( bar + 1, p); } if (!setup) { if (buySetup) { setup = true; setupBar = bar; } } if (setup) { if (buyTrigger) if ( BuyAtMarket( bar + 1) != null ) setup = false; SetBackgroundColor( bar, Color.FromArgb(30, Color.Green)); } } } } }