public static int CheckExtendedTrendline(this WealthScript obj, int bar, ChartPane pane, DataSeries ds, int bar1, int bar2, Color linecolor, int thickness, int consecBars = 1)public int CheckExtendedTrendline(int bar, ChartPane pane, DataSeries ds, int bar1, int bar2, Color linecolor, int thickness, int consecBars = 1)
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class ExtendTrendlinesExample : WealthScript { StrategyParameter _pctpeaks; public ExtendTrendlinesExample() { _pctpeaks = CreateParameter("Peaks %", 5, 1, 20, 1); } protected override void Execute() { // Find the last two n% peaks and draw a line to the end of the chart int n = Bars.Count - 1; int pb2 = (int)PeakBar.Value(n, High, _pctpeaks.Value, WealthLab.Indicators.PeakTroughMode.Percent); int pb1 = pb2; if (pb2 > -1) { pb1 = (int)PeakBar.Value(pb2, High, _pctpeaks.Value, WealthLab.Indicators.PeakTroughMode.Percent); DrawCircle(PricePane, 8, pb2, High[pb2], Color.Blue, LineStyle.Solid, 2, false); } if ((pb2 == -1) || (pb1 == -1)) { DrawLabel(PricePane, "Could not find two " + _pctpeaks.Value.ToString() + "% peaks", Color.Red); DrawLabel(PricePane, "Try decreasing the Peaks % value", Color.Red); return; } // The trendline is defined. Check if it's crossed... DrawCircle(PricePane, 8, pb1, High[pb1], Color.Blue, LineStyle.Solid, 2, false); int consecBarsCrossedTrendline = 2; for (int bar = pb2 + 1; bar < Bars.Count; bar++) { int crossbar = this.CheckExtendedTrendline(bar, PricePane, High, pb1, pb2, Color.Purple, 2, consecBarsCrossedTrendline); if (crossbar > 0) { string msg = Bars.Symbol + ", crossed " + consecBarsCrossedTrendline + " consecutive times at bar: " + crossbar; DrawLabel(PricePane, msg); break; } } } } }