public static double ChandelierStop(this Position p, Bars bars, int bar, int period, double coefficient )public double ChandelierStop(Bars bars, int bar, Position p, int period, double coefficient )
Chandelier Stop demonstration
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class ChandelierDemo : WealthScript { protected override void Execute() { // Variable that will hold Chandelier stop value double chandelierStop = 0.0; PlotStops(); // Ensure Chandelier stop visibility for(int bar = Bars.FirstActualBar + 10; bar < Bars.Count; bar++) { if (IsLastPositionActive) { // Let's work directly with the list of active positions, introduced in WL5 for( int p = ActivePositions.Count - 1; p > -1 ; p-- ) { Position pos = ActivePositions[p]; // Request Chandelier stop value using Period: 14, Coefficient: 3 chandelierStop = pos.ChandelierStop( Bars, bar, 14, 3 ); if( pos.PositionType == PositionType.Long ) SellAtTrailingStop( bar + 1, pos, chandelierStop, "Chandelier LX"); else if( pos.PositionType == PositionType.Short ) CoverAtTrailingStop( bar + 1, pos, chandelierStop, "Chandelier SX"); } } else { if( DIPlus.Series( Bars, 10 )[bar] > 1.5 * DIMinus.Series( Bars, 10 )[bar] ) if( Low[bar] <= KeltnerLower.Series( Bars, 10, 10)[bar] ) BuyAtMarket( bar + 1 ); if( DIMinus.Series( Bars, 10 )[bar] > 1.5 * DIPlus.Series( Bars, 10 )[bar] ) if( High[bar] >= KeltnerUpper.Series( Bars, 10, 10)[bar] ) ShortAtMarket( bar + 1 ); } } } } }
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using Community.Components; // includes Chandelier Stop /*** Requires installation of Community.Components Extension from www.wealth-lab.com > Extensions ***/namespace WealthLab.Strategies { public class ChandelierDemo : WealthScript { protected override void Execute() { // Create an instance of the class that returns Chandelier stop value SeriesHelper obj = new SeriesHelper( this ); // Variable that will hold Chandelier stop value double chandelierStop = 0.0; PlotStops(); // Ensure Chandelier stop visibility for(int bar = Bars.FirstActualBar + 10; bar < Bars.Count; bar++) { if (IsLastPositionActive) { // Let's work directly with the list of active positions, introduced in WL5 for( int p = ActivePositions.Count - 1; p > -1 ; p-- ) { Position pos = ActivePositions[p]; // Request Chandelier stop value using Period: 14, Coefficient: 3 chandelierStop = obj.ChandelierStop( Bars, bar, pos, 14, 3 ); if( pos.PositionType == PositionType.Long ) SellAtTrailingStop( bar + 1, pos, chandelierStop, "Chandelier LX"); else if( pos.PositionType == PositionType.Short ) CoverAtTrailingStop( bar + 1, pos, chandelierStop, "Chandelier SX"); } } else { if( DIPlus.Series( Bars, 10 )[bar] > 1.5 * DIMinus.Series( Bars, 10 )[bar] ) if( Low[bar] <= KeltnerLower.Series( Bars, 10, 10)[bar] ) BuyAtMarket( bar + 1 ); if( DIMinus.Series( Bars, 10 )[bar] > 1.5 * DIPlus.Series( Bars, 10 )[bar] ) if( High[bar] >= KeltnerUpper.Series( Bars, 10, 10)[bar] ) ShortAtMarket( bar + 1 ); } } } } }