public SwingHiLo( Bars bars, int LeftBars, double LeftReversalAmount, int RightBars, double RightReversalAmount, double EqualPriceThreshold, bool PercentMode, bool SetLeftSwings, bool SetOuterSwings, bool SetSteppedSeries, string description ) public SwingHiLo( Bars bars, int LeftBars, int RightBars, double EqualPriceThreshold, bool SetLeftSwings, bool SetOuterSwings, bool SetSteppedSeries, string description ) public static SwingHiLo( Bars bars, int LeftBars, double LeftReversalAmount, int RightBars, double RightReversalAmount, double EqualPriceThreshold, bool PercentMode, bool SetLeftSwings, bool SetOuterSwings, bool SetSteppedSeries)public SwingHi( DataSeries ds, int LeftBars, double LeftReversalAmount, int RightBars, double RightReversalAmount, double EqualPriceThreshold, bool PercentMode, bool SetLeftSwings, bool SetOuterSwings, bool SetSteppedSeries, string description ) public SwingHi( DataSeries ds, int LeftBars, int RightBars, double EqualPriceThreshold, bool SetLeftSwings, bool SetOuterSwings, bool SetSteppedSeries, string description ) public static SwingHi( DataSeries ds, int LeftBars, double LeftReversalAmount, int RightBars, double RightReversalAmount, double EqualPriceThreshold, bool PercentMode, bool SetLeftSwings, bool SetOuterSwings, bool SetSteppedSeries )public SwingLo( DataSeries ds, int LeftBars, double LeftReversalAmount, int RightBars, double RightReversalAmount, double EqualPriceThreshold, bool PercentMode, bool SetLeftSwings, bool SetOuterSwings, bool SetSteppedSeries, string description ) public SwingLo( DataSeries ds, int LeftBars, int RightBars, double EqualPriceThreshold, bool SetLeftSwings, bool SetOuterSwings, bool SetSteppedSeries, string description ) public static SwingLo( DataSeries ds, int LeftBars, double LeftReversalAmount, int RightBars, double RightReversalAmount, double EqualPriceThreshold, bool PercentMode, bool SetLeftSwings, bool SetOuterSwings, bool SetSteppedSeries )
public static bool IsSwingHi(int bar, DataSeries ds, int LeftBars, double LeftReversalAmount, int RightBars, double RightReversalAmount, int farback, int occur, double EqualPriceThreshold, bool PercentMode, bool SetLeftSwings, out int swHighBar)public static bool IsSwingHi(int bar, DataSeries ds, int LeftBars, int RightBars, int farback, int occur, double EqualPriceThreshold, bool SetLeftSwings, out int swHighBar)public static bool IsSwingLo(int bar, DataSeries ds, int LeftBars, double LeftReversalAmount, int RightBars, double RightReversalAmount, int farback, int occur, double EqualPriceThreshold, bool PercentMode, bool SetLeftSwings, out int swLowBar)public static bool IsSwingLo(int bar, DataSeries ds, int LeftBars, int RightBars, int farback, int occur, double EqualPriceThreshold, bool SetLeftSwings, out int swLowBar)
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using Community.Indicators; using Community.Components; /*** Requires installation of Community.Components Extension from www.wealth-lab.com > Extensions ***/namespace WealthLab.Strategies { using sw = IsSwing; public class MyStrategy : WealthScript { #region - parameter sliders & public methods - private StrategyParameter sliLeft; private StrategyParameter sliLeftPrice; private StrategyParameter sliRight; private StrategyParameter sliRightPrice; private StrategyParameter sliPercent; private StrategyParameter sliOccur; private StrategyParameter sliUseLeft; private StrategyParameter sliUseOutside; private StrategyParameter sliBoxedSeries; public MyStrategy() { sliLeft = CreateParameter("left bars", 13, 0, 30, 1); sliLeftPrice = CreateParameter("left price", 3.5, 0, 100, 0.001); sliRight = CreateParameter("right bars", 5, 1, 30, 1); sliRightPrice = CreateParameter("right price", 1.5, 0, 100, 0.001); sliPercent = CreateParameter("use percent chg", 1, 0, 1, 1); sliOccur = CreateParameter("occurence", 5, 1, 25, 1); sliUseLeft = CreateParameter("use left swing", 0, 0, 1, 1); sliUseOutside = CreateParameter("use ouside swings", 0, 0, 1, 1); sliBoxedSeries = CreateParameter("use boxed series", 0, 0, 1, 1); } string suffx(int ctr) { int th = ctr == 11 || ctr == 12 || ctr == 13 ? -1 : ctr % 10; string ret = ""; switch (th) { case 1 : ret = "st"; break; case 2 : ret = "nd"; break; case 3 : ret = "rd"; break; default: ret = "th"; break; } return ret; } #endregion protected override void Execute() { #region - variables & initial settings - PadBars(4); HideVolume(); //SetBarColors( Color.Green, Color.Red); int Lbars = sliLeft.ValueInt; double Lprice = sliLeftPrice.Value; int Rbars = sliRight.ValueInt; double Rprice = sliRightPrice.Value; bool UsePercent = sliPercent.ValueInt == 0 ? false : true; bool UseLeft = sliUseLeft.ValueInt == 0 ? false : true; bool UseOutsideSwings = sliUseOutside.ValueInt == 0 ? false : true; bool UseBoxed = sliBoxedSeries.ValueInt == 0 ? false : true; int swgLoBar; int swgHiBar; int lastLoBar = 999999; int lastHiBar = 999999; int _occur = sliOccur.ValueInt; string _params = String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", Lbars, Lprice, Rbars, Rprice, "0.00001", UsePercent, UseLeft, UseOutsideSwings, UseBoxed); #endregion DataSeries SwgHiLo = SwingHiLo.Series(Bars, Lbars, Lprice, Rbars, Rprice, 0.00001, UsePercent, UseLeft, UseOutsideSwings, UseBoxed); DataSeries SwgHi = SwingHi.Series(High, Lbars, Lprice, Rbars, Rprice, 0.00001, UsePercent, UseLeft, UseOutsideSwings, UseBoxed); DataSeries SwgLo = SwingLo.Series(Low, Lbars, Lprice, Rbars, Rprice, 0.00001, UsePercent, UseLeft, UseOutsideSwings, UseBoxed); SwgHiLo.Description = "SwingHiLo( " + _params + " )"; SwgHi.Description = "SwingHi( " + _params + " )"; SwgLo.Description = "SwgLo( " + _params + " )"; PlotSeries(PricePane, SwgHiLo, Color.FromArgb(70, Color.Gray), WealthLab.LineStyle.Solid, 5); PlotSeries(PricePane, SwgHi, Color.FromArgb(80, Color.YellowGreen), WealthLab.LineStyle.Solid, 5); PlotSeries(PricePane, SwgLo, Color.FromArgb(40, Color.Red), WealthLab.LineStyle.Solid, 5); DrawLabel(PricePane, SwgHiLo.Description, Color.Gray); DrawLabel(PricePane, SwgHi.Description, Color.Green); DrawLabel(PricePane, SwgLo.Description, Color.Red); //-- 1st Occurence looping backward each bar for(int ii = Bars.Count - 1; ii > Lbars + Rbars + 1 && ii > Bars.Count - 500; ii-- ) { if( sw.IsSwingLo( ii, Low, Lbars, Lprice, Rbars, Rprice, Rbars + 1, 1, 0.00001, UsePercent, UseLeft, out swgLoBar) ) { if( swgLoBar<lastLoBar )AnnotateBar( swgLoBar.ToString(), swgLoBar, false, Color.Black ); lastLoBar = swgLoBar; } if( sw.IsSwingHi( ii, High, Lbars, Lprice, Rbars, Rprice, Rbars + 1, 1, 0.00001, UsePercent, UseLeft, out swgHiBar) ) { if( swgHiBar<lastHiBar )AnnotateBar( swgHiBar.ToString(), swgHiBar, true, Color.Red ); lastHiBar = swgHiBar; } } //-- 1st, 2nd, 3rd 4th etc Occurences from Bars.Count - 1 for(int ii = 1; ii < 50; ii++) { _occur = ii; if( sw.IsSwingLo( Bars.Count - 1, Low, Lbars, Lprice, Rbars, Rprice, 300, _occur, 0.00001, UsePercent, UseLeft, out swgLoBar) ) { AnnotateBar( _occur.ToString() + suffx(_occur), swgLoBar, false, Color.Red ); } if( sw.IsSwingHi( Bars.Count - 1, High, Lbars, Lprice, Rbars, Rprice, 300, _occur, 0.00001, UsePercent, UseLeft, out swgHiBar) ) { AnnotateBar( _occur.ToString() + suffx(_occur), swgHiBar, true, Color.Blue ); } } } } }