public TrendStrengthA(DataSeries ds, int periodStart, int periodEnd, int step, string description) public static TrendStrengthA 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("TrendStrengthA Period Start",30,2,300,20); slider2 = CreateParameter("TrendStrengthA Period End",110,2,300,20); slider3 = CreateParameter("TrendStrengthA Step 3",20,2,300,20); } protected override void Execute() { TrendStrengthA tsa = TrendStrengthA.Series(Close,slider1.ValueInt,slider2.ValueInt,slider3.ValueInt); ChartPane paneTrendStrengthA1 = CreatePane(40,true,true); PlotSeriesOscillator(paneTrendStrengthA1,tsa, 60, -60, Color.Green, Color.Red, Color.CadetBlue,LineStyle.Solid,1); //Usually, values above 60 (below -60) indicate 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, tsa, 60); bool xu = CrossUnder(bar, tsa, -60); // 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 ); } } } } } }