public ATR(WealthLab.Bars bars, int period, string description) public static ATR Series(WealthLab.Bars bars, int period) public static double Value(int bar, WealthLab.Bars bars, int period)
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class RatchetStrategy : WealthScript { private StrategyParameter paramUnit; private StrategyParameter paramATR; private StrategyParameter paramLow; public RatchetStrategy() { paramUnit = CreateParameter("Unit", 0.05, 0.01, 0.1, 0.01); paramATR = CreateParameter("ATR period", 20, 2, 30, 2); paramLow = CreateParameter("Lowest low", 55, 5, 200, 5); } protected override void Execute() { int low = paramLow.ValueInt; int atr = paramATR.ValueInt; double unit = paramUnit.Value; DataSeries AtrRatchet = new DataSeries(Bars,"Ratchet"); PlotSeries(PricePane,AtrRatchet,Color.Red,LineStyle.Dots,4); for(int bar = GetTradingLoopStartBar(Math.Max(low,atr)); bar < Bars.Count; bar++) { AtrRatchet[bar] = Close[bar]; SetSeriesBarColor( bar, AtrRatchet, Color.Transparent ); if (IsLastPositionActive) { int daysintrade = bar - LastPosition.EntryBar; double ratchet = ( ATR.Series(Bars,atr)[bar] * unit ) * daysintrade; double sellprice = Lowest.Series(Low,low)[bar] + ratchet; AtrRatchet[bar] = sellprice; SetSeriesBarColor( bar, AtrRatchet, Color.Red ); if( Low[bar] < sellprice ) SellAtMarket(bar+1,LastPosition); } else { if(CrossOver(bar,Close,SMA.Series(Close,20))) BuyAtMarket(bar+1); } } } } }
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class MyStrategy : WealthScript { // Thank you fundtimer public Color WS4ColorToNET( double WS4Color ) { return Color.FromArgb( (int)Math.Floor( ( WS4Color % 1000 ) / 100 * 28.4 ), (int)Math.Floor( ( WS4Color % 100 ) / 10 * 28.4 ), (int)Math.Floor( WS4Color % 10 * 28.4 ) ); } protected override void Execute() { // Plot ATRs in decreasing length if increasing blue intensity ChartPane ATRPane = CreatePane( 50, true, true ); DrawLabel( ATRPane, "ATR from 2 to 18", Color.Black ); for( int i = 1; i < 10; i++ ) PlotSeries( ATRPane, ATR.Series( Bars, i * 2 ), WS4ColorToNET(10-i), LineStyle.Solid, 1 ); } } }