public TrendStrengthB(DataSeries ds, int periodStart, int periodEnd, int step, string description) public static TrendStrengthB Series(DataSeries ds, int periodStart, int periodEnd, int step)
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 MyStrategy : WealthScript { private StrategyParameter slider1; private StrategyParameter slider2; private StrategyParameter slider3; public MyStrategy() { slider1 = CreateParameter("TrendStrengthB Period Start",30,2,300,20); slider2 = CreateParameter("TrendStrengthB Period End",110,2,300,20); slider3 = CreateParameter("TrendStrengthB Step 3",20,2,300,20); } protected override void Execute() { TrendStrengthB tsb = TrendStrengthB.Series(Close,slider1.ValueInt,slider2.ValueInt,slider3.ValueInt); ChartPane paneTrendStrengthB = CreatePane(40,true,true); PlotSeriesOscillator(paneTrendStrengthB,tsb, 60, -60, Color.Green, Color.Red, Color.CadetBlue,LineStyle.Solid,1); //Let's consider values above 0.6 (below -0.6) indicating a strong up- (down-) trend whereas values in-between indicate a sideways market. for(int bar = GetTradingLoopStartBar(1); bar < Bars.Count; bar++) { // Detect crossover/crossunder and store state in a variable bool xo = CrossOver(bar, tsb, 0.6); bool xu = CrossUnder(bar, tsb, -0.6); // The first trade if (Positions.Count == 0){ if ( xo ) BuyAtMarket( bar + 1 ); else if( xu ) ShortAtMarket( bar + 1 ); } // Subsequent trades else { Position p = LastPosition; if ( p.PositionType == PositionType.Long ) { if ( xu ) { SellAtMarket( bar + 1, p ); ShortAtMarket( bar + 1 ); } } else if ( xo ) { CoverAtMarket( bar + 1, p ); BuyAtMarket( bar + 1 ); } } } } } }