Convert XTL indicator from Ninjatrader to ToS?

S

Saylarr

Member
Hello,

I wanted to know if anyone has or knows where to get the XTL indicator (expert trend locator) that paints the bars of the chart.

I've been searching the internet but only got it for Ninjatrader 8. But I don't know how to transcribe them to thinkscript. I leave the link.

https://futures.io/attachments/241239d1505149286

Sorry for my English, I am using the translator.

Cheers
 
Last edited by a moderator:
A

ABCswing

New member
Can someone convert the following scripts from NinjaTrader to ThinkorSwim?

Thanks

XTL TQR

Code:
#region Using declarations
using System;
                            using System.Collections;
                            using System.Collections.Generic;
                            using System.ComponentModel;
                            using System.ComponentModel.DataAnnotations;
                            using System.Diagnostics.CodeAnalysis;
                            using System.Windows;
                            using System.Reflection;
                            using System.Windows.Media;
                            using System.Xml.Serialization;
                            using NinjaTrader.Cbi;
                            using NinjaTrader.Data;
                            using NinjaTrader.Gui;
                            using NinjaTrader.Gui.Chart;
                            using NinjaTrader.Gui.Tools;
                            using NinjaTrader.NinjaScript.DrawingTools;
                            using NinjaTrader.NinjaScript.Indicators;
    ///basura del 7                    
 
                    ///        using NinjaTrader.Gui.Design;
 
 
    using System.Drawing;
   /// using System.Drawing.Drawing2D;
                         
                         
#endregion




 
namespace NinjaTrader.NinjaScript.Indicators
{
    [Description("Expert Trend Locator. Similar to eSignal Advanced Get XTL")]
    public class CharlieF_XTL : Indicator
    {
        private int indxx;
        private bool showalerts = false; // Default setting for ShowAlerts
        private bool showarrows = false; // Default setting for ShowArrows
        private int CCI_period     = 35; // Default setting for CCI_Period
        private int TGT_value     = 37; // Default setting for TGT_value
        private Brush candleColorUp = Brushes.Blue;
        private Brush candleColorDown = Brushes.Red;
        private Brush candleColorFlat = Brushes.Black;
        private int TQRActived;
        private double TQREntry;
        private int TQRstarted;
        private double TQRStop;
        private int TQRtrend;
        private int trend_0;
        private int trend_1;
        private int trend_2;
        private int trend_3;
        private int trend_upd = -1;
     
       /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        private void Initialize()
        {
            IsOverlay                = true;
            Calculate = Calculate.OnEachTick;
            /* NT8 REMOVED: PriceTypeSupported    = false */;
            PaintPriceMarkers     = false;
        }

        protected override void OnStateChange()
        {
            switch (State)
            {
                case State.SetDefaults:
                    Name = "XTL con TQR";
                    Description = "X T L - con el traquer";
                    Initialize();
                    break;
             }
        }

     
     
     
     
     
        public override string ToString()
        {
            return Name;
        }
     
        protected override void OnBarUpdate()
        {
            if (base.CurrentBar != this.trend_upd)
            {
                this.trend_3 = this.trend_2;
                this.trend_2 = this.trend_1;
                this.trend_1 = this.trend_0;
                this.trend_upd = base.CurrentBar;
            }
            ///if (base.SMA(base.Close, this.period1)[0] > base.SMA(base.Close, this.period2)[0])
            if ( (base.CCI(this.CCI_period)[0]) > this.TGT_value ) //XTL Up Calculation
            {
                base.CandleOutlineBrush = Brushes.Blue;
                this.trend_0 = 1;
     
                if (base.Open[0] < base.Close[0])
                {
                    base.BarBrush = Brushes.Transparent;
                }
                else
                {
                    base.BarBrush = Brushes.Blue;
                }
         
            /*    CandleOutlineColor = candleColorUp;
                BarColor  = candleColorUp;
                this.trend_0 = 1; */
            }
            else if ( (base.CCI(this.CCI_period)[0]) < -(this.TGT_value) ) //XTL Dn Calculation
            {
                base.CandleOutlineBrush = Brushes.Red;
                this.trend_0 = 2;
     
                if (base.Open[0] < base.Close[0])
                {
                    base.BarBrush = Brushes.Transparent;
                }
                else
                {
                    base.BarBrush = Brushes.Red;
                }
             
            /*    CandleOutlineColor = candleColorDown;
                BarColor  = candleColorDown;
                this.trend_0 = 2; */
            }
            else ///if (((base.CCI(this.CCI_Period)[0]) <= this.TGT_value) && ((base.CCI(this.CCI_Period)[0]) >= -(this.TGT_value))) //XTL Flat calculation
            {
                base.CandleOutlineBrush = Brushes.Black;
                ///this.trend_0 = 3; Find the solution for this trend NOT show the BOX.
     
                if (base.Open[0] < base.Close[0])
                {
                    base.BarBrush = Brushes.Transparent;
                }
                else
                {
                    base.BarBrush = Brushes.Black;
                }
             
            /*    CandleOutlineColor = candleColorFlat;
                BarColor  = candleColorFlat;    */
            }
         
            ///===ShowAlerts: When Candle changes Color===///
    //        if (showalerts)
    //        {
    //            if (CrossAbove(base.CCI(this.CCI_period), this.TGT_value, 1))
    //            {
    //                Alert("XLT Blue Bar",NinjaTrader.Cbi.Priority.Low,"XLT Blue Bar","Alert4.wav",60,Color.Navy,Color.PaleGreen);
    //            }
    //            else if (CrossBelow(base.CCI(this.CCI_period), -this.TGT_value, 1))
    //            {
    //                Alert("XLT Red Bar",NinjaTrader.Cbi.Priority.Low,"XLT Red Bar","Alert4.wav",60,Color.Navy,Color.LightSalmon);
    //            }
    //        }
            ///===ShowArrows===///
            if (showarrows)
            {
                if (CrossAbove(base.CCI(this.CCI_period), this.TGT_value, 1))
                {
                    //DrawArrowUp("My up arrow" + CurrentBar, false, 0, High[0] + (High[0]-Low[0]), Color.Cyan);
                 
                    Draw.ArrowUp(this, "My up arrow" + CurrentBar, false, 0, High[0] + (High[0]-Low[0]), Brushes.Cyan);
                 
                 
                }
                else if (CrossBelow(base.CCI(this.CCI_period), -this.TGT_value, 1))
                {
                //    DrawArrowDown("My dn arrow" + CurrentBar, false, 0, Low[0] - (High[0]-Low[0]), Color.Magenta);
                Draw.ArrowDown(this, "My dn arrow" + CurrentBar, false, 0, Low[0] - (High[0]-Low[0]), Brushes.Magenta);
                }    
            }
         
            if (base.CurrentBar >= 4) ///Change 4 to 2
            {
                if(
                    ((this.TQRActived == 1) && (((this.TQRtrend == 1) && (base.Low[0] < this.TQRStop)) || ((this.TQRtrend == 2) && (base.High[0] > this.TQRStop))))
                    ||
                    (((base.CCI(this.CCI_Period)[0]) <= this.TGT_value) && ((base.CCI(this.CCI_Period)[0]) >= -(this.TGT_value))) ///Added this line for rePlotZone after black color state.
                  )
                {
                    this.RemoveZone();
                }
             
                if (base.IsFirstTickOfBar)
                {
                    if ( (this.trend_1 != this.trend_2) || ( this.TQRActived == 0 && (((base.CCI(this.CCI_period)[1]) > this.TGT_value ) || ((base.CCI(this.CCI_period)[1]) < -(this.TGT_value)))) )
                    {
                        this.RemoveZone();
                        this.SetZone();
                        this.PlotZone(0);    ///this.PlotZone(0);
                    }
                    else if ( this.TQRActived == 1 )
                    {
                        this.PlotZone(1);
                    }
                }
            }
        }

        private void PlotZone(int BarEnd)
        {
            Draw.Line(this, "EntryLine", true, base.CurrentBar - this.TQRstarted, this.TQREntry, BarEnd, this.TQREntry, (this.TQRtrend == 1) ? Brushes.Blue : Brushes.Red, DashStyleHelper.Solid, (BarEnd > 0) ? 2 : 1);
            Draw.Line(this, "StopLine", true, base.CurrentBar - this.TQRstarted, this.TQRStop, BarEnd, this.TQRStop, Brushes.Red, DashStyleHelper.Dash, (BarEnd > 0) ? 2 : 1);
         
         
         
         
            if (BarEnd > 0)
            {
                Draw.Rectangle(this, "ColourZone", false, base.CurrentBar - this.TQRstarted, this.TQREntry, BarEnd, this.TQRStop, Brushes.Transparent, (this.TQRtrend == 1) ? Brushes.LightBlue : Brushes.LightSalmon, 3);
       
         
            }
        }

        private void RemoveZone()
        {
            this.TQRActived = 0;
            this.TQRstarted = 0;
            this.TQRtrend = 0;
            this.TQREntry = 0.0;
            this.TQRStop = 0.0;
            base.RemoveDrawObject("EntryLine");
            base.RemoveDrawObject("StopLine");
            base.RemoveDrawObject("ColourZone");
        }

        private void SetZone()
        {
            this.TQRActived = 1;
            this.TQRstarted = base.CurrentBar - 1;
            this.TQRtrend = (this.trend_1 == 1) ? 1 : 2;
            this.TQREntry = (this.TQRtrend == 1) ? (base.High[1] + ((base.High[1] - base.Low[1]) / 2.0)) : (base.Low[1] - ((base.High[1] - base.Low[1]) / 2.0));
            this.TQRStop = (this.TQRtrend == 1) ? (base.Low[1] - ((base.High[1] - base.Low[1]) / 2.0)) : (base.High[1] + ((base.High[1] - base.Low[1]) / 2.0));
        }

#region Properties
             
        [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
     [NinjaScriptProperty]
        [Display(Name = "Candle Color Up", Description = "Candle Color Up.", GroupName = "Parameters", Order = 1)]
        public Brush CandleColorUp
        {
            get { return candleColorUp; }
            set { candleColorUp = value; }
        }

        /// <summary>
        /// </summary>
        [Browsable(false)]
        public string candleColorUpSerialize
        {
            get { return Serialize.BrushToString(candleColorUp); }
            set { candleColorUp = Serialize.StringToBrush(value); }
        }
     
     
        /// <summary>
        /// </summary>
        [XmlIgnore()]
     
     
        [NinjaScriptProperty]    
     
        [Display(Name = "Candle Color Flat", Description = "Candle Color Flat.", GroupName = "Parameters", Order = 1)]
        public Brush CandleColorFlat
        {
            get { return candleColorFlat; }
            set { candleColorFlat = value; }
        }
     
        /// <summary>
        /// </summary>
        [Browsable(false)]
        public string candleColorFlatSerialize
        {
            get { return Serialize.BrushToString(candleColorFlat); }
            set { candleColorFlat = Serialize.StringToBrush(value); }
        }
             
        /// <summary>
        /// </summary>
        [XmlIgnore()]
             
        [NinjaScriptProperty]            
        [Display(Name = "Candle Color Down", Description = "Candle Color Down.", GroupName = "Parameters", Order = 1)]
        public Brush CandleColorDown
        {
            get { return candleColorDown; }
            set { candleColorDown = value; }
        }
     
        /// <summary>
        /// </summary>
        [Browsable(false)]
        public string candleColorDownSerialize
        {
            get { return Serialize.BrushToString(candleColorDown); }
            set { candleColorDown = Serialize.StringToBrush(value); }
        }

     
     
     
     
     
     
     
            [Display(Name="CCI_Period", Description = "CCI_Period", GroupName = "Parameters")]
     
     
        public int CCI_Period
        {
            get
            {
                return this.CCI_period;
            }
            set
            {
                this.CCI_period = Math.Max(1, value);
            }
        }

        //basura del 7
        //[Category("Parameters"), NinjaTrader.Gui.Design.DisplayName("TGT_Value"), Description("TGT_Value")]
     
        [Display(Name="TGT_Value", Description = "TGT_Value", GroupName = "Parameters")]
        public int TGT_Value
        {
            get
            {
                return this.TGT_value;
            }
            set
            {
                this.TGT_value = Math.Max(1, value);
            }
        }
     
        [Description("Determines whether arrows are shown")]
        [Category("Parameters")]
        public bool ShowArrows
        {
            get { return showarrows; }
            set { showarrows = value; }
        }
             
        [Description("Determines whether alerts are shown")]
        [Category("Parameters")]
        public bool ShowAlerts
        {
            get { return showalerts; }
            set { showalerts = value; }
        }
       #endregion
    }
}

#region NinjaScript generated code. Neither change nor remove.

namespace NinjaTrader.NinjaScript.Indicators
{
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
        private CharlieF_XTL[] cacheCharlieF_XTL;
        public CharlieF_XTL CharlieF_XTL(Brush candleColorUp, Brush candleColorFlat, Brush candleColorDown)
        {
            return CharlieF_XTL(Input, candleColorUp, candleColorFlat, candleColorDown);
        }

        public CharlieF_XTL CharlieF_XTL(ISeries<double> input, Brush candleColorUp, Brush candleColorFlat, Brush candleColorDown)
        {
            if (cacheCharlieF_XTL != null)
                for (int idx = 0; idx < cacheCharlieF_XTL.Length; idx++)
                    if (cacheCharlieF_XTL[idx] != null && cacheCharlieF_XTL[idx].CandleColorUp == candleColorUp && cacheCharlieF_XTL[idx].CandleColorFlat == candleColorFlat && cacheCharlieF_XTL[idx].CandleColorDown == candleColorDown && cacheCharlieF_XTL[idx].EqualsInput(input))
                        return cacheCharlieF_XTL[idx];
            return CacheIndicator<CharlieF_XTL>(new CharlieF_XTL(){ CandleColorUp = candleColorUp, CandleColorFlat = candleColorFlat, CandleColorDown = candleColorDown }, input, ref cacheCharlieF_XTL);
        }
    }
}

namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
        public Indicators.CharlieF_XTL CharlieF_XTL(Brush candleColorUp, Brush candleColorFlat, Brush candleColorDown)
        {
            return indicator.CharlieF_XTL(Input, candleColorUp, candleColorFlat, candleColorDown);
        }

        public Indicators.CharlieF_XTL CharlieF_XTL(ISeries<double> input , Brush candleColorUp, Brush candleColorFlat, Brush candleColorDown)
        {
            return indicator.CharlieF_XTL(input, candleColorUp, candleColorFlat, candleColorDown);
        }
    }
}

namespace NinjaTrader.NinjaScript.Strategies
{
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
        public Indicators.CharlieF_XTL CharlieF_XTL(Brush candleColorUp, Brush candleColorFlat, Brush candleColorDown)
        {
            return indicator.CharlieF_XTL(Input, candleColorUp, candleColorFlat, candleColorDown);
        }

        public Indicators.CharlieF_XTL CharlieF_XTL(ISeries<double> input , Brush candleColorUp, Brush candleColorFlat, Brush candleColorDown)
        {
            return indicator.CharlieF_XTL(input, candleColorUp, candleColorFlat, candleColorDown);
        }
    }
}

#endregion

Price Action Swing Pro

Code:
// #############################################################
// #                                                           #
// #                    PriceActionSwingPro                    #
// #                                                           #
// #     19.12.2016 by dorschden, [email protected]     #
// #                                                           #
// #        Thanks and comments are highly appreciated         #
// #        Paypal thanks to "[email protected]"        #
// #                                                           #
// #############################################################


#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
using PriceActionSwing.Base;
#endregion

//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators.PriceActionSwing
{
    /// <summary>
    /// PriceActionSwingPro calculates swings and visualizes them in different ways
    /// and displays several information about the swings. Features:
    /// ABC pattern recognition | Fibonacci retracements/-extensions | Divergence
    /// </summary>
    public class PriceActionSwingPro : Indicator
    {
        #region Variables
        //#########################################################################################
        #region Display
        //=========================================================================================
        /// <summary>
        /// Represents the swing length visualization type for the swings.
        /// </summary>
        private SwingLengthStyle swingLengthType = SwingLengthStyle.Ticks;
        /// <summary>
        /// Represents the swing duration visualization type for the swings.
        /// </summary>
        private SwingDurationStyle swingDurationType = SwingDurationStyle.Bars;
        /// <summary>
        /// Indicates if the swing price is shown for the swings.
        /// </summary>
        private bool showSwingPrice = true;
        /// <summary>
        /// Indicates if the swing label is shown for the swings.
        /// </summary>
        private bool showSwingLabel = false;
        /// <summary>
        /// Indicates if the swing percentage in relation to the last swing is shown for the
        /// swings.
        /// </summary>
        private bool showSwingPercent = false;
        /// <summary>
        /// Represents the swing time visualization type for the swings.
        /// </summary>
        private SwingTimeStyle swingTimeType = SwingTimeStyle.False;
        /// <summary>
        /// Indicates if the swing volume is shown for the swings.
        /// </summary>
        private SwingVolumeStyle swingVolumeType = SwingVolumeStyle.Absolute;
        /// <summary>
        /// Represents the name of the indicator.
        /// </summary>
        private string displayName = null;
        //=========================================================================================
        #endregion

        #region Visualize swings
        //=========================================================================================
        /// <summary>
        /// Represents the swing visualization type for the swings.
        /// </summary>
        private VisualizationStyle visualizationType = VisualizationStyle.Dots_ZigZag;
        /// <summary>
        /// Indicates if AutoScale is used for the swings.
        /// </summary>
        private bool useAutoScale = true;
        /// <summary>
        /// Indicates if the swings are drawn on the price panel.
        /// </summary>
        private bool drawSwingsOnPricePanel = true;
        /// <summary>
        /// Represents the color of the zig-zag up lines for the swings.
        /// </summary>
        private Brush zigZagColorUp = Brushes.LimeGreen;
        /// <summary>
        /// Represents the color of the zig-zag down lines for the swings.
        /// </summary>
        private Brush zigZagColorDn = Brushes.OrangeRed;
        /// <summary>
        /// Represents the line style of the zig-zag lines for the swings.
        /// </summary>
        private DashStyleHelper zigZagStyle = DashStyleHelper.Solid;
        /// <summary>
        /// Represents the line width of the zig-zag lines for the swings.
        /// </summary>
        private int zigZagWidth = 3;
        /// <summary>
        /// Represents the color of the swing value output for higher highs for the swings.
        /// </summary>
        private Brush textColorHigherHigh = Brushes.White;
        /// <summary>
        /// Represents the color of the swing value output for lower highs for the swings.
        /// </summary>
        private Brush textColorLowerHigh = Brushes.Black;
        /// <summary>
        /// Represents the color of the swing value output for double tops for the swings.
        /// </summary>
        private Brush textColorDoubleTop = Brushes.Gold;
        /// <summary>
        /// Represents the color of the swing value output for higher lows for the swings.
        /// </summary>
        private Brush textColorHigherLow = Brushes.White;
        /// <summary>
        /// Represents the color of the swing value output for lower lows swings for the swings.
        /// </summary>
        private Brush textColorLowerLow = Brushes.Black;
        /// <summary>
        /// Represents the color of the swing value output for double bottoms for the swings.
        /// </summary>
        private Brush textColorDoubleBottom = Brushes.Gold;
        /// <summary>
        /// Represents the text font for the swing value output for the swings.
        /// </summary>
        private SimpleFont textFont = new SimpleFont("Courier", 15);
        /// <summary>
        /// Represents the text offset in pixel for the swing length for the swings.
        /// </summary>
        private int textOffsetLength = 15;
        /// <summary>
        /// Represents the text offset in pixel for the retracement value for the swings.
        /// </summary>
        private int textOffsetPercent = 90;
        /// <summary>
        /// Represents the text offset in pixel for the swing price for the swings.
        /// </summary>
        private int textOffsetPrice = 45;
        /// <summary>
        /// Represents the text offset in pixel for the swing labels for the swings.
        /// </summary>
        private int textOffsetLabel = 60;
        /// <summary>
        /// Represents the text offset in pixel for the swing time for the swings.
        /// </summary>
        private int textOffsetTime = 75;
        /// <summary>
        /// Represents the text offset in pixel for the swing volume for the swings.
        /// </summary>
        private int textOffsetVolume = 30;

        /// <summary>
        /// Indicates if the Gann swings are updated if the last swing high/low is broken.
        /// </summary>
        private bool useBreakouts = true;
        /// <summary>
        /// Indicates if inside bars are ignored for the Gann swing calculation. If set to
        /// true it is possible that between consecutive up/down bars are inside bars.
        /// </summary>
        private bool ignoreInsideBars = true;
        /// <summary>
        /// Represents the number of decimal places for the instrument
        /// </summary>
        private int decimalPlaces;
        /// <summary>
        /// Indicates if the change from down to up or up to down swings is indicated on the chart
        /// for the swings.
        /// </summary>
        private bool showSwingSwitch = false;
        /// <summary>
        /// Represents the number of ticks the swing switch triangle is placed above/below the bar.
        /// </summary>
        private int swingSwitchOffsetInTicks = 10;
        private Brush swingSwitchDownColor = Brushes.Red;
        private Brush swingSwitchUpColor = Brushes.Blue;
        //=========================================================================================
        #endregion

        #region Features
        //=========================================================================================
        /// <summary>
        /// Indicates if and for which direction AB=CD patterns are computed.
        /// </summary>
        private AbcPatternMode abcPattern = AbcPatternMode.Long_Short;
        /// <summary>
        /// Indicates the target in percent of the AB range for the AB=CD pattern for the risk
        /// management.
        /// </summary>
        private double abcTarget = 100.0;
        private DivergenceMode divergenceMode = DivergenceMode.False;
        private DivergenceDirection divergenceDirection = DivergenceDirection.Long_Short;
        private int param1 = 10;
        private int param2 = 26;
        private int param3 = 9;
        /// <summary>
        /// Indicates if and where a swing statistic is shown.
        /// </summary>
        private StatisticPositionStyle statisticPosition = StatisticPositionStyle.False;
        /// <summary>
        /// Indicates the number of swings which are used for the current swing statistic.
        /// </summary>
        private int statisticLength = 5;
        /// <summary>
        /// Indicates if and where the risk management tools are shown.
        /// </summary>
        private RiskManagementStyle riskManagementPosition = RiskManagementStyle.Tab;
        /// <summary>
        /// Represents the stop loss in ticks for long entries to calculate the risk parameters.
        /// </summary>
        private int riskLongStopInTicks = 50;
        /// <summary>
        /// Represents the take profit in ticks for long entries to calculate the risk parameters.
        /// </summary>
        private int riskLongTargetInTicks = 100;
        /// <summary>
        /// Represents the stop loss in ticks for short entries to calculate the risk parameters.
        /// </summary>
        private int riskShortStopInTicks = 50;
        /// <summary>
        /// Represents the take profit in ticks for short entries to calculate the risk parameters.
        /// </summary>
        private int riskShortTargetInTicks = 100;
        /// <summary>
        /// Represents the account size from which the quantity for a trade is calculated based
        /// on the account risk.
        /// </summary>
        private double accountSize = 100000.00;
        /// <summary>
        /// Represents the percentage of the account size which is risked for each trade.
        /// </summary>
        private double accountRisk = 0.5;
        /// <summary>
        /// Indicates if a swing extension is drawn on the chart.
        /// </summary>
        private bool addSwingExtension = false;
        /// <summary>
        /// Indicates if a swing retracement is drawn on the chart for the current swing.
        /// </summary>
        private bool addSwingRetracementFast = false;
        /// <summary>
        /// Indicates if a swing retracement is drawn on the chart for the last swing.
        /// </summary>
        private bool addSwingRetracementSlow = false;
        //=========================================================================================
        #endregion

        #region Naked swings
        //=========================================================================================
        private SortedList<double, int> nakedSwingHighsList = new SortedList<double, int>();
        private SortedList<double, int> nakedSwingLowsList = new SortedList<double, int>();
        private bool showNakedSwings = false;
        private bool showHistoricalNakedSwings = false;
        private int nakedSwingCounter = 0;
        private Brush nakedSwingHighColor = Brushes.Red;
        private Brush nakedSwingLowColor = Brushes.Blue;
        private DashStyleHelper nakedSwingDashStyle = DashStyleHelper.Solid;
        private int nakedSwingLineWidth = 1;
        //=========================================================================================
        #endregion

        #region ABC pattern
        //=========================================================================================
        private bool abcLabel = true;
        private DashStyleHelper abcLineStyle = DashStyleHelper.Solid;
        private DashStyleHelper abcLineStyleRatio = DashStyleHelper.Dash;
        private int abcLineWidth = 4;
        private int abcLineWidthRatio = 2;
        private SimpleFont abcTextFont = new SimpleFont("Courier", 14);
        private int abcTextOffsetLabel = 50;
        private Brush abcTextColorDn = Brushes.Red;
        private Brush abcTextColorUp = Brushes.Green;
        private Brush abcZigZagColorDn = Brushes.Red;
        private Brush abcZigZagColorUp = Brushes.Green;
        private double abcMaxRetracement = 92.0;
        private double abcMinRetracement = 61.0;
        private DashStyleHelper entryLineStyle = DashStyleHelper.Solid;
        private int entryLineWidth = 4;
        private Brush entryLineColorDn = Brushes.Red;
        private Brush entryLineColorUp = Brushes.Green;
        private bool showEntryArrows = true;
        private bool showEntryLine = true;
        private bool showHistoricalEntryLine = true;
        private int yTickOffset = 5;
        //=========================================================================================
        private Series<double> abcSignals;
        private Series<double> entryLong;
        private Series<double> entryShort;
        private Series<double> entryLevelLine;
        //=========================================================================================
        private int abcEntryTag = 0;
        private bool abcLongChanceInProgress = false;
        private bool abcShortChanceInProgress = false;
        private double retracementEntryValue = 38.0;
        private double entryLevel = 0.0;
        private int entryLineStartBar = 0;
        private int aBar = 0;
        private int bBar = 0;
        private int cBar = 0;
        private int entryBar = 0;
        private int patternCounter = 0;
        private int tmpCounter = 0;
        private int drawTag = 0;
        //=========================================================================================
        #endregion

        #region Alerts
        //=========================================================================================
        private int alertTag = 0;
        private bool alertAbc = true;
        private bool alertAbcEntry = true;
        private Priority alertAbcPriority = Priority.Medium;
        private Priority alertAbcEntryPriority = Priority.High;
        private string alertAbcLongSoundFileName = "AbcLong.wav";
        private string alertAbcLongEntrySoundFileName = "AbcLongEntry.wav";
        private string alertAbcShortSoundFileName = "AbcShort.wav";
        private string alertAbcShortEntrySoundFileName = "AbcShortEntry.wav";
        //=========================================================================================
        private bool alertDoubleBottom = false;
        private Priority alertDoubleBottomPriority =
            Priority.Medium;
        private string alertDoubleBottomMessage = "Double Bottom";
        private string alertDoubleBottomSoundFileName = "DoubleBottom.wav";
        private int alertDoubleBottomRearmSeconds = 0;
        private Brush alertDoubleBottomBackColor = Brushes.Blue;
        private Brush alertDoubleBottomForeColor = Brushes.White;
        //=========================================================================================
        private bool alertDoubleTop = false;
        private Priority alertDoubleTopPriority =
            Priority.Medium;
        private string alertDoubleTopMessage = "Double Top";
        private string alertDoubleTopSoundFileName = "DoubleTop.wav";
        private int alertDoubleTopRearmSeconds = 0;
        private Brush alertDoubleTopBackColor = Brushes.Red;
        private Brush alertDoubleTopForeColor = Brushes.White;
        //=========================================================================================
        private bool alertHigherLow = false;
        private Priority alertHigherLowPriority =
            Priority.Medium;
        private string alertHigherLowMessage = "Higher Low";
        private string alertHigherLowSoundFileName = "HigherLow.wav";
        private int alertHigherLowRearmSeconds = 0;
        private Brush alertHigherLowBackColor = Brushes.Black;
        private Brush alertHigherLowForeColor = Brushes.White;
        //=========================================================================================
        private bool alertLowerHigh = false;
        private Priority alertLowerHighPriority =
            Priority.Medium;
        private string alertLowerHighMessage = "Lower High";
        private string alertLowerHighSoundFileName = "LowerHigh.wav";
        private int alertLowerHighRearmSeconds = 0;
        private Brush alertLowerHighBackColor = Brushes.Black;
        private Brush alertLowerHighForeColor = Brushes.White;
        //=========================================================================================
        private bool alertSwingChange = false;
        private Priority alertSwingChangePriority =
            Priority.Low;
        private string alertSwingChangeMessage = "Swing change";
        private string alertSwingChangeSoundFileName = "SwingChange.wav";
        private int alertSwingChangeRearmSeconds = 0;
        private Brush alertSwingChangeBackColor = Brushes.Black;
        private Brush alertSwingChangeForeColor = Brushes.White;
        //=========================================================================================
        private bool alertDivergenceRegularHigh = true;
        private Priority alertDivergenceRegularHighPriority =
            Priority.Medium;
        private string alertDivergenceRegularHighMessage = "High regular divergence";
        private string alertDivergenceRegularHighSoundFileName = "DivergenceRegularHigh.wav";
        private int alertDivergenceRegularHighRearmSeconds = 0;
        private Brush alertDivergenceRegularHighBackColor = Brushes.Red;
        private Brush alertDivergenceRegularHighForeColor = Brushes.White;
        //=========================================================================================
        private bool alertDivergenceHiddenHigh = true;
        private Priority alertDivergenceHiddenHighPriority =
            Priority.Medium;
        private string alertDivergenceHiddenHighMessage = "High hidden divergence";
        private string alertDivergenceHiddenHighSoundFileName = "DivergenceHiddenHigh.wav";
        private int alertDivergenceHiddenHighRearmSeconds = 0;
        private Brush alertDivergenceHiddenHighBackColor = Brushes.Red;
        private Brush alertDivergenceHiddenHighForeColor = Brushes.White;
        //=========================================================================================
        private bool alertDivergenceRegularLow = true;
        private Priority alertDivergenceRegularLowPriority =
            Priority.Medium;
        private string alertDivergenceRegularLowMessage = "Low regular divergence";
        private string alertDivergenceRegularLowSoundFileName = "DivergenceRegularLow.wav";
        private int alertDivergenceRegularLowRearmSeconds = 0;
        private Brush alertDivergenceRegularLowBackColor = Brushes.Blue;
        private Brush alertDivergenceRegularLowForeColor = Brushes.White;
        //=========================================================================================
        private bool alertDivergenceHiddenLow = true;
        private Priority alertDivergenceHiddenLowPriority =
            Priority.Medium;
        private string alertDivergenceHiddenLowMessage = "Low hidden divergence";
        private string alertDivergenceHiddenLowSoundFileName = "DivergenceHiddenLow.wav";
        private int alertDivergenceHiddenLowRearmSeconds = 0;
        private Brush alertDivergenceHiddenLowBackColor = Brushes.Blue;
        private Brush alertDivergenceHiddenLowForeColor = Brushes.White;
        //=========================================================================================
        #endregion

        #region Divergence
        //=========================================================================================
        private bool showDivergenceRegular = true;
        private bool showDivergenceHidden = true;
        private Series<double> divergenceDataHigh;
        private Series<double> divergenceDataLow;

        private double divLastSwing = 0.0;
        private double divLastOscValue = 0.0;
        private double divCurSwing = 0.0;
        private double divCurOscValue = 0.0;

        private int drawTagDivUp = 0;
        private int drawTagDivDn = 0;
        private DashStyleHelper divDnLineStyle = DashStyleHelper.Dot;
        private int divDnLineWidth = 2;
        private Brush divDnLineColor = Brushes.Red;
        private DashStyleHelper divUpLineStyle = DashStyleHelper.Dot;
        private int divUpLineWidth = 2;
        private Brush divUpLineColor = Brushes.Green;

        private Stochastics stochastics;
        private MACD macd;
        private Series<double> divSignal;
        private bool divHiddenShortActive = false;
        private bool divRegularShortActive = false;
        private bool divHiddenLongActive = false;
        private bool divRegularLongActive = false;
        //=========================================================================================
        #endregion

        #region Forms
        // Statistic forms ========================================================================
        private System.Windows.Forms.Panel panel = null;
        private System.Windows.Forms.Label label = null;
        private System.Windows.Forms.TabControl mainTabControl = null;
        private System.Windows.Forms.TabPage tabABC = null;
        private System.Windows.Forms.TabPage tabSwingLength = null;
        private System.Windows.Forms.TabPage tabSwingRelation = null;
        private System.Windows.Forms.DataGridView lengthList = null;
        private System.Windows.Forms.DataGridViewTextBoxColumn colLengthDirection = null;
        private System.Windows.Forms.DataGridViewTextBoxColumn colLengthSwingCount = null;
        private System.Windows.Forms.DataGridViewTextBoxColumn colLengthLength = null;
        private System.Windows.Forms.DataGridViewTextBoxColumn colLengthLastLength = null;
        private System.Windows.Forms.DataGridViewTextBoxColumn colLengthDuration = null;
        private System.Windows.Forms.DataGridViewTextBoxColumn colLengthLastDuration = null;
        private System.Windows.Forms.DataGridView relationList = null;
        private System.Windows.Forms.DataGridViewTextBoxColumn colRelationSwing = null;
        private System.Windows.Forms.DataGridViewTextBoxColumn colRelationSwingCount = null;
        private System.Windows.Forms.DataGridViewTextBoxColumn colRelationHigherHigh = null;
        private System.Windows.Forms.DataGridViewTextBoxColumn colRelationLowerHigh = null;
        private System.Windows.Forms.DataGridViewTextBoxColumn colRelationHigherLow = null;
        private System.Windows.Forms.DataGridViewTextBoxColumn colRelationLowerLow = null;
        private System.Windows.Forms.Splitter splitter = null;
        // Necessary toolstrip items forms ========================================================
        System.Windows.Forms.ToolStrip toolStrip = null;
        System.Windows.Forms.ToolStripButton toolStripButton = null;
        System.Windows.Forms.ToolStripSeparator toolStripSeparator = null;
        // Risk calculation forms toolstrip =======================================================
        System.Windows.Forms.ToolStripSeparator toolStripSeparator1 = null;
        System.Windows.Forms.ToolStripSeparator toolStripSeparator2 = null;
        System.Windows.Forms.ToolStripSeparator toolStripSeparator3 = null;
        System.Windows.Forms.ToolStripSeparator toolStripSeparator4 = null;
        System.Windows.Forms.ToolStripLabel toolStripLabelQty = null;
        System.Windows.Forms.ToolStripLabel toolStripLabelRiskReward = null;
        System.Windows.Forms.ToolStripLabel toolStripLabelLoss = null;
        System.Windows.Forms.ToolStripLabel toolStripLabelProfit = null;
        System.Windows.Forms.ToolStripLabel toolStripLabelEntry = null;
        System.Windows.Forms.ToolStripButton toolStripButtonLong = null;
        System.Windows.Forms.ToolStripButton toolStripButtonShort = null;
        System.Windows.Forms.ToolStripLabel toolStripLabelStop = null;
        System.Windows.Forms.ToolStripLabel toolStripLabelTarget = null;
        System.Windows.Forms.NumericUpDown toolStripNumericUpDownEntry;
        System.Windows.Forms.NumericUpDown toolStripNumericUpDownStop;
        System.Windows.Forms.NumericUpDown toolStripNumericUpDownTarget;
        System.Windows.Forms.ToolStripControlHost toolStripControlHostEntry = null;
        System.Windows.Forms.ToolStripControlHost toolStripControlHostStop = null;
        System.Windows.Forms.ToolStripControlHost toolStripControlHostTarget = null;
        // Risk calculation forms tab =============================================================
        private System.Windows.Forms.TabPage tabRiskManagement = null;
        private System.Windows.Forms.Label labelQuantity = null;
        private System.Windows.Forms.Label labelRiskReward = null;
        private System.Windows.Forms.Label labelLoss = null;
        private System.Windows.Forms.Label labelWin = null;
        private System.Windows.Forms.Label labelLossValue = null;
        private System.Windows.Forms.Label labelWinValue = null;
        private System.Windows.Forms.Label labelEntry = null;
        private System.Windows.Forms.Label labelStopLoss = null;
        private System.Windows.Forms.Label labelTakeProfit = null;
        private System.Windows.Forms.Button buttonEntryLong = null;
        private System.Windows.Forms.Button buttonEntryShort = null;
        private System.Windows.Forms.NumericUpDown numericUpDownEntry = null;
        private System.Windows.Forms.NumericUpDown numericUpDownStopLoss = null;
        private System.Windows.Forms.NumericUpDown numericUpDownTakeProfit = null;
        //=========================================================================================
        #endregion

        #region Statistic
        //===================================================================
        private double overallAvgDnLength = 0;
        private double overallAvgUpLength = 0;
        private double overallUpLength = 0;
        private double overallDnLength = 0;
        private double overallAvgDnDuration = 0;
        private double overallAvgUpDuration = 0;
        private double overallUpDuration = 0;
        private double overallDnDuration = 0;

        private double avgUpLength = 0;
        private double avgDnLength = 0;
        private double upLength = 0;
        private double dnLength = 0;
        private double avgUpDuration = 0;
        private double avgDnDuration = 0;
        private double upDuration = 0;
        private double dnDuration = 0;

        // Variables for the swing to swing relation statistic ================
        private int hhCount = 0;
        private int hhCountHH = 0;
        private double hhCountHHPercent = 0;
        private int hhCountLH = 0;
        private double hhCountLHPercent = 0;
        private int hhCountHL = 0;
        private double hhCountHLPercent = 0;
        private int hhCountLL = 0;
        private double hhCountLLPercent = 0;

        private int lhCount = 0;
        private int lhCountHH = 0;
        private double lhCountHHPercent = 0;
        private int lhCountLH = 0;
        private double lhCountLHPercent = 0;
        private int lhCountHL = 0;
        private double lhCountHLPercent = 0;
        private int lhCountLL = 0;
        private double lhCountLLPercent = 0;

        private int dtCount = 0;
        private int dtCountHH = 0;
        private double dtCountHHPercent = 0;
        private int dtCountLH = 0;
        private double dtCountLHPercent = 0;
        private int dtCountHL = 0;
        private double dtCountHLPercent = 0;
        private int dtCountLL = 0;
        private double dtCountLLPercent = 0;

        private int llCount = 0;
        private int llCountHH = 0;
        private double llCountHHPercent = 0;
        private int llCountLH = 0;
        private double llCountLHPercent = 0;
        private int llCountHL = 0;
        private double llCountHLPercent = 0;
        private int llCountLL = 0;
        private double llCountLLPercent = 0;

        private int hlCount = 0;
        private int hlCountHH = 0;
        private double hlCountHHPercent = 0;
        private int hlCountLH = 0;
        private double hlCountLHPercent = 0;
        private int hlCountHL = 0;
        private double hlCountHLPercent = 0;
        private int hlCountLL = 0;
        private double hlCountLLPercent = 0;

        private int dbCount = 0;
        private int dbCountHH = 0;
        private double dbCountHHPercent = 0;
        private int dbCountLH = 0;
        private double dbCountLHPercent = 0;
        private int dbCountHL = 0;
        private double dbCountHLPercent = 0;
        private int dbCountLL = 0;
        private double dbCountLLPercent = 0;
        //===================================================================
        #endregion

        #region Class objects and DataSeries
        //=========================================================================================
        /// <summary>
        /// Represents the properties for the swing.
        /// </summary>
        private SwingProperties swingProperties;
        /// <summary>
        /// Represents the values for the current swing.
        /// </summary>
        private SwingCurrent swingCurrent = new SwingCurrent();
        /// <summary>
        /// Represents the swing high values.
        /// </summary>
        private Swings swingHigh = new Swings();
        /// <summary>
        /// Represents the swing low values.
        /// </summary>
        private Swings swingLow = new Swings();
        /// <summary>
        /// Indicates if the swing direction changed form down to up swing for the swings.
        /// </summary>
        private Series<bool> upFlip;
        /// <summary>
        /// Indicates if the swing direction changed form up to down swing for the swings.
        /// </summary>
        private Series<bool> dnFlip;
        /// <summary>
        /// Represents a list of all up swings for the swings.
        /// </summary>
        private List<SwingStruct> swingHighs = new List<SwingStruct>();
        /// <summary>
        /// Represents a list of all down swings for the swings.
        /// </summary>
        private List<SwingStruct> swingLows = new List<SwingStruct>();
        //=========================================================================================
        #endregion
        //#########################################################################################
        #endregion
     
        #region OnStateChange()
        //=========================================================================================
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description                            = @"PriceActionSwingPro calculates swings and visualize them in different ways and display several information about them.";
                Name                                = "PriceActionSwingPro";
                Calculate                            = Calculate.OnEachTick;
                IsOverlay                            = true;
                DisplayInDataBox                    = true;
                DrawOnPricePanel                    = true;
                DrawHorizontalGridLines                = true;
                DrawVerticalGridLines                = true;
                PaintPriceMarkers                    = true;
                ScaleJustification                    = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                //See Help Guide for additional information.
                IsSuspendedWhileInactive            = true;
             
                #region Parameters
                //=========================================================================================
                DtbStrength = 20;
                SwingSize = 7;
                SwingType = SwingStyle.Standard;
                UseCloseValues = false;
                //=========================================================================================
                #endregion
             
                AddPlot(new Stroke(Brushes.Gold, DashStyleHelper.Solid, 3), PlotStyle.Dot, "DoubleBottom");
                AddPlot(new Stroke(Brushes.Red, DashStyleHelper.Solid, 3), PlotStyle.Dot, "LowerLow");
                AddPlot(new Stroke(Brushes.Green, DashStyleHelper.Solid, 3), PlotStyle.Dot, "HigherLow");

                AddPlot(new Stroke(Brushes.Gold, DashStyleHelper.Solid, 3), PlotStyle.Dot, "DoubleTop");
                AddPlot(new Stroke(Brushes.Red, DashStyleHelper.Solid, 3), PlotStyle.Dot, "LowerHigh");
                AddPlot(new Stroke(Brushes.Green, DashStyleHelper.Solid, 3), PlotStyle.Dot, "HigherHigh");
             
                AddPlot(new Stroke(Brushes.Blue, DashStyleHelper.Solid, 1), PlotStyle.Square, "GannSwing");
            }
            else if (State == State.DataLoaded)
            {
                // Calculate decimal places
                decimal increment = Convert.ToDecimal(Instrument.MasterInstrument.TickSize);
                int incrementLength = increment.ToString().Length;
                decimalPlaces = 0;
                if (incrementLength == 1)
                    decimalPlaces = 0;
                else if (incrementLength > 2)
                    decimalPlaces = incrementLength - 2;
             
                if (SwingType != SwingStyle.Percent)
                {
                    SwingSize = SwingSize < 1 ? 1 : Math.Round(SwingSize, MidpointRounding.AwayFromZero);
                }
             
                displayName = Name +  "(" + Instrument.FullName + " (" + BarsPeriod.Value + " " + BarsPeriod.BarsPeriodType + "), " + SwingType + ", " + SwingSize + ", " + DtbStrength + ")";

                swingProperties = new SwingProperties(SwingType, SwingSize, DtbStrength,
                    swingLengthType, swingDurationType, showSwingPrice, showSwingLabel,
                    showSwingPercent, swingTimeType, swingVolumeType, visualizationType,
                    useBreakouts, ignoreInsideBars, useAutoScale,
                    zigZagColorUp, zigZagColorDn, zigZagStyle, zigZagWidth, textColorHigherHigh,
                    textColorLowerHigh, textColorDoubleTop, textColorHigherLow,
                    textColorLowerLow, textColorDoubleBottom, textFont, textOffsetLength,
                    textOffsetPercent, textOffsetPrice, textOffsetLabel, textOffsetTime,
                    textOffsetVolume, UseCloseValues, drawSwingsOnPricePanel);
            }
            else if (State == State.Configure)
            {
                dnFlip = new Series<bool>(this);
                upFlip = new Series<bool>(this);
             
                abcSignals = new Series<double>(this);
                entryLong = new Series<double>(this);
                entryShort = new Series<double>(this);
                entryLevelLine = new Series<double>(this);
                divergenceDataHigh = new Series<double>(this);
                divergenceDataLow = new Series<double>(this);
                divSignal = new Series<double>(this);
             
                #region Divergence
                //=====================================================================================
                if (divergenceMode != DivergenceMode.False)
                {
                    switch (divergenceMode)
                    {
                        case DivergenceMode.Custom:
                            // Add custom divergence indicator here
                            break;
                        case DivergenceMode.MACD:
                            macd = MACD(param1, param2, param3);
                            break;
                        case DivergenceMode.Stochastics:
                            stochastics = Stochastics(param1, param2, param3);
                            break;
                    }
                }
                //=====================================================================================
                #endregion
            }
        }
        //=========================================================================================
        #endregion

        protected override void OnBarUpdate()
        {
            #region Initialize varibles
            //=====================================================================================
            if (IsFirstTickOfBar)
            {
                entryLevelLine[0] = 0;
                abcSignals[0] = 0;

                if (divHiddenShortActive == true)
                    divSignal[0] = 2;
                else if (divRegularShortActive == true)
                    divSignal[0] = 1;
                else if (divHiddenLongActive == true)
                    divSignal[0] = 2;
                else if (divRegularLongActive == true)
                    divSignal[0] = 1;
                else
                    divSignal[0] = 0;

                if (swingLow.CurPrice == 0.0 || swingHigh.CurPrice == 0.0)
                {
                    entryLong[0] = 0;
                    entryShort[0] = 0;
                }
                else
                {
                    entryLong[0] = entryLong[1];
                    entryShort[0] = entryShort[1];
                }

                if (CurrentBar == 1)
                {
                    #region Divergence
                    switch (divergenceMode)
                    {
                        case DivergenceMode.Custom:
                            // Add custom divergence indicator here
                            break;
                        case DivergenceMode.MACD:
                            divergenceDataHigh = macd.Diff;
                            divergenceDataLow = macd.Diff;
                            break;
                        case DivergenceMode.Stochastics:
                            divergenceDataHigh = stochastics.K;
                            divergenceDataLow = stochastics.K;
                            break;
                    }
                    #endregion
                }
            }
            // Checks to ensure there are enough bars before beginning
            if (CurrentBars[BarsInProgress] <= 1
                || CurrentBars[BarsInProgress] < SwingSize
                || (divergenceMode != DivergenceMode.False &&
                    (CurrentBars[BarsInProgress] <= param1
                    || CurrentBars[BarsInProgress] <= param2
                    || CurrentBars[BarsInProgress] <= param3)))
                return;
            //=====================================================================================
            #endregion

            #region Swing calculation
            //=====================================================================================
            InitializeSwingCalculation(swingHigh, swingLow, swingCurrent, upFlip, swingHighs,
                dnFlip, swingLows);

            switch (SwingType)
            {
                case SwingStyle.Standard:
                    CalculateSwingStandard(swingHigh, swingLow, swingCurrent, swingProperties,
                        upFlip, swingHighs, dnFlip, swingLows, decimalPlaces, UseCloseValues,
                        DoubleBottom, LowerLow, HigherLow, DoubleTop, LowerHigh, HigherHigh,
                        GannSwing);
                    break;
                case SwingStyle.Gann:
                    CalculateSwingGann(swingHigh, swingLow, swingCurrent, swingProperties, upFlip,
                        swingHighs, dnFlip, swingLows, decimalPlaces, DoubleBottom, LowerLow,
                        HigherLow, DoubleTop, LowerHigh, HigherHigh, GannSwing);
                    break;
                case SwingStyle.Ticks:
                    CalculateSwingTicks(swingHigh, swingLow, swingCurrent, swingProperties,
                        upFlip, swingHighs, dnFlip, swingLows, decimalPlaces, UseCloseValues,
                        DoubleBottom, LowerLow, HigherLow, DoubleTop, LowerHigh, HigherHigh,
                        GannSwing);
                    break;
                case SwingStyle.Percent:
                    CalculateSwingPercent(swingHigh, swingLow, swingCurrent, swingProperties,
                        upFlip, swingHighs, dnFlip, swingLows, decimalPlaces, UseCloseValues,
                        DoubleBottom, LowerLow, HigherLow, DoubleTop, LowerHigh, HigherHigh,
                        GannSwing);
                    break;
            }
            //=====================================================================================
            #endregion

            #region Fibonacci tools
            //=====================================================================================
            if (swingHigh.New || swingLow.New || swingHigh.Update || swingLow.Update)
            {
                #region Fibonacci extensions
                //---------------------------------------------------------------------------------
                if (addSwingExtension)
                {
                    if (swingHigh.LastPrice == 0.0 || swingLow.LastPrice == 0.0)
                        return;

                    if (swingLows[swingLows.Count - 1].relation == 1
                        && swingCurrent.SwingSlope == -1)
                    {
                        int anchor1BarsAgo = CurrentBar - swingLow.LastBar;
                        int anchor2BarsAgo = CurrentBar - swingHigh.CurBar;
                        int anchor3BarsAgo = CurrentBar - swingLow.CurBar;
                        double anchor1Y = swingLow.LastPrice;
                        double anchor2Y = swingHigh.CurPrice;
                        double anchor3Y = swingLow.CurPrice;
                        Draw.FibonacciExtensions(this, "FibExtUp", false, anchor1BarsAgo, anchor1Y,
                            anchor2BarsAgo, anchor2Y, anchor3BarsAgo, anchor3Y);
                    }
                    else if (swingLows[swingLows.Count - 1].relation == 1
                        && swingCurrent.SwingSlope == 1)
                    {
                        int anchor1BarsAgo = CurrentBar - swingLow.LastBar;
                        int anchor2BarsAgo = CurrentBar - swingHigh.LastBar;
                        int anchor3BarsAgo = CurrentBar - swingLow.CurBar;
                        double anchor1Y = swingLow.LastPrice;
                        double anchor2Y = swingHigh.LastPrice;
                        double anchor3Y = swingLow.CurPrice;
                        Draw.FibonacciExtensions(this,"FibExtUp", false, anchor1BarsAgo, anchor1Y,
                            anchor2BarsAgo, anchor2Y, anchor3BarsAgo, anchor3Y);
                    }
                    else
                        RemoveDrawObject("FibExtUp");

                    if (swingHighs[swingHighs.Count - 1].relation == -1
                        && swingCurrent.SwingSlope == 1)
                    {
                        int anchor1BarsAgo = CurrentBar - swingHigh.LastBar;
                        int anchor2BarsAgo = CurrentBar - swingLow.CurBar;
                        int anchor3BarsAgo = CurrentBar - swingHigh.CurBar;
                        double anchor1Y = swingHigh.LastPrice;
                        double anchor2Y = swingLow.CurPrice;
                        double anchor3Y = swingHigh.CurPrice;
                        Draw.FibonacciExtensions(this,"FibExtDn", false, anchor1BarsAgo, anchor1Y,
                            anchor2BarsAgo, anchor2Y, anchor3BarsAgo, anchor3Y);
                    }
                    else if (swingHighs[swingHighs.Count - 1].relation == -1
                        && swingCurrent.SwingSlope == -1)
                    {
                        int anchor1BarsAgo = CurrentBar - swingHigh.LastBar;
                        int anchor2BarsAgo = CurrentBar - swingLow.LastBar;
                        int anchor3BarsAgo = CurrentBar - swingHigh.CurBar;
                        double anchor1Y = swingHigh.LastPrice;
                        double anchor2Y = swingLow.LastPrice;
                        double anchor3Y = swingHigh.CurPrice;
                        Draw.FibonacciExtensions(this,"FibExtDn", false, anchor1BarsAgo, anchor1Y,
                            anchor2BarsAgo, anchor2Y, anchor3BarsAgo, anchor3Y);
                    }
                    else
                        RemoveDrawObject("FibExtDn");
                }
                //---------------------------------------------------------------------------------
                #endregion

                #region Fibonacci retracements
                //---------------------------------------------------------------------------------
                if (addSwingRetracementFast)
                {
                    int anchor1BarsAgo = 0;
                    int anchor2BarsAgo = 0;
                    double anchor1Y = 0.0;
                    double anchor2Y = 0.0;

                    if (swingCurrent.SwingSlope == 1)
                    {
                        anchor1BarsAgo = CurrentBar - swingLow.CurBar;
                        anchor1Y = swingLow.CurPrice;
                        anchor2BarsAgo = CurrentBar - swingHigh.CurBar;
                        anchor2Y = swingHigh.CurPrice;
                    }
                    else
                    {
                        anchor1BarsAgo = CurrentBar - swingHigh.CurBar;
                        anchor1Y = swingHigh.CurPrice;
                        anchor2BarsAgo = CurrentBar - swingLow.CurBar;
                        anchor2Y = swingLow.CurPrice;
                    }
                    Draw.FibonacciRetracements(this, "FastFibRet", IsAutoScale,
                        anchor1BarsAgo, anchor1Y, anchor2BarsAgo, anchor2Y);
                }

                if (addSwingRetracementSlow)
                {
                    if (swingHigh.LastPrice == 0.0 || swingLow.LastPrice == 0.0) return;

                    int anchor1BarsAgo = 0;
                    int anchor2BarsAgo = 0;
                    double anchor1Y = 0.0;
                    double anchor2Y = 0.0;

                    if (swingCurrent.SwingSlope == 1)
                    {
                        anchor1BarsAgo = CurrentBar - swingHigh.LastBar;
                        anchor1Y = swingHigh.LastPrice;
                        anchor2BarsAgo = CurrentBar - swingLow.CurBar;
                        anchor2Y = swingLow.CurPrice;
                    }
                    else
                    {
                        anchor1BarsAgo = CurrentBar - swingLow.LastBar;
                        anchor1Y = swingLow.LastPrice;
                        anchor2BarsAgo = CurrentBar - swingHigh.CurBar;
                        anchor2Y = swingHigh.CurPrice;
                    }

                    if ((swingCurrent.SwingSlope == 1 && swingHigh.CurPrice < swingHigh.LastPrice)
                        || (swingCurrent.SwingSlope == -1
                        && swingLow.CurPrice > swingLow.LastPrice))
                        Draw.FibonacciRetracements(this, "SlowFibRet", IsAutoScale,
                            anchor1BarsAgo, anchor1Y, anchor2BarsAgo, anchor2Y);
                    else
                        RemoveDrawObject("SlowFibRet");
                }
                //---------------------------------------------------------------------------------
                #endregion
            }
            //=====================================================================================
            #endregion

            #region Swing statistic
            //=====================================================================================
            if (statisticPosition != StatisticPositionStyle.False)
            {
                if (swingLow.New == true && swingLow.Update == false)
                    UpStatistic();
                if (swingHigh.New == true && swingHigh.Update == false)
                    DownStatistic();
            }
            //=====================================================================================
            #endregion

            #region ABC pattern
            //=====================================================================================
            #region ABC long pattern
            //-------------------------------------------------------------------------------------
            if (abcPattern == AbcPatternMode.Long_Short || abcPattern == AbcPatternMode.Long)
            {
                if ((swingLow.Update || swingLow.New) && !abcLongChanceInProgress
                        && swingLow.LastRelation == -1 && swingLow.CurRelation == 1
                        && swingLow.CurPercent > abcMinRetracement && swingLow.CurPercent < abcMaxRetracement)
                {
                    drawTag = swingHigh.Counter;
                    abcLongChanceInProgress = true;
                    entryLineStartBar = CurrentBar;
                    patternCounter++;
                    tmpCounter = swingLow.Counter;
                    abcSignals[0] = 1;
                    aBar = CurrentBar - swingLow.LastBar;
                    bBar = CurrentBar - swingHigh.CurBar;
                    cBar = CurrentBar - swingLow.CurBar;

                    Draw.Line(this, "ABLineUp" + drawTag, IsAutoScale, aBar, swingLow.LastPrice,
                        bBar, swingHigh.CurPrice, abcZigZagColorUp, abcLineStyle, abcLineWidth);
                    Draw.Line(this, "BCLineUp" + drawTag, IsAutoScale, bBar, swingHigh.CurPrice,
                        cBar, swingLow.CurPrice, abcZigZagColorUp, abcLineStyle, abcLineWidth);
                    Draw.Line(this, "ACLineUp" + drawTag, IsAutoScale, aBar, swingLow.LastPrice,
                        cBar, swingLow.CurPrice, abcZigZagColorUp, abcLineStyleRatio, abcLineWidthRatio);
                    if (abcLabel)
                    {
                        Draw.Text(this, "AUp" + drawTag, IsAutoScale, "A", aBar, swingLow.LastPrice,
                            -abcTextOffsetLabel, abcTextColorUp, abcTextFont,
                            TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
                        Draw.Text(this, "BUp" + drawTag, IsAutoScale, "B", bBar, swingHigh.CurPrice,
                            abcTextOffsetLabel, abcTextColorUp, abcTextFont,
                            TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
                        Draw.Text(this, "CUp" + drawTag, IsAutoScale, "C", cBar, swingLow.CurPrice,
                            -abcTextOffsetLabel, abcTextColorUp, abcTextFont,
                            TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
                    }

                    entryLevel = swingLow.CurPrice + Instrument.MasterInstrument.RoundToTickSize((Math.Abs(swingLow.CurLength) * TickSize)
                        / 100 * retracementEntryValue);
                    entryLevelLine[0] = entryLevel;
                    if (showEntryLine)
                        Draw.Line(this, "EntryLine" + CurrentBar.ToString(), IsAutoScale, 1, entryLevelLine[0], 0, entryLevelLine[0],
                            entryLineColorUp, entryLineStyle, entryLineWidth);
                    if (alertAbc)
                        Alert("Alert_Abc_Long" + alertTag++.ToString(), alertAbcPriority, "ABC Long" + " ("
                            + Instrument.FullName + " " + BarsPeriod + ")", alertAbcLongSoundFileName, 0, Brushes.White, Brushes.Blue);
                    entryLong[0] = entryLevel;
                    if (riskManagementPosition != RiskManagementStyle.False)
                    {
                        double entryRM = entryLong[0];
                        double stopRM = swingLow.CurPrice - 1 * TickSize;
                        double target100RM = 0.0;
                        if (swingCurrent.SwingSlope == 1)
                            target100RM = swingLow.CurPrice + swingHigh.LastLength * TickSize * abcTarget / 100;
                        else
                            target100RM = swingLow.CurPrice + swingHigh.CurLength * TickSize * abcTarget / 100;
                        CalculateLongRisk(entryRM, stopRM, target100RM);
                    }
                }

                if (abcLongChanceInProgress)
                {
                    if (swingLow.CurPercent > abcMaxRetracement && tmpCounter == swingLow.Counter)
                    {
                        abcLongChanceInProgress = false;
                        RemoveDrawObject("ABLineUp" + drawTag.ToString());
                        RemoveDrawObject("BCLineUp" + drawTag.ToString());
                        RemoveDrawObject("ACLineUp" + drawTag.ToString());
                        RemoveDrawObject("AUp" + drawTag.ToString());
                        RemoveDrawObject("BUp" + drawTag.ToString());
                        RemoveDrawObject("CUp" + drawTag.ToString());
                        // Remove entryLevelLine (maybe remove more objects as drawn (COBC))
                        if (!showHistoricalEntryLine)
                        {
                            for (int index = 0; index < CurrentBar - entryLineStartBar + 1; index++)
                            {
                                RemoveDrawObject("EntryLine" + (CurrentBar - index).ToString());
                            }
                            entryLineStartBar = 0;
                        }
                    }
                    else if (dnFlip[0] && tmpCounter != swingLow.Counter)
                    {
                        abcLongChanceInProgress = false;
                        entryLineStartBar = 0;
                    }
                    else
                    {
                        if (swingLow.Update && tmpCounter == swingLow.Counter)
                        {
                            aBar = CurrentBar - swingLow.LastBar;
                            bBar = CurrentBar - swingHigh.CurBar;
                            cBar = CurrentBar - swingLow.CurBar;

                            Draw.Line(this, "BCLineUp" + drawTag, IsAutoScale, bBar, swingHigh.CurPrice,
                                cBar, swingLow.CurPrice, abcZigZagColorUp, abcLineStyle, abcLineWidth);
                            Draw.Line(this, "ACLineUp" + drawTag, IsAutoScale, aBar, swingLow.LastPrice,
                                cBar, swingLow.CurPrice, abcZigZagColorUp, abcLineStyleRatio, abcLineWidthRatio);
                            if (abcLabel)
                            {
                                Draw.Text(this, "CUp" + drawTag, IsAutoScale, "C", cBar, swingLow.CurPrice,
                                    -abcTextOffsetLabel, abcTextColorUp, abcTextFont,
                                    TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
                            }

                            entryLevel = swingLow.CurPrice + Instrument.MasterInstrument.RoundToTickSize((Math.Abs(swingLow.CurLength) * TickSize)
                                / 100 * retracementEntryValue);
                            entryLevelLine[0] = entryLevel;

                            if (showEntryLine)
                            {
                                if (entryLevelLine[1] == 0)
                                    Draw.Line(this, "EntryLine" + CurrentBar.ToString(), IsAutoScale, 1, entryLevelLine[0], 0, entryLevelLine[0],
                                        entryLineColorUp, entryLineStyle, entryLineWidth);
                                else
                                    Draw.Line(this, "EntryLine" + CurrentBar.ToString(), IsAutoScale, 1, entryLevelLine[1], 0, entryLevelLine[0],
                                        entryLineColorUp, entryLineStyle, entryLineWidth);
                            }
                            entryLong[0] = entryLevel;
                            if (riskManagementPosition != RiskManagementStyle.False)
                            {
                                double entryRM = entryLong[0];
                                double stopRM = swingLow.CurPrice - 1 * TickSize;
                                double target100RM = 0.0;
                                if (swingCurrent.SwingSlope == 1)
                                    target100RM = swingLow.CurPrice + swingHigh.LastLength * TickSize * abcTarget / 100;
                                else
                                    target100RM = swingLow.CurPrice + swingHigh.CurLength * TickSize * abcTarget / 100;
                                CalculateLongRisk(entryRM, stopRM, target100RM);
                            }
                        }
                        else if (IsFirstTickOfBar)
                        {
                            entryLevelLine[0] = entryLevel;

                            if (showEntryLine)
                            {
                                if (entryLevelLine[1] == 0)
                                    Draw.Line(this, "EntryLine" + CurrentBar.ToString(), IsAutoScale, 1, entryLevelLine[0], 0, entryLevelLine[0],
                                        entryLineColorUp, entryLineStyle, entryLineWidth);
                                else
                                    Draw.Line(this, "EntryLine" + CurrentBar.ToString(), IsAutoScale, 1, entryLevelLine[1], 0, entryLevelLine[0],
                                        entryLineColorUp, entryLineStyle, entryLineWidth);
                            }
                        }
                        abcSignals[0] = 1;

                        bool abcLong = false;
                        if (Calculate == Calculate.OnBarClose || State == State.Historical)
                        {
                            if (Close[0] > entryLevel)
                            {
                                entryLong[0] = Close[0];
                                abcLong = true;
                            }
                        }
                        else
                        {
                            if (IsFirstTickOfBar && Open[0] > entryLevel)
                            {
                                entryLong[0] = Open[0];
                                abcLong = true;
                            }
                        }

                        if (abcLong)
                        {
                            if (showEntryArrows)
                                Draw.ArrowUp(this, "AbcUp" + abcEntryTag++.ToString(), IsAutoScale, 0,
                                    Low[0] - yTickOffset * TickSize, abcTextColorUp);
                            abcLongChanceInProgress = false;
                            entryLineStartBar = 0;
                            entryBar = CurrentBar;
                            abcSignals[0] = 2;
                            if (riskManagementPosition != RiskManagementStyle.False)
                            {
                                double entryRM = entryLong[0];
                                double stopRM = swingLow.CurPrice - 1 * TickSize;
                                double target100RM = 0.0;
                                if (swingCurrent.SwingSlope == 1)
                                    target100RM = swingLow.CurPrice + swingHigh.LastLength * TickSize * abcTarget / 100;
                                else
                                    target100RM = swingLow.CurPrice + swingHigh.CurLength * TickSize * abcTarget / 100;
                                CalculateLongRisk(entryRM, stopRM, target100RM);
                            }
                            if (alertAbcEntry)
                                Alert("Alert_Abc_Long_Entry" + alertTag++.ToString(), alertAbcEntryPriority, "ABC Long Entry" + " ("
                                    + Instrument.FullName + " " + BarsPeriod + ")", alertAbcLongEntrySoundFileName, 0, Brushes.Blue, Brushes.White);
                        }
                    }
                }
            }
            //-------------------------------------------------------------------------------------
            #endregion

            #region ABC short pattern
            //-------------------------------------------------------------------------------------
            if (abcPattern == AbcPatternMode.Long_Short || abcPattern == AbcPatternMode.Short)
            {
                if ((swingHigh.Update || swingHigh.New) && !abcShortChanceInProgress
                        && swingHigh.LastRelation == 1 && swingHigh.CurRelation == -1
                        && swingHigh.CurPercent > abcMinRetracement && swingHigh.CurPercent < abcMaxRetracement)
                {
                    drawTag = swingLow.Counter;
                    abcShortChanceInProgress = true;
                    entryLineStartBar = CurrentBar;
                    patternCounter++;
                    tmpCounter = swingHigh.Counter;
                    abcSignals[0] = -1;

                    aBar = CurrentBar - swingHigh.LastBar;
                    bBar = CurrentBar - swingLow.CurBar;
                    cBar = CurrentBar - swingHigh.CurBar;

                    Draw.Line(this, "ABLineDn" + drawTag, IsAutoScale, aBar, swingHigh.LastPrice,
                        bBar, swingLow.CurPrice, abcZigZagColorDn, abcLineStyle, abcLineWidth);
                    Draw.Line(this, "BCLineDn" + drawTag, IsAutoScale, bBar, swingLow.CurPrice,
                        cBar, swingHigh.CurPrice, abcZigZagColorDn, abcLineStyle, abcLineWidth);
                    Draw.Line(this, "ACLineDn" + drawTag, IsAutoScale, aBar, swingHigh.LastPrice,
                        cBar, swingHigh.CurPrice, abcZigZagColorDn, abcLineStyleRatio, abcLineWidthRatio);
                    if (abcLabel)
                    {
                        Draw.Text(this, "ADn" + drawTag, IsAutoScale, "A", aBar, swingHigh.LastPrice,
                            abcTextOffsetLabel, abcTextColorDn, abcTextFont,
                            TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
                        Draw.Text(this, "BDn" + drawTag, IsAutoScale, "B", bBar, swingLow.CurPrice,
                            -abcTextOffsetLabel, abcTextColorDn, abcTextFont,
                            TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
                        Draw.Text(this, "CDn" + drawTag, IsAutoScale, "C", cBar, swingHigh.CurPrice,
                            abcTextOffsetLabel, abcTextColorDn, abcTextFont,
                            TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
                    }

                    entryLevel = swingHigh.CurPrice - Instrument.MasterInstrument.RoundToTickSize((swingHigh.CurLength * TickSize)
                        / 100 * retracementEntryValue);
                    entryLevelLine[0] = entryLevel;
                    if (showEntryLine)
                        Draw.Line(this, "EntryLine" + CurrentBar.ToString(), IsAutoScale, 1, entryLevelLine[0], 0, entryLevelLine[0],
                            entryLineColorDn, entryLineStyle, entryLineWidth);
                    if (alertAbc)
                        Alert("Alert_Abc_Short" + alertTag++.ToString(), alertAbcPriority, "ABC Short" + " ("
                            + Instrument.FullName + " " + BarsPeriod + ")", alertAbcShortSoundFileName, 0, Brushes.White, Brushes.Red);
                    entryShort[0] = entryLevel;
                    if (riskManagementPosition != RiskManagementStyle.False)
                    {
                        double entryRM = entryShort[0];
                        double stopRM = swingHigh.CurPrice + 1 * TickSize;
                        double target100RM = 0.0;
                        if (swingCurrent.SwingSlope == -1)
                            target100RM = swingHigh.CurPrice + swingLow.LastLength * TickSize * abcTarget / 100;
                        else
                            target100RM = swingHigh.CurPrice + swingLow.CurLength * TickSize * abcTarget / 100;
                        CalculateShortRisk(entryRM, stopRM, target100RM);
                    }
                }

                if (abcShortChanceInProgress)
                {
                    if (swingHigh.CurPercent > abcMaxRetracement && tmpCounter == swingHigh.Counter)
                    {
                        abcShortChanceInProgress = false;
                        RemoveDrawObject("ABLineDn" + drawTag.ToString());
                        RemoveDrawObject("BCLineDn" + drawTag.ToString());
                        RemoveDrawObject("ACLineDn" + drawTag.ToString());
                        RemoveDrawObject("ADn" + drawTag.ToString());
                        RemoveDrawObject("BDn" + drawTag.ToString());
                        RemoveDrawObject("CDn" + drawTag.ToString());
                        // Remove entryLevelLine (maybe remove more objects as drawn (COBC))
                        if (!showHistoricalEntryLine)
                        {
                            for (int index = 0; index < CurrentBar - entryLineStartBar + 1; index++)
                            {
                                RemoveDrawObject("EntryLine" + (CurrentBar - index).ToString());
                            }
                            entryLineStartBar = 0;
                        }
                    }
                    else if (upFlip[0] && tmpCounter != swingHigh.Counter)
                    {
                        abcShortChanceInProgress = false;
                        entryLineStartBar = 0;
                    }
                    else
                    {
                        if (swingHigh.Update && tmpCounter == swingHigh.Counter)
                        {
                            aBar = CurrentBar - swingHigh.LastBar;
                            bBar = CurrentBar - swingLow.CurBar;
                            cBar = CurrentBar - swingHigh.CurBar;

                            Draw.Line(this, "BCLineDn" + drawTag, IsAutoScale, bBar, swingLow.CurPrice,
                                cBar, swingHigh.CurPrice, abcZigZagColorDn, abcLineStyle, abcLineWidth);
                            Draw.Line(this, "ACLineDn" + drawTag, IsAutoScale, aBar, swingHigh.LastPrice,
                                cBar, swingHigh.CurPrice, abcZigZagColorDn, abcLineStyleRatio, abcLineWidthRatio);
                            if (abcLabel)
                            {
                                Draw.Text(this, "CDn" + drawTag, IsAutoScale, "C", cBar, swingHigh.CurPrice,
                                    abcTextOffsetLabel, abcTextColorDn, abcTextFont,
                                    TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
                            }

                            entryLevel = swingHigh.CurPrice - Instrument.MasterInstrument.RoundToTickSize((swingHigh.CurLength * TickSize)
                                / 100 * retracementEntryValue);
                            entryLevelLine[0] = entryLevel;

                            if (showEntryLine)
                            {
                                if (entryLevelLine[1] == 0)
                                    Draw.Line(this, "EntryLine" + CurrentBar.ToString(), IsAutoScale, 1, entryLevelLine[0], 0, entryLevelLine[0],
                                        entryLineColorDn, entryLineStyle, entryLineWidth);
                                else
                                    Draw.Line(this, "EntryLine" + CurrentBar.ToString(), IsAutoScale, 1, entryLevelLine[1], 0, entryLevelLine[0],
                                        entryLineColorDn, entryLineStyle, entryLineWidth);
                            }
                            entryShort[0] = entryLevel;
                            if (riskManagementPosition != RiskManagementStyle.False)
                            {
                                double entryRM = entryShort[0];
                                double stopRM = swingHigh.CurPrice + 1 * TickSize;
                                double target100RM = 0.0;
                                if (swingCurrent.SwingSlope == -1)
                                    target100RM = swingHigh.CurPrice + swingLow.LastLength * TickSize * abcTarget / 100;
                                else
                                    target100RM = swingHigh.CurPrice + swingLow.CurLength * TickSize * abcTarget / 100;
                                CalculateShortRisk(entryRM, stopRM, target100RM);
                            }
                        }
                        else if (IsFirstTickOfBar)
                        {
                            entryLevelLine[0] = entryLevel;

                            if (showEntryLine)
                            {
                                if (entryLevelLine[1] == 0)
                                    Draw.Line(this, "EntryLine" + CurrentBar.ToString(), IsAutoScale, 1, entryLevelLine[0], 0, entryLevelLine[0],
                                        entryLineColorDn, entryLineStyle, entryLineWidth);
                                else
                                    Draw.Line(this, "EntryLine" + CurrentBar.ToString(), IsAutoScale, 1, entryLevelLine[1], 0, entryLevelLine[0],
                                        entryLineColorDn, entryLineStyle, entryLineWidth);
                            }
                        }
                        abcSignals[0] = -1;

                        bool abcShort = false;
                        if (Calculate == Calculate.OnBarClose || State == State.Historical)
                        {
                            if (Close[0] < entryLevel)
                            {
                                entryShort[0] = Close[0];
                                abcShort = true;
                            }
                        }
                        else
                        {
                            if (IsFirstTickOfBar && Open[0] < entryLevel)
                            {
                                entryShort[0] = Open[0];
                                abcShort = true;
                            }
                        }

                        if (abcShort)
                        {
                            if (showEntryArrows)
                                Draw.ArrowDown(this, "AbcDn" + abcEntryTag++.ToString(), IsAutoScale, 0,
                                    High[0] + yTickOffset * TickSize, abcTextColorDn);
                            abcShortChanceInProgress = false;
                            entryLineStartBar = 0;
                            entryBar = CurrentBar;
                            abcSignals[0] = -2;
                            if (riskManagementPosition != RiskManagementStyle.False)
                            {
                                double entryRM = entryShort[0];
                                double stopRM = swingHigh.CurPrice + 1 * TickSize;
                                double target100RM = 0.0;
                                if (swingCurrent.SwingSlope == -1)
                                    target100RM = swingHigh.CurPrice + swingLow.LastLength * TickSize * abcTarget / 100;
                                else
                                    target100RM = swingHigh.CurPrice + swingLow.CurLength * TickSize * abcTarget / 100;
                                CalculateShortRisk(entryRM, stopRM, target100RM);
                            }
                            if (alertAbcEntry)
                                Alert("Alert_Abc_Short_Entry" + alertTag++.ToString(), alertAbcEntryPriority, "ABC Short Entry" + " ("
                                    + Instrument.FullName + " " + BarsPeriod + ")", alertAbcShortEntrySoundFileName, 0, Brushes.Red, Brushes.Black);
                        }
                    }
                }
            }
            //-------------------------------------------------------------------------------------
            #endregion
            //=====================================================================================
            #endregion

            #region Divergence
            //=====================================================================================
            if (divergenceMode != DivergenceMode.False)
            {
                if (divergenceDirection != DivergenceDirection.Short)
                {
                    if (swingHigh.New == true && swingHigh.Update == false)
                    {
                        drawTagDivDn++;
                        divLastSwing = swingHigh.LastPrice;
                        divLastOscValue = Math.Max(divergenceDataHigh[CurrentBar -
                            swingHigh.LastBar + 1], Math.Max(divergenceDataHigh[CurrentBar -
                            swingHigh.LastBar], divergenceDataHigh[CurrentBar -
                            swingHigh.LastBar - 1]));
                    }

                    if (swingHigh.New == true || swingHigh.Update == true)
                    {
                        divCurSwing = swingHigh.CurPrice;
                        divCurOscValue = Math.Max(divergenceDataHigh[CurrentBar -
                            swingHigh.CurBar], divergenceDataHigh[CurrentBar -
                            swingHigh.CurBar + 1]);

                        if (showDivergenceHidden == true)
                        {
                            if (divLastSwing > divCurSwing && divLastOscValue < divCurOscValue)
                            {
                                Draw.Line(this, "DivHidSignalDn" + drawTagDivDn, IsAutoScale,
                                    CurrentBar - swingHigh.LastBar, swingHigh.LastPrice,
                                    CurrentBar - swingHigh.CurBar, swingHigh.CurPrice,
                                    divDnLineColor, divDnLineStyle, divDnLineWidth);
                                int textDivBarAgo = Convert.ToInt32(CurrentBar -
                                    (swingHigh.LastBar + swingHigh.CurBar) / 2);
                                double textDivPrice = Instrument.MasterInstrument.RoundToTickSize(
                                    (swingHigh.LastPrice + swingHigh.CurPrice) / 2);
                                Draw.Text(this, "DivHidTextDn" + drawTagDivDn, IsAutoScale, "hDiv",
                                    textDivBarAgo, textDivPrice, 10, divDnLineColor, textFont,
                                    TextAlignment.Center, Brushes.Transparent, Brushes.Transparent,
                                    0);
                                divHiddenShortActive = true;
                                divSignal[0] = -2;
                            }
                            else
                            {
                                RemoveDrawObject("DivHidSignalDn" + drawTagDivDn);
                                RemoveDrawObject("DivHidTextDn" + drawTagDivDn);
                                divHiddenShortActive = false;
                            }
                        }

                        if (showDivergenceRegular == true)
                        {
                            if (divLastSwing < divCurSwing && divLastOscValue > divCurOscValue)
                            {
                                Draw.Line(this, "DivSignalDn" + drawTagDivDn, IsAutoScale,
                                    CurrentBar - swingHigh.LastBar, swingHigh.LastPrice,
                                    CurrentBar - swingHigh.CurBar, swingHigh.CurPrice,
                                    divDnLineColor, divDnLineStyle, divDnLineWidth);
                                int textDivBarAgo = Convert.ToInt32(CurrentBar -
                                    (swingHigh.LastBar + swingHigh.CurBar) / 2);
                                double textDivPrice = Instrument.MasterInstrument.RoundToTickSize(
                                    (swingHigh.LastPrice + swingHigh.CurPrice) / 2);
                                Draw.Text(this, "DivRegTextDn" + drawTagDivDn, IsAutoScale, "rDiv",
                                    textDivBarAgo, textDivPrice, 10, divDnLineColor, textFont,
                                    TextAlignment.Center, Brushes.Transparent, Brushes.Transparent,
                                    0);
                                divRegularShortActive = true;
                                divSignal[0] = -1;
                            }
                            else
                            {
                                RemoveDrawObject("DivSignalDn" + drawTagDivDn);
                                RemoveDrawObject("DivRegTextDn" + drawTagDivDn);
                                divRegularShortActive = false;
                            }
                        }
                    }
                }

                if (divergenceDirection != DivergenceDirection.Long)
                {
                    if (swingLow.New == true && swingLow.Update == false)
                    {
                        drawTagDivUp++;
                        divLastSwing = swingLow.LastPrice;
                        divLastOscValue = Math.Min(divergenceDataLow[CurrentBar -
                            swingLow.LastBar + 1], Math.Min(divergenceDataLow[CurrentBar -
                            swingLow.LastBar], divergenceDataLow[CurrentBar -
                            swingLow.LastBar - 1]));
                    }

                    if (swingLow.New == true || swingLow.Update == true)
                    {
                        divCurSwing = swingLow.CurPrice;
                        divCurOscValue = Math.Min(divergenceDataLow[CurrentBar - swingLow.CurBar],
                            divergenceDataLow[CurrentBar - swingLow.CurBar + 1]);

                        if (showDivergenceHidden == true)
                        {
                            if (divLastSwing < divCurSwing && divLastOscValue > divCurOscValue)
                            {
                                Draw.Line(this, "DivHidSignalup" + drawTagDivUp, IsAutoScale,
                                    CurrentBar - swingLow.LastBar, swingLow.LastPrice,
                                    CurrentBar - swingLow.CurBar, swingLow.CurPrice,
                                    divUpLineColor, divUpLineStyle, divUpLineWidth);
                                int textDivBarAgo = Convert.ToInt32(CurrentBar -
                                    (swingLow.LastBar + swingLow.CurBar) / 2);
                                double textDivPrice = Instrument.MasterInstrument.RoundToTickSize(
                                    (swingLow.LastPrice + swingLow.CurPrice) / 2);
                                Draw.Text(this, "DivHidTextUp" + drawTagDivUp, IsAutoScale, "hDiv",
                                    textDivBarAgo, textDivPrice, -10, divUpLineColor, textFont,
                                    TextAlignment.Center, Brushes.Transparent, Brushes.Transparent,
                                    0);
                                divHiddenLongActive = true;
                                divSignal[0] = 2;
                            }
                            else
                            {
                                RemoveDrawObject("DivHidSignalup" + drawTagDivUp);
                                RemoveDrawObject("DivHidTextUp" + drawTagDivUp);
                                divHiddenLongActive = false;
                            }
                        }

                        if (showDivergenceRegular == true)
                        {
                            if (divLastSwing > divCurSwing && divLastOscValue < divCurOscValue)
                            {
                                Draw.Line(this, "DivSignalUp" + drawTagDivUp, IsAutoScale,
                                    CurrentBar - swingLow.LastBar, swingLow.LastPrice,
                                    CurrentBar - swingLow.CurBar, swingLow.CurPrice,
                                    divUpLineColor, divUpLineStyle, divUpLineWidth);
                                int textDivBarAgo = Convert.ToInt32(CurrentBar -
                                    (swingLow.LastBar + swingLow.CurBar) / 2);
                                double textDivPrice = Instrument.MasterInstrument.RoundToTickSize(
                                    (swingLow.LastPrice + swingLow.CurPrice) / 2);
                                Draw.Text(this, "DivRegTextUp" + drawTagDivUp, IsAutoScale, "rDiv",
                                    textDivBarAgo, textDivPrice, -10, divUpLineColor, textFont,
                                    TextAlignment.Center, Brushes.Transparent, Brushes.Transparent,
                                    0);
                                divRegularLongActive = true;
                                divSignal[0] = 1;
                            }
                            else
                            {
                                RemoveDrawObject("DivSignalUp" + drawTagDivUp);
                                RemoveDrawObject("DivRegTextUp" + drawTagDivUp);
                                divRegularLongActive = false;
                            }
                        }
                    }
                }

                if (dnFlip[0] == true)
                {
                    if (divRegularShortActive == true)
                    {
                        divRegularShortActive = false;
                        divSignal[0] = -3;
                    }
                    else if (divHiddenShortActive == true)
                    {
                        divHiddenShortActive = false;
                        divSignal[0] = -4;
                    }
                }
                else if (upFlip[0] == true)
                {
                    if (divRegularLongActive == true)
                    {
                        divRegularLongActive = false;
                        divSignal[0] = 3;
                    }
                    else if (divHiddenLongActive == true)
                    {
                        divHiddenLongActive = false;
                        divSignal[0] = 4;
                    }
                }
            }
            //=====================================================================================
            #endregion

            #region Naked swing
            //=====================================================================================
            if (showNakedSwings == true)
            {
                if (swingLow.New == true && swingLow.Update == false)
                {
                    nakedSwingHighsList.Add(swingHigh.CurPrice, swingHigh.CurBar);
                    Draw.Ray(this, "NakedSwingHigh" + swingHigh.CurPrice.ToString(), false,
                        CurrentBar - swingHigh.CurBar, swingHigh.CurPrice,
                        CurrentBar - swingHigh.CurBar - 1, swingHigh.CurPrice,
                        nakedSwingHighColor, nakedSwingDashStyle,
                        nakedSwingLineWidth);
                }
                if ((swingLow.New == true || swingLow.Update == true)
                    && nakedSwingLowsList.Count > 0)
                {
                    while (nakedSwingLowsList.Count > 0
                        && nakedSwingLowsList.Keys[nakedSwingLowsList.Count
                        - 1] >= swingLow.CurPrice)
                    {
                        int counter = nakedSwingLowsList.Count - 1;
                        double nakedSwingLowPrice = nakedSwingLowsList.Keys[counter];
                        RemoveDrawObject("NakedSwingLow" + nakedSwingLowPrice.ToString());
                        if (showHistoricalNakedSwings == true)
                        {
                            Draw.Line(this, "NakedSwingLow" + nakedSwingCounter++, false,
                                CurrentBar - nakedSwingLowsList.Values[counter],
                                nakedSwingLowPrice, CurrentBar - swingLow.CurBar,
                                nakedSwingLowPrice, nakedSwingLowColor,
                                nakedSwingDashStyle, nakedSwingLineWidth);
                        }
                        nakedSwingLowsList.RemoveAt(counter);
                    }
                }
                if (swingHigh.New == true && swingHigh.Update == false)
                {
                    nakedSwingLowsList.Add(swingLow.CurPrice, swingLow.CurBar);
                    Draw.Ray(this, "NakedSwingLow" + swingLow.CurPrice.ToString(), false,
                        CurrentBar - swingLow.CurBar, swingLow.CurPrice,
                        CurrentBar - swingLow.CurBar - 1, swingLow.CurPrice,
                        nakedSwingLowColor, nakedSwingDashStyle,
                        nakedSwingLineWidth);
                }
                if ((swingHigh.New == true || swingHigh.Update == true)
                    && nakedSwingHighsList.Count > 0)
                {
                    while (nakedSwingHighsList.Count > 0
                        && nakedSwingHighsList.Keys[0] <= swingHigh.CurPrice)
                    {
                        double nakedSwingHighPrice = nakedSwingHighsList.Keys[0];
                        RemoveDrawObject("NakedSwingHigh" + nakedSwingHighPrice.ToString());
                        if (showHistoricalNakedSwings == true)
                        {
                            Draw.Line(this, "NakedSwingHigh" + nakedSwingCounter++, false,
                                CurrentBar - nakedSwingHighsList.Values[0],
                                nakedSwingHighPrice, CurrentBar - swingHigh.CurBar,
                                nakedSwingHighPrice, nakedSwingHighColor,
                                nakedSwingDashStyle, nakedSwingLineWidth);
                        }
                        nakedSwingHighsList.RemoveAt(0);
                    }
                }
            }
            //=====================================================================================
            #endregion

            #region Swing switch
            //=====================================================================================
            if (showSwingSwitch == true)
            {
                if (swingLow.New == true && swingLow.Update == false)
                    Draw.TriangleDown(this, "DnSwingStart", false, 0,
                        Highs[BarsInProgress][0] + swingSwitchOffsetInTicks * TickSize,
                        swingSwitchDownColor);

                if (swingHigh.New == true && swingHigh.Update == false)
                    Draw.TriangleUp(this, "UpSwingStart", false, 0,
                        Lows[BarsInProgress][0] - swingSwitchOffsetInTicks * TickSize,
                        swingSwitchUpColor);
            }
            //=====================================================================================
            #endregion

            #region Alerts
            //=====================================================================================
            // Double bottom
            if (alertDoubleBottom == true && swingHigh.New == true && swingHigh.Update == false
                && swingLow.CurRelation == 0)
            {
                Print(alertDoubleTopMessage + " (" + Instrument.FullName + " " + BarsPeriod + ")");
                Alert("alertDoubleBottom" + alertTag++, alertDoubleBottomPriority,
                    alertDoubleBottomMessage + " (" + Instrument.FullName + " " + BarsPeriod + ")",
                    alertDoubleBottomSoundFileName, alertDoubleBottomRearmSeconds,
                    alertDoubleBottomBackColor, alertDoubleBottomForeColor);
            }
            //=====================================================================================
            // Double Top
            if (alertDoubleTop == true && swingLow.New == true && swingLow.Update == false
                && swingHigh.CurRelation == 0)
            {
                Print(alertDoubleTopMessage + " (" + Instrument.FullName + " " + BarsPeriod + ")");
                Alert("alertDoubleTop" + alertTag++, alertDoubleTopPriority,
                    alertDoubleTopMessage + " (" + Instrument.FullName + " " + BarsPeriod + ")",
                    alertDoubleTopSoundFileName, alertDoubleTopRearmSeconds,
                    alertDoubleTopBackColor, alertDoubleTopForeColor);
            }
            //=====================================================================================
            // Swing change
            if (alertSwingChange == true && ((swingHigh.New == true && swingHigh.Update == false)
                || (swingLow.New == true && swingLow.Update == false)))
            {
                Print(alertDoubleTopMessage + " (" + Instrument.FullName + " " + BarsPeriod + ")");
                Alert("alertSwingChange" + alertTag++, alertSwingChangePriority,
                    alertSwingChangeMessage + " (" + Instrument.FullName + " " + BarsPeriod + ")",
                    alertSwingChangeSoundFileName, alertSwingChangeRearmSeconds,
                    alertSwingChangeBackColor, alertSwingChangeForeColor);
            }
            //=====================================================================================
            // Divergence regular high
            if (alertDivergenceRegularHigh == true && swingLow.New == true
                && swingLow.Update == false && divSignal[0] == -3)
            {
                Alert("alertDivergenceRegularHigh" + alertTag++,
                    alertDivergenceRegularHighPriority,
                    alertDivergenceRegularHighMessage + " (" + Instrument.FullName + " " + BarsPeriod + ")",
                    alertDivergenceRegularHighSoundFileName,
                    alertDivergenceRegularHighRearmSeconds, alertDivergenceRegularHighBackColor,
                    alertDivergenceRegularHighForeColor);
            }
            //=====================================================================================
            // Divergence hidden high
            if (alertDivergenceHiddenHigh == true && swingLow.New == true
                && swingLow.Update == false && divSignal[0] == -4)
            {
                Alert("alertDivergenceHiddenHigh" + alertTag++,
                    alertDivergenceHiddenHighPriority,
                    alertDivergenceHiddenHighMessage + " (" + Instrument.FullName + " " + BarsPeriod + ")",
                    alertDivergenceHiddenHighSoundFileName,
                    alertDivergenceHiddenHighRearmSeconds, alertDivergenceHiddenHighBackColor,
                    alertDivergenceHiddenHighForeColor);
            }
            //=====================================================================================
            // Divergence regular low
            if (alertDivergenceRegularLow == true && swingHigh.New == true
                && swingHigh.Update == false && divSignal[0] == 3)
            {
                Alert("alertDivergenceRegularLow" + alertTag++,
                    alertDivergenceRegularLowPriority,
                    alertDivergenceRegularLowMessage + " (" + Instrument.FullName + " " + BarsPeriod + ")",
                    alertDivergenceRegularLowSoundFileName,
                    alertDivergenceRegularLowRearmSeconds, alertDivergenceRegularLowBackColor,
                    alertDivergenceRegularLowForeColor);
            }
            //=====================================================================================
            // Divergence hidden low
            if (alertDivergenceHiddenLow == true && swingHigh.New == true
                && swingHigh.Update == false && divSignal[0] == 4)
            {
                Alert("alertDivergenceHiddenLow" + alertTag++,
                    alertDivergenceHiddenLowPriority,
                    alertDivergenceHiddenLowMessage + " (" + Instrument.FullName + " " + BarsPeriod + ")",
                    alertDivergenceHiddenLowSoundFileName,
                    alertDivergenceHiddenLowRearmSeconds, alertDivergenceHiddenLowBackColor,
                    alertDivergenceHiddenLowForeColor);
            }
            //=====================================================================================
            // Higher low
            if (alertHigherLow == true && swingHigh.New == true
                && swingHigh.Update == false && swingLow.CurRelation == 1)
            {
                Alert("alertHigherLow" + alertTag++,
                    alertHigherLowPriority,
                    alertHigherLowMessage + " (" + Instrument.FullName + " " + BarsPeriod + ")",
                    alertHigherLowSoundFileName,
                    alertHigherLowRearmSeconds, alertHigherLowBackColor,
                    alertHigherLowForeColor);
            }
            //=====================================================================================
            // Lower high
            if (alertLowerHigh == true && swingLow.New == true
                && swingLow.Update == false && swingHigh.CurRelation == -1)
            {
                Alert("alertLowerHigh" + alertTag++,
                    alertLowerHighPriority,
                    alertLowerHighMessage + " (" + Instrument.FullName + " " + BarsPeriod + ")",
                    alertLowerHighSoundFileName,
                    alertLowerHighRearmSeconds, alertLowerHighBackColor,
                    alertLowerHighForeColor);
            }
            //=====================================================================================
            #endregion
        }
     
        #region Initialize swing calculation
        //#########################################################################################
        public void InitializeSwingCalculation(Swings swingHigh, Swings swingLow,
            SwingCurrent swingCur, Series<bool> upFlip, List<SwingStruct> swingHighs,
            Series<bool> dnFlip, List<SwingStruct> swingLows)
        {
            if (IsFirstTickOfBar)
            {
                swingCur.StopOutsideBarCalc = false;

                // Initialize first swing
                if (swingHighs.Count == 0)
                {
                    swingHigh.CurBar = CurrentBars[BarsInProgress];
                    swingHigh.CurPrice = Highs[BarsInProgress][CurrentBars[BarsInProgress]];
                    swingHigh.CurDateTime = swingHigh.LastDateTime =
                        Times[BarsInProgress][CurrentBars[BarsInProgress]];
                    SwingStruct up = new SwingStruct(swingHigh.CurPrice, swingHigh.CurBar,
                        Times[BarsInProgress][CurrentBars[BarsInProgress] - 1], 0, 0, -1,
                        Convert.ToInt64(Volumes[BarsInProgress][0]));
                    swingHighs.Add(up);
                    swingHigh.ListCount = swingHighs.Count;
                }
                if (swingLows.Count == 0)
                {
                    swingLow.CurBar = CurrentBars[BarsInProgress];
                    swingLow.CurPrice = Lows[BarsInProgress][CurrentBars[BarsInProgress]];
                    swingLow.CurDateTime = swingLow.LastDateTime =
                        Times[BarsInProgress][CurrentBars[BarsInProgress]];
                    SwingStruct dn = new SwingStruct(swingLow.CurPrice, swingLow.CurBar,
                        Times[BarsInProgress][CurrentBars[BarsInProgress] - 1], 0, 0, -1,
                        Convert.ToInt64(Volumes[BarsInProgress][0]));
                    swingLows.Add(dn);
                    swingLow.ListCount = swingLows.Count;
                }
            }
            // Set new/update high/low back to false, to avoid function calls which depends on
            // them
            dnFlip[0] = false;
            upFlip[0] = false;
            swingHigh.New = swingLow.New = swingHigh.Update = swingLow.Update = false;
        }
        //#########################################################################################
        #endregion

        #region Calculate Swing Standard
        //#########################################################################################
        protected void CalculateSwingStandard(Swings swingHigh, Swings swingLow,
            SwingCurrent swingCur, SwingProperties swingProp, Series<bool> upFlip,
            List<SwingStruct> swingHighs, Series<bool> dnFlip, List<SwingStruct> swingLows,
            int decimalPlaces, bool useCloseValues, Series<double> doubleBottom, Series<double> lowerLow,
            Series<double> higherLow, Series<double> doubleTop, Series<double> lowerHigh,
            Series<double> higherHigh, Series<double> gannSwing)
        {
            // Check if high and low values are used or only close values
            PriceSeries[] highs;
            PriceSeries[] lows;
            if (useCloseValues == true)
            {
                lows = Closes;
                highs = Closes;
            }
            else
            {
                lows = Lows;
                highs = Highs;
            }

            // For a new swing high in an uptrend, Highs[BarsInProgress][0] must be
            // greater than the current swing high
            if (swingCur.SwingSlope == 1 && highs[BarsInProgress][0] <= swingHigh.CurPrice)
                swingHigh.New = false;
            else
                swingHigh.New = true;

            // For a new swing low in a downtrend, Lows[BarsInProgress][0] must be
            // smaller than the current swing low
            if (swingCur.SwingSlope == -1 && lows[BarsInProgress][0] >= swingLow.CurPrice)
                swingLow.New = false;
            else
                swingLow.New = true;

            // CalculatOnBarClose == true
            if (Calculate == Calculate.OnBarClose)
            {
                // test if Highs[BarsInProgress][0] is higher than the last
                // calculationSize highs = new swing high
                if (swingHigh.New)
                {
                    for (int i = 1; i < swingProp.SwingSize + 1; i++)
                    {
                        if (highs[BarsInProgress][0] <= highs[BarsInProgress][i])
                        {
                            swingHigh.New = false;
                            break;
                        }
                    }
                }
                // test if Lows[BarsInProgress][0] is lower than the last
                // calculationSize lows = new swing low
                if (swingLow.New)
                {
                    for (int i = 1; i < swingProp.SwingSize + 1; i++)
                    {
                        if (lows[BarsInProgress][0] >= lows[BarsInProgress][i])
                        {
                            swingLow.New = false;
                            break;
                        }
                    }
                }

                // New swing high and new swing low
                if (swingHigh.New && swingLow.New)
                {
                    // Downtrend - ignore the swing high
                    if (swingCur.SwingSlope == -1)
                        swingHigh.New = false;
                    // Uptrend   - ignore the swing low
                    else
                        swingLow.New = false;
                }
            }
            // CalculatOnBarClose == false
            else
            {
                // Used to control, that only one swing is set for
                // each bar
                if (IsFirstTickOfBar)
                    swingCur.NewSwing = 0;

                // No swing or an up swing is found
                if (swingCur.NewSwing != -1)
                {
                    // test if Highs[BarsInProgress][0] is higher than the last
                    // calculationSize highs = new swing high
                    if (swingHigh.New)
                    {
                        for (int i = 1; i < swingProp.SwingSize + 1; i++)
                        {
                            if (highs[BarsInProgress][0] <= highs[BarsInProgress][i])
                            {
                                swingHigh.New = false;
                                break;
                            }
                        }
                        // Found a swing high
                        if (swingHigh.New)
                            swingCur.NewSwing = 1;
                    }
                }

                // No swing or an down swing is found
                if (swingCur.NewSwing != 1)
                {
                    // test if Lows[BarsInProgress][0] is lower than the last
                    // calculationSize lows = new swing low
                    if (swingLow.New)
                    {
                        for (int i = 1; i < swingProp.SwingSize + 1; i++)
                        {
                            if (lows[BarsInProgress][0] >= lows[BarsInProgress][i])
                            {
                                swingLow.New = false;
                                break;
                            }
                        }
                        // Found a swing low
                        if (swingLow.New)
                            swingCur.NewSwing = -1;
                    }
                }

                // Set newLow back to false
                if (swingCur.NewSwing == 1)
                    swingLow.New = false;
                // Set newHigh back to false
                if (swingCur.NewSwing == -1)
                    swingHigh.New = false;
            }

            // Swing high
            if (swingHigh.New)
            {
                int bar;
                double price;
                // New swing high
                if (swingCur.SwingSlope != 1)
                {
                    bar = CurrentBars[BarsInProgress] -
                        HighestBar(highs[BarsInProgress], CurrentBars[BarsInProgress] -
                        swingLow.CurBar);
                    price = highs[BarsInProgress][HighestBar(highs[BarsInProgress],
                        CurrentBars[BarsInProgress] - swingLow.CurBar)];
                    swingHigh.Update = false;
                }
                // Update swing high
                else
                {
                    bar = CurrentBars[BarsInProgress];
                    price = highs[BarsInProgress][0];
                    swingHigh.Update = true;
                }
                CalcUpSwing(bar, price, swingHigh.Update, swingHigh, swingLow, swingCur,
                    swingProp, upFlip, swingHighs, decimalPlaces, doubleBottom, lowerLow,
                    higherLow, doubleTop, lowerHigh, higherHigh, gannSwing);
            }
            // Swing low
            else if (swingLow.New)
            {
                int bar;
                double price;
                // New swing low
                if (swingCur.SwingSlope != -1)
                {
                    bar = CurrentBars[BarsInProgress] - LowestBar(lows[BarsInProgress],
                        CurrentBars[BarsInProgress] - swingHigh.CurBar);
                    price = lows[BarsInProgress][LowestBar(lows[BarsInProgress],
                        CurrentBars[BarsInProgress] - swingHigh.CurBar)];
                    swingLow.Update = false;
                }
                // Update swing low
                else
                {
                    bar = CurrentBars[BarsInProgress];
                    price = lows[BarsInProgress][0];
                    swingLow.Update = true;
                }
                CalcDnSwing(bar, price, swingLow.Update, swingHigh, swingLow, swingCur,
                    swingProp, dnFlip, swingLows, decimalPlaces, doubleBottom, lowerLow,
                    higherLow, doubleTop, lowerHigh, higherHigh, gannSwing);
            }        
        }
        //#########################################################################################
        #endregion

        #region Calculate Swing Gann
        //#########################################################################################
        protected void CalculateSwingGann(Swings swingHigh, Swings swingLow, SwingCurrent swingCur,
            SwingProperties swingProp, Series<bool> upFlip, List<SwingStruct> swingHighs,
            Series<bool> dnFlip, List<SwingStruct> swingLows, int decimalPlaces,
            Series<double> doubleBottom, Series<double> lowerLow, Series<double> higherLow,
            Series<double> doubleTop, Series<double> lowerHigh, Series<double> higherHigh,
            Series<double> gannSwing)
        {
            #region Set bar property
            //=================================================================================
            // Represents the bar type. -1 = Down | 0 = Inside | 1 = Up | 2 = Outside
            int barType = 0;
            if (Highs[BarsInProgress][0] > Highs[BarsInProgress][1])
            {
                if (Lows[BarsInProgress][0] < Lows[BarsInProgress][1])
                    barType = 2;
                else
                    barType = 1;
            }
            else
            {
                if (Lows[BarsInProgress][0] < Lows[BarsInProgress][1])
                    barType = -1;
                else
                    barType = 0;
            }
            //=================================================================================
            #endregion

            #region Up swing
            //=================================================================================
            if (swingCur.SwingSlope == 1)
            {
                switch (barType)
                {
                    // Up bar
                    case 1:
                        swingCur.ConsecutiveBars = 0;
                        swingCur.ConsecutiveBarValue = 0.0;
                        if (Highs[BarsInProgress][0] > swingHigh.CurPrice)
                        {
                            swingHigh.New = true;
                            swingHigh.Update = true;
                            CalcUpSwing(CurrentBars[BarsInProgress],
                                Highs[BarsInProgress][0], swingHigh.Update, swingHigh,
                                swingLow, swingCur, swingProp, upFlip, swingHighs,
                                decimalPlaces, doubleBottom, lowerLow, higherLow, doubleTop,
                                lowerHigh, higherHigh, gannSwing);
                            if ((swingCur.ConsecutiveBars + 1) == swingProp.SwingSize)
                                swingCur.StopOutsideBarCalc = true;
                        }
                        break;
                    // Down bar
                    case -1:
                        if (swingCur.ConsecutiveBarNumber != CurrentBars[BarsInProgress])
                        {
                            if (swingCur.ConsecutiveBarValue == 0.0)
                            {
                                swingCur.ConsecutiveBars++;
                                swingCur.ConsecutiveBarNumber = CurrentBars[BarsInProgress];
                                swingCur.ConsecutiveBarValue = Lows[BarsInProgress][0];
                            }
                            else if (Lows[BarsInProgress][0] < swingCur.ConsecutiveBarValue)
                            {
                                swingCur.ConsecutiveBars++;
                                swingCur.ConsecutiveBarNumber = CurrentBars[BarsInProgress];
                                swingCur.ConsecutiveBarValue = Lows[BarsInProgress][0];
                            }
                        }
                        else if (Lows[BarsInProgress][0] < swingCur.ConsecutiveBarValue)
                            swingCur.ConsecutiveBarValue = Lows[BarsInProgress][0];
                        if (swingCur.ConsecutiveBars == swingProp.SwingSize ||
                            (swingProp.UseBreakouts && Lows[BarsInProgress][0] <
                            swingLow.CurPrice))
                        {
                            swingCur.ConsecutiveBars = 0;
                            swingCur.ConsecutiveBarValue = 0.0;
                            swingLow.New = true;
                            swingLow.Update = false;
                            int bar = CurrentBars[BarsInProgress] -
                                LowestBar(Lows[BarsInProgress],
                                CurrentBars[BarsInProgress] - swingHigh.CurBar);
                            double price =
                                Lows[BarsInProgress][LowestBar(Lows[BarsInProgress],
                                CurrentBars[BarsInProgress] - swingHigh.CurBar)];
                            CalcDnSwing(bar, price, swingLow.Update, swingHigh, swingLow,
                                swingCur, swingProp, dnFlip, swingLows, decimalPlaces,
                                doubleBottom, lowerLow, higherLow, doubleTop, lowerHigh,
                                higherHigh, gannSwing);
                        }
                        break;
                    // Inside bar
                    case 0:
                        if (!swingProp.IgnoreInsideBars)
                        {
                            swingCur.ConsecutiveBars = 0;
                            swingCur.ConsecutiveBarValue = 0.0;
                        }
                        break;
                    // Outside bar
                    case 2:
                        if (Highs[BarsInProgress][0] > swingHigh.CurPrice)
                        {
                            swingHigh.New = true;
                            swingHigh.Update = true;
                            CalcUpSwing(CurrentBars[BarsInProgress],
                                Highs[BarsInProgress][0], swingHigh.Update, swingHigh,
                                swingLow, swingCur, swingProp, upFlip, swingHighs,
                                decimalPlaces, doubleBottom, lowerLow, higherLow, doubleTop,
                                lowerHigh, higherHigh, gannSwing);
                        }
                        else if (!swingCur.StopOutsideBarCalc)
                        {
                            if (swingCur.ConsecutiveBarNumber != CurrentBars[BarsInProgress])
                            {
                                if (swingCur.ConsecutiveBarValue == 0.0)
                                {
                                    swingCur.ConsecutiveBars++;
                                    swingCur.ConsecutiveBarNumber =
                                        CurrentBars[BarsInProgress];
                                    swingCur.ConsecutiveBarValue = Lows[BarsInProgress][0];
                                }
                                else if (Lows[BarsInProgress][0] <
                                    swingCur.ConsecutiveBarValue)
                                {
                                    swingCur.ConsecutiveBars++;
                                    swingCur.ConsecutiveBarNumber =
                                        CurrentBars[BarsInProgress];
                                    swingCur.ConsecutiveBarValue = Lows[BarsInProgress][0];
                                }
                            }
                            else if (Lows[BarsInProgress][0] < swingCur.ConsecutiveBarValue)
                                swingCur.ConsecutiveBarValue = Lows[BarsInProgress][0];
                            if (swingCur.ConsecutiveBars == swingProp.SwingSize ||
                                (swingProp.UseBreakouts && Lows[BarsInProgress][0] <
                                swingLow.CurPrice))
                            {
                                swingCur.ConsecutiveBars = 0;
                                swingCur.ConsecutiveBarValue = 0.0;
                                swingLow.New = true;
                                swingLow.Update = false;
                                int bar = CurrentBars[BarsInProgress] -
                                    LowestBar(Lows[BarsInProgress],
                                    CurrentBars[BarsInProgress] - swingHigh.CurBar);
                                double price =
                                    Lows[BarsInProgress][LowestBar(Lows[BarsInProgress],
                                    CurrentBars[BarsInProgress] - swingHigh.CurBar)];
                                CalcDnSwing(bar, price, swingLow.Update, swingHigh, swingLow,
                                    swingCur, swingProp, dnFlip, swingLows, decimalPlaces,
                                    doubleBottom, lowerLow, higherLow, doubleTop, lowerHigh,
                                    higherHigh, gannSwing);
                            }
                        }
                        break;
                }
            }
            //=================================================================================
            #endregion

            #region Down swing
            //=================================================================================
            else
            {
                switch (barType)
                {
                    // Dwon bar
                    case -1:
                        swingCur.ConsecutiveBars = 0;
                        swingCur.ConsecutiveBarValue = 0.0;
                        if (Lows[BarsInProgress][0] < swingLow.CurPrice)
                        {
                            swingLow.New = true;
                            swingLow.Update = true;
                            CalcDnSwing(CurrentBars[BarsInProgress],
                                Lows[BarsInProgress][0], swingLow.Update, swingHigh,
                                swingLow, swingCur, swingProp, dnFlip, swingLows,
                                decimalPlaces, doubleBottom, lowerLow, higherLow, doubleTop,
                                lowerHigh, higherHigh, gannSwing);
                            if ((swingCur.ConsecutiveBars + 1) == swingProp.SwingSize)
                                swingCur.StopOutsideBarCalc = true;
                        }
                        break;
                    // Up bar
                    case 1:
                        if (swingCur.ConsecutiveBarNumber != CurrentBars[BarsInProgress])
                        {
                            if (swingCur.ConsecutiveBarValue == 0.0)
                            {
                                swingCur.ConsecutiveBars++;
                                swingCur.ConsecutiveBarNumber = CurrentBars[BarsInProgress];
                                swingCur.ConsecutiveBarValue = Highs[BarsInProgress][0];
                            }
                            else if (Highs[BarsInProgress][0] > swingCur.ConsecutiveBarValue)
                            {
                                swingCur.ConsecutiveBars++;
                                swingCur.ConsecutiveBarNumber = CurrentBars[BarsInProgress];
                                swingCur.ConsecutiveBarValue = Highs[BarsInProgress][0];
                            }
                        }
                        else if (Highs[BarsInProgress][0] > swingCur.ConsecutiveBarValue)
                            swingCur.ConsecutiveBarValue = Highs[BarsInProgress][0];
                        if (swingCur.ConsecutiveBars == swingProp.SwingSize ||
                            (swingProp.UseBreakouts && Highs[BarsInProgress][0] >
                            swingHigh.CurPrice))
                        {
                            swingCur.ConsecutiveBars = 0;
                            swingCur.ConsecutiveBarValue = 0.0;
                            swingHigh.New = true;
                            swingHigh.Update = false;
                            int bar = CurrentBars[BarsInProgress] -
                                HighestBar(Highs[BarsInProgress],
                                CurrentBars[BarsInProgress] - swingLow.CurBar);
                            double price =
                                Highs[BarsInProgress][HighestBar(Highs[BarsInProgress],
                                CurrentBars[BarsInProgress] - swingLow.CurBar)];
                            CalcUpSwing(bar, price, swingHigh.Update, swingHigh, swingLow,
                                swingCur, swingProp, upFlip, swingHighs, decimalPlaces,
                                doubleBottom, lowerLow, higherLow, doubleTop, lowerHigh,
                                higherHigh, gannSwing);
                        }
                        break;
                    // Inside bar
                    case 0:
                        if (!swingProp.IgnoreInsideBars)
                        {
                            swingCur.ConsecutiveBars = 0;
                            swingCur.ConsecutiveBarValue = 0.0;
                        }
                        break;
                    // Outside bar
                    case 2:
                        if (Lows[BarsInProgress][0] < swingLow.CurPrice)
                        {
                            swingLow.New = true;
                            swingLow.Update = true;
                            CalcDnSwing(CurrentBars[BarsInProgress],
                                Lows[BarsInProgress][0], swingLow.Update, swingHigh,
                                swingLow, swingCur, swingProp, dnFlip, swingLows,
                                decimalPlaces, doubleBottom, lowerLow, higherLow, doubleTop,
                                lowerHigh, higherHigh, gannSwing);
                        }
                        else if (!swingCur.StopOutsideBarCalc)
                        {
                            if (swingCur.ConsecutiveBarNumber != CurrentBars[BarsInProgress])
                            {
                                if (swingCur.ConsecutiveBarValue == 0.0)
                                {
                                    swingCur.ConsecutiveBars++;
                                    swingCur.ConsecutiveBarNumber =
                                        CurrentBars[BarsInProgress];
                                    swingCur.ConsecutiveBarValue = Highs[BarsInProgress][0];
                                }
                                else if (Highs[BarsInProgress][0] >
                                    swingCur.ConsecutiveBarValue)
                                {
                                    swingCur.ConsecutiveBars++;
                                    swingCur.ConsecutiveBarNumber =
                                        CurrentBars[BarsInProgress];
                                    swingCur.ConsecutiveBarValue = Highs[BarsInProgress][0];
                                }
                            }
                            else if (Highs[BarsInProgress][0] > swingCur.ConsecutiveBarValue)
                                swingCur.ConsecutiveBarValue = Highs[BarsInProgress][0];
                            if (swingCur.ConsecutiveBars == swingProp.SwingSize ||
                                (swingProp.UseBreakouts && Highs[BarsInProgress][0] >
                                swingHigh.CurPrice))
                            {
                                swingCur.ConsecutiveBars = 0;
                                swingCur.ConsecutiveBarValue = 0.0;
                                swingHigh.New = true;
                                swingHigh.Update = false;
                                int bar = CurrentBars[BarsInProgress] -
                                    HighestBar(Highs[BarsInProgress],
                                    CurrentBars[BarsInProgress] - swingLow.CurBar);
                                double price =
                                    Highs[BarsInProgress][HighestBar(Highs[BarsInProgress],
                                    CurrentBars[BarsInProgress] - swingLow.CurBar)];
                                CalcUpSwing(bar, price, swingHigh.Update, swingHigh,
                                    swingLow, swingCur, swingProp, upFlip, swingHighs,
                                    decimalPlaces, doubleBottom, lowerLow, higherLow,
                                    doubleTop, lowerHigh, higherHigh, gannSwing);
                            }
                        }
                        break;
                }
            }
            //=================================================================================
            #endregion
        }
        //#########################################################################################
        #endregion

        #region Calculate Swing Ticks
        //#########################################################################################
        protected void CalculateSwingTicks(Swings swingHigh, Swings swingLow,
            SwingCurrent swingCur, SwingProperties swingProp, Series<bool> upFlip,
            List<SwingStruct> swingHighs, Series<bool> dnFlip, List<SwingStruct> swingLows,
            int decimalPlaces, bool useCloseValues, Series<double> doubleBottom, Series<double> lowerLow,
            Series<double> higherLow, Series<double> doubleTop, Series<double> lowerHigh,
            Series<double> higherHigh, Series<double> gannSwing)
        {
            // Check if high and low values are used or only close values
            PriceSeries[] highs;
            PriceSeries[] lows;
            if (useCloseValues == true)
            {
                lows = Closes;
                highs = Closes;
            }
            else
            {
                lows = Lows;
                highs = Highs;
            }

            // For a new swing high in an uptrend, Highs[BarsInProgress][0] must be
            // greater than the current swing high
            if (swingCur.SwingSlope == 1 && highs[BarsInProgress][0] <= swingHigh.CurPrice)
                swingHigh.New = false;
            else
                swingHigh.New = true;

            // For a new swing low in a downtrend, Lows[BarsInProgress][0] must be
            // smaller than the current swing low
            if (swingCur.SwingSlope == -1 && lows[BarsInProgress][0] >= swingLow.CurPrice)
                swingLow.New = false;
            else
                swingLow.New = true;

            // CalculatOnBarClose == true
            if (Calculate == Calculate.OnBarClose)
            {
                if (swingHigh.New
                    && highs[BarsInProgress][0] <
                    (swingLow.CurPrice + swingProp.SwingSize * TickSize))
                        swingHigh.New = false;

                if (swingLow.New
                    && lows[BarsInProgress][0] >
                    (swingHigh.CurPrice - swingProp.SwingSize * TickSize))
                    swingLow.New = false;

                // New swing high and new swing low
                if (swingHigh.New && swingLow.New)
                {
                    // Downtrend - ignore the swing high
                    if (swingCur.SwingSlope == -1)
                        swingHigh.New = false;
                    // Uptrend   - ignore the swing low
                    else
                        swingLow.New = false;
                }
            }
            // CalculatOnBarClose == false
            else
            {
                // Used to control, that only one swing is set for
                // each bar
                if (IsFirstTickOfBar)
                    swingCur.NewSwing = 0;

                // No swing or an up swing is found
                if (swingCur.NewSwing != -1)
                {
                    // test if Highs[BarsInProgress][0] is higher than the last
                    // calculationSize highs = new swing high
                    if (swingHigh.New)
                    {
                        if (highs[BarsInProgress][0] <
                            (swingLow.CurPrice + swingProp.SwingSize * TickSize))
                            swingHigh.New = false;
                        // Found a swing high
                        if (swingHigh.New)
                            swingCur.NewSwing = 1;
                    }
                }

                // No swing or an down swing is found
                if (swingCur.NewSwing != 1)
                {
                    // test if Lows[BarsInProgress][0] is lower than the last
                    // calculationSize lows = new swing low
                    if (swingLow.New)
                    {
                        if (lows[BarsInProgress][0] >
                            (swingHigh.CurPrice - swingProp.SwingSize * TickSize))
                            swingLow.New = false;
                        // Found a swing low
                        if (swingLow.New)
                            swingCur.NewSwing = -1;
                    }
                }

                // Set newLow back to false
                if (swingCur.NewSwing == 1)
                    swingLow.New = false;
                // Set newHigh back to false
                if (swingCur.NewSwing == -1)
                    swingHigh.New = false;
            }

            // Swing high
            if (swingHigh.New)
            {
                int bar;
                double price;
                // New swing high
                if (swingCur.SwingSlope != 1)
                {
                    bar = CurrentBars[BarsInProgress] -
                        HighestBar(highs[BarsInProgress], CurrentBars[BarsInProgress] -
                        swingLow.CurBar);
                    price = highs[BarsInProgress][HighestBar(highs[BarsInProgress],
                        CurrentBars[BarsInProgress] - swingLow.CurBar)];
                    swingHigh.Update = false;
                }
                // Update swing high
                else
                {
                    bar = CurrentBars[BarsInProgress];
                    price = highs[BarsInProgress][0];
                    swingHigh.Update = true;
                }
                CalcUpSwing(bar, price, swingHigh.Update, swingHigh, swingLow, swingCur,
                    swingProp, upFlip, swingHighs, decimalPlaces, doubleBottom, lowerLow,
                    higherLow, doubleTop, lowerHigh, higherHigh, gannSwing);
            }
            // Swing low
            else if (swingLow.New)
            {
                int bar;
                double price;
                // New swing low
                if (swingCur.SwingSlope != -1)
                {
                    bar = CurrentBars[BarsInProgress] - LowestBar(lows[BarsInProgress],
                        CurrentBars[BarsInProgress] - swingHigh.CurBar);
                    price = lows[BarsInProgress][LowestBar(lows[BarsInProgress],
                        CurrentBars[BarsInProgress] - swingHigh.CurBar)];
                    swingLow.Update = false;
                }
                // Update swing low
                else
                {
                    bar = CurrentBars[BarsInProgress];
                    price = lows[BarsInProgress][0];
                    swingLow.Update = true;
                }
                CalcDnSwing(bar, price, swingLow.Update, swingHigh, swingLow, swingCur,
                    swingProp, dnFlip, swingLows, decimalPlaces, doubleBottom, lowerLow,
                    higherLow, doubleTop, lowerHigh, higherHigh, gannSwing);
            }
        }
        //#########################################################################################
        #endregion

        #region Calculate Swing Percent
        //#########################################################################################
        protected void CalculateSwingPercent(Swings swingHigh, Swings swingLow,
            SwingCurrent swingCur, SwingProperties swingProp, Series<bool> upFlip,
            List<SwingStruct> swingHighs, Series<bool> dnFlip, List<SwingStruct> swingLows,
            int decimalPlaces, bool useCloseValues, Series<double> doubleBottom, Series<double> lowerLow,
            Series<double> higherLow, Series<double> doubleTop, Series<double> lowerHigh,
            Series<double> higherHigh, Series<double> gannSwing)
        {
            // Check if high and low values are used or only close values
            PriceSeries[] highs;
            PriceSeries[] lows;
            if (useCloseValues == true)
            {
                lows = Closes;
                highs = Closes;
            }
            else
            {
                lows = Lows;
                highs = Highs;
            }

            // For a new swing high in an uptrend, Highs[BarsInProgress][0] must be
            // greater than the current swing high
            if (swingCur.SwingSlope == 1 && highs[BarsInProgress][0] <= swingHigh.CurPrice)
                swingHigh.New = false;
            else
                swingHigh.New = true;

            // For a new swing low in a downtrend, Lows[BarsInProgress][0] must be
            // smaller than the current swing low
            if (swingCur.SwingSlope == -1 && lows[BarsInProgress][0] >= swingLow.CurPrice)
                swingLow.New = false;
            else
                swingLow.New = true;

            // CalculatOnBarClose == true
            if (Calculate == Calculate.OnBarClose)
            {
                if (swingHigh.New
                    && highs[BarsInProgress][0] <
                    (swingLow.CurPrice + swingLow.CurPrice / 100 * swingProp.SwingSize))
                    swingHigh.New = false;

                if (swingLow.New
                    && lows[BarsInProgress][0] >
                    (swingHigh.CurPrice - swingLow.CurPrice / 100 * swingProp.SwingSize))
                    swingLow.New = false;

                // New swing high and new swing low
                if (swingHigh.New && swingLow.New)
                {
                    // Downtrend - ignore the swing high
                    if (swingCur.SwingSlope == -1)
                        swingHigh.New = false;
                    // Uptrend   - ignore the swing low
                    else
                        swingLow.New = false;
                }
            }
            // CalculatOnBarClose == false
            else
            {
                // Used to control, that only one swing is set for
                // each bar
                if (IsFirstTickOfBar)
                    swingCur.NewSwing = 0;

                // No swing or an up swing is found
                if (swingCur.NewSwing != -1)
                {
                    // test if Highs[BarsInProgress][0] is higher than the last
                    // calculationSize highs = new swing high
                    if (swingHigh.New)
                    {
                        if (highs[BarsInProgress][0] <
                            (swingLow.CurPrice + swingLow.CurPrice / 100 * swingProp.SwingSize))
                            swingHigh.New = false;
                        // Found a swing high
                        if (swingHigh.New)
                            swingCur.NewSwing = 1;
                    }
                }

                // No swing or an down swing is found
                if (swingCur.NewSwing != 1)
                {
                    // test if Lows[BarsInProgress][0] is lower than the last
                    // calculationSize lows = new swing low
                    if (swingLow.New)
                    {
                        if (lows[BarsInProgress][0] >
                            (swingHigh.CurPrice - swingLow.CurPrice / 100 * swingProp.SwingSize))
                            swingLow.New = false;
                        // Found a swing low
                        if (swingLow.New)
                            swingCur.NewSwing = -1;
                    }
                }

                // Set newLow back to false
                if (swingCur.NewSwing == 1)
                    swingLow.New = false;
                // Set newHigh back to false
                if (swingCur.NewSwing == -1)
                    swingHigh.New = false;
            }

            // Swing high
            if (swingHigh.New)
            {
                int bar;
                double price;
                // New swing high
                if (swingCur.SwingSlope != 1)
                {
                    bar = CurrentBars[BarsInProgress] -
                        HighestBar(highs[BarsInProgress], CurrentBars[BarsInProgress] -
                        swingLow.CurBar);
                    price = highs[BarsInProgress][HighestBar(highs[BarsInProgress],
                        CurrentBars[BarsInProgress] - swingLow.CurBar)];
                    swingHigh.Update = false;
                }
                // Update swing high
                else
                {
                    bar = CurrentBars[BarsInProgress];
                    price = highs[BarsInProgress][0];
                    swingHigh.Update = true;
                }
                CalcUpSwing(bar, price, swingHigh.Update, swingHigh, swingLow, swingCur,
                    swingProp, upFlip, swingHighs, decimalPlaces, doubleBottom, lowerLow,
                    higherLow, doubleTop, lowerHigh, higherHigh, gannSwing);
            }
            // Swing low
            else if (swingLow.New)
            {
                int bar;
                double price;
                // New swing low
                if (swingCur.SwingSlope != -1)
                {
                    bar = CurrentBars[BarsInProgress] - LowestBar(lows[BarsInProgress],
                        CurrentBars[BarsInProgress] - swingHigh.CurBar);
                    price = lows[BarsInProgress][LowestBar(lows[BarsInProgress],
                        CurrentBars[BarsInProgress] - swingHigh.CurBar)];
                    swingLow.Update = false;
                }
                // Update swing low
                else
                {
                    bar = CurrentBars[BarsInProgress];
                    price = lows[BarsInProgress][0];
                    swingLow.Update = true;
                }
                CalcDnSwing(bar, price, swingLow.Update, swingHigh, swingLow, swingCur,
                    swingProp, dnFlip, swingLows, decimalPlaces, doubleBottom, lowerLow,
                    higherLow, doubleTop, lowerHigh, higherHigh, gannSwing);
            }
        }
        //#########################################################################################
        #endregion

        #region Calculate down swing
        //#########################################################################################
        protected void CalcDnSwing(int bar, double low, bool updateLow, Swings swingHigh,
            Swings swingLow, SwingCurrent swingCur, SwingProperties swingProp, Series<bool> dnFlip,
            List<SwingStruct> swingLows, int decimalPlaces, Series<double> doubleBottom,
            Series<double> lowerLow, Series<double> higherLow, Series<double> doubleTop, Series<double> lowerHigh,
            Series<double> higherHigh, Series<double> gannSwing)
        {
            #region New and update Swing values
            //=====================================================================================
            if (!updateLow)
            {
                if (swingProp.VisualizationType == VisualizationStyle.GannStyle)
                {
                    for (int i = CurrentBar - swingCur.SwingSlopeChangeBar; i >= 0; i--)
                        gannSwing[i] = swingHigh.CurPrice;
                    gannSwing[0] = low;
                }
                swingLow.LastPrice = swingLow.CurPrice;
                swingLow.LastBar = swingLow.CurBar;
                swingLow.LastDateTime = swingLow.CurDateTime;
                swingLow.LastDuration = swingLow.CurDuration;
                swingLow.LastLength = swingLow.CurLength;
                swingLow.LastTime = swingLow.CurTime;
                swingLow.LastPercent = swingLow.CurPercent;
                swingLow.LastRelation = swingLow.CurRelation;
                swingLow.LastVolume = swingLow.CurVolume;
                swingLow.Counter++;
                swingCur.SwingSlope = -1;
                swingCur.SwingSlopeChangeBar = bar;
                dnFlip[0] = true;
            }
            else
            {
                if (swingProp.VisualizationType == VisualizationStyle.Dots
                    || swingProp.VisualizationType == VisualizationStyle.Dots_ZigZag)
                {
                    doubleBottom.Reset(CurrentBar - swingLow.CurBar);
                    higherLow.Reset(CurrentBar - swingLow.CurBar);
                    lowerLow.Reset(CurrentBar - swingLow.CurBar);
                }
                swingLows.RemoveAt(swingLows.Count - 1);
            }
            swingLow.CurBar = bar;
            swingLow.CurPrice = Math.Round(low, decimalPlaces, MidpointRounding.AwayFromZero);
            swingLow.CurTime = ToTime(Times[BarsInProgress][CurrentBars[BarsInProgress] -
                swingLow.CurBar]);
            swingLow.CurDateTime = Times[BarsInProgress][CurrentBars[BarsInProgress] -
                swingLow.CurBar];
            swingLow.CurLength = Convert.ToInt32(Math.Round((swingLow.CurPrice -
                swingHigh.CurPrice) / TickSize, 0, MidpointRounding.AwayFromZero));
            if (swingHigh.CurLength != 0)
                swingLow.CurPercent = Math.Round(100.0 / swingHigh.CurLength *
                    Math.Abs(swingLow.CurLength), 1);
            swingLow.CurDuration = swingLow.CurBar - swingHigh.CurBar;
            double dtbOffset = ATR(BarsArray[BarsInProgress], 14)[CurrentBars[BarsInProgress] -
                swingLow.CurBar] * swingProp.DtbStrength / 100;
            if (swingLow.CurPrice > swingLow.LastPrice - dtbOffset && swingLow.CurPrice <
                swingLow.LastPrice + dtbOffset)
                swingLow.CurRelation = 0;
            else if (swingLow.CurPrice < swingLow.LastPrice)
                swingLow.CurRelation = -1;
            else
                swingLow.CurRelation = 1;
            if (Calculate != Calculate.OnBarClose)
                swingHigh.SignalBarVolume = Volumes[BarsInProgress][0];
            double swingVolume = 0.0;
            for (int i = 0; i < swingLow.CurDuration; i++)
                swingVolume = swingVolume + Volumes[BarsInProgress][i];
            if (Calculate != Calculate.OnBarClose)
                swingVolume = swingVolume + (Volumes[BarsInProgress][CurrentBars[BarsInProgress] -
                    swingHigh.CurBar] - swingLow.SignalBarVolume);
            if (swingProp.SwingVolumeType == SwingVolumeStyle.Relative)
                swingVolume = Math.Round(swingVolume / swingLow.CurDuration, 0,
                    MidpointRounding.AwayFromZero);
            swingLow.CurVolume = Convert.ToInt64(swingVolume);
            //=====================================================================================
            #endregion

            #region Visualize swing
            //=====================================================================================
            switch (swingProp.VisualizationType)
            {
                case VisualizationStyle.False:
                    break;
                case VisualizationStyle.Dots:
                    switch (swingLow.CurRelation)
                    {
                        case 1:
                            higherLow[CurrentBar - swingLow.CurBar] = swingLow.CurPrice;
                            break;
                        case -1:
                            lowerLow[CurrentBar - swingLow.CurBar] = swingLow.CurPrice;
                            break;
                        case 0:
                            doubleBottom[CurrentBar - swingLow.CurBar] = swingLow.CurPrice;
                            break;
                    }
                    break;
                case VisualizationStyle.Dots_ZigZag:
                    switch (swingLow.CurRelation)
                    {
                        case 1:
                            higherLow[CurrentBar - swingLow.CurBar] = swingLow.CurPrice;
                            break;
                        case -1:
                            lowerLow[CurrentBar - swingLow.CurBar] = swingLow.CurPrice;
                            break;
                        case 0:
                            doubleBottom[CurrentBar - swingLow.CurBar] = swingLow.CurPrice;
                            break;
                    }
                    Draw.Line(this, "ZigZagDown" + swingLow.Counter,
                        swingProp.UseAutoScale, CurrentBar - swingHigh.CurBar, swingHigh.CurPrice,
                        CurrentBar - swingLow.CurBar, swingLow.CurPrice, swingProp.ZigZagColorDn,
                        swingProp.ZigZagStyle, swingProp.ZigZagWidth, swingProp.DrawSwingsOnPricePanel);
                    break;
                case VisualizationStyle.ZigZag:
                    Draw.Line(this, "ZigZagDown" + swingLow.Counter,
                        swingProp.UseAutoScale, CurrentBar - swingHigh.CurBar, swingHigh.CurPrice,
                        CurrentBar - swingLow.CurBar, swingLow.CurPrice, swingProp.ZigZagColorDn,
                        swingProp.ZigZagStyle, swingProp.ZigZagWidth, swingProp.DrawSwingsOnPricePanel);
                    break;
                case VisualizationStyle.GannStyle:
                    for (int i = CurrentBar - swingCur.SwingSlopeChangeBar; i >= 0; i--)
                        gannSwing[i] = swingLow.CurPrice;
                    break;
                case VisualizationStyle.ZigZagVolume:
                    if (swingLow.CurVolume > swingHigh.CurVolume)
                        Draw.Line(this, "ZigZagDown" + swingLow.Counter,
                            swingProp.UseAutoScale, CurrentBar - swingHigh.CurBar,
                            swingHigh.CurPrice, CurrentBar - swingLow.CurBar, swingLow.CurPrice,
                            swingProp.ZigZagColorDn, swingProp.ZigZagStyle, swingProp.ZigZagWidth,
                            swingProp.DrawSwingsOnPricePanel);
                    else
                        Draw.Line(this, "ZigZagDown" + swingLow.Counter,
                            swingProp.UseAutoScale, CurrentBar - swingHigh.CurBar,
                            swingHigh.CurPrice, CurrentBar - swingLow.CurBar, swingLow.CurPrice,
                            swingProp.ZigZagColorUp, swingProp.ZigZagStyle, swingProp.ZigZagWidth,
                            swingProp.DrawSwingsOnPricePanel);
                    break;
            }
            //=====================================================================================
            #endregion

            #region Swing value output
            //=====================================================================================
            string output = "";
            switch (swingProp.SwingLengthType)
            {
                case SwingLengthStyle.False:
                    break;
                case SwingLengthStyle.Ticks:
                    output = swingLow.CurLength.ToString();
                    break;
                case SwingLengthStyle.Ticks_Price:
                    output = swingLow.CurLength.ToString() + " / " + swingLow.CurPrice.ToString();
                    break;
                case SwingLengthStyle.Price_Ticks:
                    output = swingLow.CurPrice.ToString() + " / " + swingLow.CurLength.ToString();
                    break;
                case SwingLengthStyle.Points:
                    output = (swingLow.CurLength * TickSize).ToString();
                    break;
                case SwingLengthStyle.Points_Price:
                    output = (swingLow.CurLength * TickSize).ToString() + " / " +
                        swingLow.CurPrice.ToString();
                    break;
                case SwingLengthStyle.Price_Points:
                    output = swingLow.CurPrice.ToString() + " / " +
                        (swingLow.CurLength * TickSize).ToString();
                    break;
                case SwingLengthStyle.Price:
                    output = swingLow.CurPrice.ToString();
                    break;
                case SwingLengthStyle.Percent:
                    output = (Math.Round((100.0 / swingHigh.CurPrice * (swingLow.CurLength *
                        TickSize)), 2, MidpointRounding.AwayFromZero)).ToString();
                    break;
            }
            string outputDuration = "";
            TimeSpan timeSpan;
            int hours, minutes, seconds = 0;
            switch (swingProp.SwingDurationType)
            {
                case SwingDurationStyle.False:
                    break;
                case SwingDurationStyle.Bars:
                    outputDuration = swingLow.CurDuration.ToString();
                    break;
                case SwingDurationStyle.MMSS:
                    timeSpan = swingLow.CurDateTime.Subtract(swingHigh.CurDateTime);
                    minutes = timeSpan.Minutes;
                    seconds = timeSpan.Seconds;
                    if (minutes == 0)
                        outputDuration = "0:" + seconds.ToString();
                    else if (seconds == 0)
                        outputDuration = minutes + ":00";
                    else
                        outputDuration = minutes + ":" + seconds;
                    break;
                case SwingDurationStyle.HHMM:
                    timeSpan = swingLow.CurDateTime.Subtract(swingHigh.CurDateTime);
                    hours = timeSpan.Hours;
                    minutes = timeSpan.Minutes;
                    if (hours == 0)
                        outputDuration = "0:" + minutes.ToString();
                    else if (minutes == 0)
                        outputDuration = hours + ":00";
                    else
                        outputDuration = hours + ":" + minutes;
                    break;
                case SwingDurationStyle.SecondsTotal:
                    timeSpan = swingLow.CurDateTime.Subtract(swingHigh.CurDateTime);
                    outputDuration = Math.Round(timeSpan.TotalSeconds, 1,
                        MidpointRounding.AwayFromZero).ToString();
                    break;
                case SwingDurationStyle.MinutesTotal:
                    timeSpan = swingLow.CurDateTime.Subtract(swingHigh.CurDateTime);
                    outputDuration = Math.Round(timeSpan.TotalMinutes, 1,
                        MidpointRounding.AwayFromZero).ToString();
                    break;
                case SwingDurationStyle.HoursTotal:
                    timeSpan = swingLow.CurDateTime.Subtract(swingHigh.CurDateTime);
                    outputDuration = timeSpan.TotalHours.ToString();
                    break;
                case SwingDurationStyle.Days:
                    timeSpan = swingLow.CurDateTime.Subtract(swingHigh.CurDateTime);
                    outputDuration = Math.Round(timeSpan.TotalDays, 1,
                        MidpointRounding.AwayFromZero).ToString();
                    break;
            }
            if (swingProp.SwingLengthType != SwingLengthStyle.False)
            {
                if (swingProp.SwingDurationType != SwingDurationStyle.False)
                    output = output + " / " + outputDuration;
            }
            else
                output = outputDuration;

            string swingLabel = null;
            Brush textColor = Brushes.Transparent;
            switch (swingLow.CurRelation)
            {
                case 1:
                    swingLabel = "HL";
                    textColor = swingProp.TextColorHigherLow;
                    break;
                case -1:
                    swingLabel = "LL";
                    textColor = swingProp.TextColorLowerLow;
                    break;
                case 0:
                    swingLabel = "DB";
                    textColor = swingProp.TextColorDoubleBottom;
                    break;
            }
            if (output != null)
                Draw.Text(this, "DnLength" + swingLow.Counter, swingProp.UseAutoScale,
                    output.ToString(), CurrentBar - swingLow.CurBar, swingLow.CurPrice,
                    -swingProp.TextOffsetLength, textColor, swingProp.TextFont,
                    TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
            if (swingProp.ShowSwingLabel)
                Draw.Text(this, "DnLabel" + swingLow.Counter, swingProp.UseAutoScale,
                    swingLabel, CurrentBar - swingLow.CurBar, swingLow.CurPrice,
                    -swingProp.TextOffsetLabel, textColor, swingProp.TextFont,
                    TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
            if (swingProp.ShowSwingPrice)
                Draw.Text(this, "DnPrice" + swingLow.Counter, swingProp.UseAutoScale,
                    String.Format("{0:F" + decimalPlaces + "}", swingLow.CurPrice),
                    CurrentBar - swingLow.CurBar, swingLow.CurPrice, -swingProp.TextOffsetPrice,
                    textColor, swingProp.TextFont, TextAlignment.Center, Brushes.Transparent,
                    Brushes.Transparent, 0);
            if (swingProp.ShowSwingPercent && swingLow.CurPercent != 0)
                Draw.Text(this, "DnPerc" + swingLow.Counter, swingProp.UseAutoScale,
                    String.Format("{0:F1}", swingLow.CurPercent) + "%", CurrentBar - swingLow.CurBar,
                    swingLow.CurPrice, -swingProp.TextOffsetPercent, textColor,
                    swingProp.TextFont, TextAlignment.Center, Brushes.Transparent,
                    Brushes.Transparent, 0);
            if (swingProp.SwingTimeType != SwingTimeStyle.False)
            {
                string timeOutput = "";
                switch (swingProp.SwingTimeType)
                {
                    case SwingTimeStyle.False:
                        break;
                    case SwingTimeStyle.Integer:
                        timeOutput = swingLow.CurTime.ToString();
                        break;
                    case SwingTimeStyle.HHMM:
                        timeOutput = string.Format("{0:t}",
                            Times[BarsInProgress][CurrentBars[BarsInProgress] - swingLow.CurBar]);
                        break;
                    case SwingTimeStyle.HHMMSS:
                        timeOutput = string.Format("{0:T}",
                            Times[BarsInProgress][CurrentBars[BarsInProgress] - swingLow.CurBar]);
                        break;
                    case SwingTimeStyle.DDMM:
                        timeOutput = string.Format("{0:dd.MM}",
                            Times[BarsInProgress][CurrentBars[BarsInProgress] - swingHigh.CurBar]);
                        break;
                }
                Draw.Text(this, "DnTime" + swingLow.Counter, swingProp.UseAutoScale,
                    timeOutput, CurrentBar - swingLow.CurBar, swingLow.CurPrice, -swingProp.TextOffsetTime,
                    textColor, swingProp.TextFont, TextAlignment.Center, Brushes.Transparent,
                    Brushes.Transparent, 0);
            }
            if (swingProp.SwingVolumeType != SwingVolumeStyle.False)
                Draw.Text(this, "DnVolume" + swingLow.Counter, swingProp.UseAutoScale,
                    TruncIntToStr(swingLow.CurVolume), CurrentBar - swingLow.CurBar,
                    swingLow.CurPrice, -swingProp.TextOffsetVolume, textColor, swingProp.TextFont,
                    TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
            //=====================================================================================
            #endregion

            SwingStruct dn = new SwingStruct(swingLow.CurPrice, swingLow.CurBar,
                swingLow.CurDateTime, swingLow.CurDuration, swingLow.CurLength,
                swingLow.CurRelation, swingLow.CurVolume);
            swingLows.Add(dn);
            swingLow.ListCount = swingLows.Count - 1;
        }
        //#########################################################################################
        #endregion

        #region Calculate up swing
        //#########################################################################################
        private void CalcUpSwing(int bar, double high, bool updateHigh, Swings swingHigh,
            Swings swingLow, SwingCurrent swingCur, SwingProperties swingProp, Series<bool> upFlip,
            List<SwingStruct> swingHighs, int decimalPlaces, Series<double> doubleBottom,
            Series<double> lowerLow, Series<double> higherLow, Series<double> doubleTop, Series<double> lowerHigh,
            Series<double> higherHigh, Series<double> gannSwing)
        {
            #region New and update swing values
            //=====================================================================================
            if (!updateHigh)
            {
                if (swingProp.VisualizationType == VisualizationStyle.GannStyle)
                {
                    for (int i = CurrentBar - swingCur.SwingSlopeChangeBar; i >= 0; i--)
                        gannSwing[i] = swingLow.CurPrice;
                    gannSwing[0] = high;
                }
                swingHigh.LastPrice = swingHigh.CurPrice;
                swingHigh.LastBar = swingHigh.CurBar;
                swingHigh.LastDateTime = swingHigh.CurDateTime;
                swingHigh.LastDuration = swingHigh.CurDuration;
                swingHigh.LastLength = swingHigh.CurLength;
                swingHigh.LastTime = swingHigh.CurTime;
                swingHigh.LastPercent = swingHigh.CurPercent;
                swingHigh.LastRelation = swingHigh.CurRelation;
                swingHigh.LastVolume = swingHigh.CurVolume;
                swingHigh.Counter++;
                swingCur.SwingSlope = 1;
                swingCur.SwingSlopeChangeBar = bar;
                upFlip[0] = true;
            }
            else
            {
                if (swingProp.VisualizationType == VisualizationStyle.Dots
                    || swingProp.VisualizationType == VisualizationStyle.Dots_ZigZag)
                {
                    doubleTop.Reset(CurrentBar - swingHigh.CurBar);
                    higherHigh.Reset(CurrentBar - swingHigh.CurBar);
                    lowerHigh.Reset(CurrentBar - swingHigh.CurBar);
                }
                swingHighs.RemoveAt(swingHighs.Count - 1);
            }
            swingHigh.CurBar = bar;
            swingHigh.CurPrice = Math.Round(high, decimalPlaces, MidpointRounding.AwayFromZero);
            swingHigh.CurTime = ToTime(Times[BarsInProgress][CurrentBars[BarsInProgress] -
                swingHigh.CurBar]);
            swingHigh.CurDateTime = Times[BarsInProgress][CurrentBars[BarsInProgress] -
                swingHigh.CurBar];
            swingHigh.CurLength = Convert.ToInt32(Math.Round((swingHigh.CurPrice -
                swingLow.CurPrice) / TickSize, 0, MidpointRounding.AwayFromZero));
            if (swingLow.CurLength != 0)
                swingHigh.CurPercent = Math.Round(100.0 / Math.Abs(swingLow.CurLength) *
                    swingHigh.CurLength, 1);
            swingHigh.CurDuration = swingHigh.CurBar - swingLow.CurBar;
            double dtbOffset = ATR(BarsArray[BarsInProgress], 14)[CurrentBars[BarsInProgress] -
                swingHigh.CurBar] * swingProp.DtbStrength / 100;
            if (swingHigh.CurPrice > swingHigh.LastPrice - dtbOffset && swingHigh.CurPrice <
                swingHigh.LastPrice + dtbOffset)
                swingHigh.CurRelation = 0;
            else if (swingHigh.CurPrice < swingHigh.LastPrice)
                swingHigh.CurRelation = -1;
            else
                swingHigh.CurRelation = 1;
            if (Calculate != Calculate.OnBarClose)
                swingLow.SignalBarVolume = Volumes[BarsInProgress][0];
            double swingVolume = 0.0;
            for (int i = 0; i < swingHigh.CurDuration; i++)
                swingVolume = swingVolume + Volumes[BarsInProgress][i];
            if (Calculate != Calculate.OnBarClose)
                swingVolume = swingVolume + (Volumes[BarsInProgress][CurrentBars[BarsInProgress] -
                    swingLow.CurBar] - swingHigh.SignalBarVolume);
            if (swingProp.SwingVolumeType == SwingVolumeStyle.Relative)
                swingVolume = Math.Round(swingVolume / swingHigh.CurDuration, 0,
                    MidpointRounding.AwayFromZero);
            swingHigh.CurVolume = Convert.ToInt64(swingVolume);
            //=====================================================================================
            #endregion

            #region Visualize swing
            //=====================================================================================
            switch (swingProp.VisualizationType)
            {
                case VisualizationStyle.False:
                    break;
                case VisualizationStyle.Dots:
                    switch (swingHigh.CurRelation)
                    {
                        case 1:
                            higherHigh[CurrentBar - swingHigh.CurBar] = swingHigh.CurPrice;
                            break;
                        case -1:
                            lowerHigh[CurrentBar - swingHigh.CurBar] = swingHigh.CurPrice;
                            break;
                        case 0:
                            doubleTop[CurrentBar - swingHigh.CurBar] = swingHigh.CurPrice;
                            break;
                    }
                    break;
                case VisualizationStyle.Dots_ZigZag:
                    switch (swingHigh.CurRelation)
                    {
                        case 1:
                            higherHigh[CurrentBar - swingHigh.CurBar] = swingHigh.CurPrice;
                            break;
                        case -1:
                            lowerHigh[CurrentBar - swingHigh.CurBar] = swingHigh.CurPrice;
                            break;
                        case 0:
                            doubleTop[CurrentBar - swingHigh.CurBar] = swingHigh.CurPrice;
                            break;
                    }
                    Draw.Line(this, "ZigZagUp" + swingHigh.Counter,
                        swingProp.UseAutoScale, CurrentBar - swingLow.CurBar, swingLow.CurPrice,
                        CurrentBar - swingHigh.CurBar, swingHigh.CurPrice, swingProp.ZigZagColorUp,
                        swingProp.ZigZagStyle, swingProp.ZigZagWidth);
                    break;
                case VisualizationStyle.ZigZag:
                    Draw.Line(this, "ZigZagUp" + swingHigh.Counter,
                        swingProp.UseAutoScale, CurrentBar - swingLow.CurBar, swingLow.CurPrice,
                        CurrentBar - swingHigh.CurBar, swingHigh.CurPrice, swingProp.ZigZagColorUp,
                        swingProp.ZigZagStyle, swingProp.ZigZagWidth);
                    break;
                case VisualizationStyle.GannStyle:
                    for (int i = CurrentBar - swingCur.SwingSlopeChangeBar; i >= 0; i--)
                        gannSwing[i] = swingHigh.CurPrice;
                    break;
                case VisualizationStyle.ZigZagVolume:
                    if (swingHigh.CurVolume > swingLow.CurVolume)
                        Draw.Line(this, "ZigZagUp" + swingHigh.Counter,
                            swingProp.UseAutoScale, CurrentBar - swingLow.CurBar,
                            swingLow.CurPrice, CurrentBar - swingHigh.CurBar, swingHigh.CurPrice,
                            swingProp.ZigZagColorUp, swingProp.ZigZagStyle, swingProp.ZigZagWidth);
                    else
                        Draw.Line(this, "ZigZagUp" + swingHigh.Counter,
                            swingProp.UseAutoScale, CurrentBar - swingLow.CurBar,
                            swingLow.CurPrice, CurrentBar - swingHigh.CurBar, swingHigh.CurPrice,
                            swingProp.ZigZagColorDn, swingProp.ZigZagStyle, swingProp.ZigZagWidth);
                    break;
            }
            //=====================================================================================
            #endregion

            #region Swing value output
            //=====================================================================================
            string output = "";
            switch (swingProp.SwingLengthType)
            {
                case SwingLengthStyle.False:
                    break;
                case SwingLengthStyle.Ticks:
                    output = swingHigh.CurLength.ToString();
                    break;
                case SwingLengthStyle.Ticks_Price:
                    output = swingHigh.CurLength.ToString() + " / " +
                        swingHigh.CurPrice.ToString();
                    break;
                case SwingLengthStyle.Price_Ticks:
                    output = swingHigh.CurPrice.ToString() + " / " +
                        swingHigh.CurLength.ToString();
                    break;
                case SwingLengthStyle.Points:
                    output = (swingHigh.CurLength * TickSize).ToString();
                    break;
                case SwingLengthStyle.Points_Price:
                    output = (swingHigh.CurLength * TickSize).ToString() + " / " +
                        swingHigh.CurPrice.ToString();
                    break;
                case SwingLengthStyle.Price_Points:
                    output = swingHigh.CurPrice.ToString() + " / " +
                        (swingHigh.CurLength * TickSize).ToString();
                    break;
                case SwingLengthStyle.Price:
                    output = swingHigh.CurPrice.ToString();
                    break;
                case SwingLengthStyle.Percent:
                    output = (Math.Round((100.0 / swingLow.CurPrice * (swingHigh.CurLength *
                        TickSize)), 2, MidpointRounding.AwayFromZero)).ToString();
                    break;
            }
            string outputDuration = "";
            TimeSpan timeSpan;
            int hours, minutes, seconds = 0;
            switch (swingProp.SwingDurationType)
            {
                case SwingDurationStyle.False:
                    break;
                case SwingDurationStyle.Bars:
                    outputDuration = swingHigh.CurDuration.ToString();
                    break;
                case SwingDurationStyle.MMSS:
                    timeSpan = swingHigh.CurDateTime.Subtract(swingLow.CurDateTime);
                    minutes = timeSpan.Minutes;
                    seconds = timeSpan.Seconds;
                    if (minutes == 0)
                        outputDuration = "0:" + seconds.ToString();
                    else if (seconds == 0)
                        outputDuration = minutes + ":00";
                    else
                        outputDuration = minutes + ":" + seconds;
                    break;
                case SwingDurationStyle.HHMM:
                    timeSpan = swingHigh.CurDateTime.Subtract(swingLow.CurDateTime);
                    hours = timeSpan.Hours;
                    minutes = timeSpan.Minutes;
                    if (hours == 0)
                        outputDuration = "0:" + minutes.ToString();
                    else if (minutes == 0)
                        outputDuration = hours + ":00";
                    else
                        outputDuration = hours + ":" + minutes;
                    break;
                case SwingDurationStyle.SecondsTotal:
                    timeSpan = swingHigh.CurDateTime.Subtract(swingLow.CurDateTime);
                    outputDuration = Math.Round(timeSpan.TotalSeconds, 1,
                        MidpointRounding.AwayFromZero).ToString();
                    break;
                case SwingDurationStyle.MinutesTotal:
                    timeSpan = swingHigh.CurDateTime.Subtract(swingLow.CurDateTime);
                    outputDuration = Math.Round(timeSpan.TotalMinutes, 1,
                        MidpointRounding.AwayFromZero).ToString();
                    break;
                case SwingDurationStyle.HoursTotal:
                    timeSpan = swingHigh.CurDateTime.Subtract(swingLow.CurDateTime);
                    outputDuration = Math.Round(timeSpan.TotalHours, 1,
                        MidpointRounding.AwayFromZero).ToString();
                    break;
                case SwingDurationStyle.Days:
                    timeSpan = swingHigh.CurDateTime.Subtract(swingLow.CurDateTime);
                    outputDuration = Math.Round(timeSpan.TotalDays, 1,
                        MidpointRounding.AwayFromZero).ToString();
                    break;
            }
            if (swingProp.SwingLengthType != SwingLengthStyle.False)
            {
                if (swingProp.SwingDurationType != SwingDurationStyle.False)
                    output = output + " / " + outputDuration;
            }
            else
                output = outputDuration;

            string swingLabel = null;
            Brush textColor = Brushes.Transparent;
            switch (swingHigh.CurRelation)
            {
                case 1:
                    swingLabel = "HH";
                    textColor = swingProp.TextColorHigherHigh;
                    break;
                case -1:
                    swingLabel = "LH";
                    textColor = swingProp.TextColorLowerHigh;
                    break;
                case 0:
                    swingLabel = "DT";
                    textColor = swingProp.TextColorDoubleTop;
                    break;
            }
            if (output != null)
                Draw.Text(this, "UpLength" + swingHigh.Counter,
                    swingProp.UseAutoScale, output.ToString(), CurrentBar - swingHigh.CurBar,
                    swingHigh.CurPrice, swingProp.TextOffsetLength + Convert.ToInt32(textFont.Size), textColor, swingProp.TextFont,
                    TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
            if (swingProp.ShowSwingLabel)
                Draw.Text(this, "UpLabel" + swingHigh.Counter, swingProp.UseAutoScale,
                    swingLabel, CurrentBar - swingHigh.CurBar, swingHigh.CurPrice,
                    swingProp.TextOffsetLabel + Convert.ToInt32(textFont.Size), textColor, swingProp.TextFont,
                    TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
            if (swingProp.ShowSwingPrice)
                Draw.Text(this, "UpPrice" + swingHigh.Counter, swingProp.UseAutoScale,
                    String.Format("{0:F" + decimalPlaces + "}", swingHigh.CurPrice),
                    CurrentBar - swingHigh.CurBar, swingHigh.CurPrice, swingProp.TextOffsetPrice + Convert.ToInt32(textFont.Size),
                    textColor, swingProp.TextFont, TextAlignment.Center, Brushes.Transparent,
                    Brushes.Transparent, 0);
            if (swingProp.ShowSwingPercent && swingHigh.CurPercent != 0)
                Draw.Text(this, "UpPerc" + swingHigh.Counter, swingProp.UseAutoScale,
                    String.Format("{0:F1}", swingHigh.CurPercent) + "%", CurrentBar - swingHigh.CurBar,
                    swingHigh.CurPrice, swingProp.TextOffsetPercent + Convert.ToInt32(textFont.Size), textColor, swingProp.TextFont,
                    TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
            if (swingProp.SwingTimeType != SwingTimeStyle.False)
            {
                string timeOutput = "";
                switch (swingProp.SwingTimeType)
                {
                    case SwingTimeStyle.False:
                        break;
                    case SwingTimeStyle.Integer:
                        timeOutput = swingHigh.CurTime.ToString();
                        break;
                    case SwingTimeStyle.HHMM:
                        timeOutput = string.Format("{0:t}",
                            Times[BarsInProgress][CurrentBars[BarsInProgress] - swingHigh.CurBar]);
                        break;
                    case SwingTimeStyle.HHMMSS:
                        timeOutput = string.Format("{0:T}",
                            Times[BarsInProgress][CurrentBars[BarsInProgress] - swingHigh.CurBar]);
                        break;
                    case SwingTimeStyle.DDMM:
                        timeOutput = string.Format("{0:dd.MM}",
                            Times[BarsInProgress][CurrentBars[BarsInProgress] - swingHigh.CurBar]);
                        break;
                }
                Draw.Text(this, "UpTime" + swingHigh.Counter, swingProp.UseAutoScale,
                    timeOutput, CurrentBar - swingHigh.CurBar, swingHigh.CurPrice,
                    swingProp.TextOffsetTime+ Convert.ToInt32(textFont.Size), textColor, swingProp.TextFont,
                    TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
            }
            if (swingProp.SwingVolumeType != SwingVolumeStyle.False)
                Draw.Text(this, "UpVolume" + swingHigh.Counter, swingProp.UseAutoScale,
                    TruncIntToStr(swingHigh.CurVolume), CurrentBar - swingHigh.CurBar,
                    swingHigh.CurPrice, swingProp.TextOffsetVolume + Convert.ToInt32(textFont.Size), textColor, swingProp.TextFont,
                    TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
            //=========================================================================================
            #endregion

            SwingStruct up = new SwingStruct(swingHigh.CurPrice, swingHigh.CurBar,
                swingHigh.CurDateTime, swingHigh.CurDuration, swingHigh.CurLength,
                swingHigh.CurRelation, swingHigh.CurVolume);
            swingHighs.Add(up);
            swingHigh.ListCount = swingHighs.Count - 1;
        }
        //#########################################################################################
        #endregion

        #region Trunc integer to string
        //#########################################################################################
        /// <summary>
        /// Converts long integer numbers in a number-string format.
        /// </summary>
        protected string TruncIntToStr(long number)
        {
            long numberAbs = Math.Abs(number);
            string output = "";
            double convertedNumber = 0.0;
            if (numberAbs > 1000000000)
            {
                convertedNumber = Math.Round(number / 1000000000.0, 1,
                    MidpointRounding.AwayFromZero);
                output = convertedNumber.ToString() + "B";
            }
            else if (numberAbs > 1000000)
            {
                convertedNumber = Math.Round(number / 1000000.0, 1,
                    MidpointRounding.AwayFromZero);
                output = convertedNumber.ToString() + "M";
            }
            else if (numberAbs > 1000)
            {
                convertedNumber = Math.Round(number / 1000.0, 1,
                    MidpointRounding.AwayFromZero);
                output = convertedNumber.ToString() + "K";
            }
            else
                output = number.ToString();

            return output;
        }
        //#########################################################################################
        #endregion
     
        #region Properties
     
        #region Plots
        // Plots ==================================================================================
        [Browsable(false)]
        [XmlIgnore]
        public Series<double> DoubleBottom
        {
            get { return Values[0]; }
        }
        [Browsable(false)]
        [XmlIgnore]
        public Series<double> LowerLow
        {
            get { return Values[1]; }
        }
        [Browsable(false)]
        [XmlIgnore]
        public Series<double> HigherLow
        {
            get { return Values[2]; }
        }
        [Browsable(false)]
        [XmlIgnore]
        public Series<double> DoubleTop
        {
            get { return Values[3]; }
        }
        [Browsable(false)]
        [XmlIgnore]
        public Series<double> LowerHigh
        {
            get { return Values[4]; }
        }
        [Browsable(false)]
        [XmlIgnore]
        public Series<double> HigherHigh
        {
            get { return Values[5]; }
        }
        [Browsable(false)]
        [XmlIgnore]
        public Series<double> GannSwing
        {
            get { return Values[6]; }
        }
        //=========================================================================================
        #endregion

        #region Parameters
        //=========================================================================================    
        [NinjaScriptProperty]
        [Display(Name="Swing type", Description="Represents the swing type for the swings.", Order=1, GroupName="Parameters")]
        public SwingStyle SwingType
        { get; set; }
     
        [Range(0.00000001, double.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name="Swing size", Description="Represents the swing size. e.g. 1 = small swings and 5 = bigger swings.", Order=2, GroupName="Parameters")]
        public double SwingSize
        { get; set; }
     
        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name="Double top/-bottom strength", Description="Represents the double top/-bottom strength. Increase the value to get more DB/DT.", Order=3, GroupName="Parameters")]
        public int DtbStrength
        { get; set; }
     
        [NinjaScriptProperty]
        [Display(Name="Use close values", Description="Indicates if high and low prices are used for the swing calculations or close values.", Order=4, GroupName="Parameters")]
        public bool UseCloseValues
        { get; set; }
        //=========================================================================================
        #endregion

        #region Swing features
        //=========================================================================================
        [NinjaScriptProperty]
        [Display(Name="ABC Pattern", Description="Indicates if and for which direction AB=CD patterns are computed." , Order=1, GroupName="0. Features")]
        public AbcPatternMode AbcPattern
        {
            get { return abcPattern; }
            set { abcPattern = value; }
        }
//        [NinjaScriptProperty]
//        [Display(Name="ABC target in percent", Description="Indicates the target in percent of the AB range for the AB=CD pattern for the risk management." , Order=2, GroupName="0. Features")]
//        public double AbcTarget
//        {
//            get { return abcTarget; }
//            set { abcTarget = Math.Max(1.0, value); }
//        }
        [NinjaScriptProperty]
        [Display(Name="Divergence indicator", Description="Represents the indicator for the divergence calculations." , Order=3, GroupName="0. Features")]
        public DivergenceMode DivergenceIndicatorMode
        {
            get { return divergenceMode; }
            set { divergenceMode = value; }
        }
        [NinjaScriptProperty]
        [Display(Name="Divergence long and short", Description="Represents the direction the divergences are calculated for." , Order=4, GroupName="0. Features")]
        public DivergenceDirection DivergenceDirectionMode
        {
            get { return divergenceDirection; }
            set { divergenceDirection = value; }
        }
        [NinjaScriptProperty]
        [Display(Name="Divergence Parameter 1", Description="Represents the first parameter for the indicator choosen in 'Divergence indicator'." , Order=5, GroupName="0. Features")]
        public int Param1
        {
            get { return param1; }
            set { param1 = Math.Max(1, value); }
        }
        [NinjaScriptProperty]
        [Display(Name="Divergence Parameter 2", Description="Represents the first parameter for the indicator choosen in 'Divergence indicator'." , Order=6, GroupName="0. Features")]
        public int Param2
        {
            get { return param2; }
            set { param2 = Math.Max(1, value); }
        }
        [NinjaScriptProperty]
        [Display(Name="Divergence Parameter 3", Description="Represents the first parameter for the indicator choosen in 'Divergence indicator'." , Order=7, GroupName="0. Features")]
        public int Param3
        {
            get { return param3; }
            set { param3 = Math.Max(1, value); }
        }
        [NinjaScriptProperty]
        [Display(Name="Naked swing lines", Description="Indicates if naked swing lines are shown." , Order=8, GroupName="0. Features")]
        public bool ShowNakedSwings
        {
            get { return showNakedSwings; }
            set { showNakedSwings = value; }
        }
//        [NinjaScriptProperty]
//        [Display(Name="Statistic", Description="Indicates if and where a swing statistic is shown." , Order=9, GroupName="0. Features")]
//        public StatisticPositionStyle StatisticPosition
//        {
//            get { return statisticPosition; }
//            set { statisticPosition = value; }
//        }
//        [NinjaScriptProperty]
//        [Display(Name="Statistic number of swings", Description="Indicates the number of swings which are used for the current swing statistic." , Order=10, GroupName="0. Features")]
//        public int StatisticLength
//        {
//            get { return statisticLength; }
//            set { statisticLength = Math.Max(1, value); }
//        }
//        [NinjaScriptProperty]
//        [Display(Name="Risk management", Description="Indicates if the risk management tools are shown. If ABC pattern is on, it calculates the risk reward ratio and the trade quantity." , Order=11, GroupName="0. Features")]
//        public RiskManagementStyle RiskManagementPosition
//        {
//            get { return riskManagementPosition; }
//            set { riskManagementPosition = value; }
//        }
//        [NinjaScriptProperty]
//        [Display(Name="RM long stop in ticks", Description="Indicates the number of ticks for a long stop. Used to get the current values when the risk management buttons are clicked." , Order=12, GroupName="0. Features")]
//        public int RiskLongStopInTicks
//        {
//            get { return riskLongStopInTicks; }
//            set { riskLongStopInTicks = Math.Max(1, value); }
//        }
//        [NinjaScriptProperty]
//        [Display(Name="RM long target in ticks", Description="Indicates the number of ticks for a long target. Used to get the current values when the risk management buttons are clicked." , Order=13, GroupName="0. Features")]
//        public int RiskLongTargetInTicks
//        {
//            get { return riskLongTargetInTicks; }
//            set { riskLongTargetInTicks = Math.Max(1, value); }
//        }
//        [NinjaScriptProperty]
//        [Display(Name="RM short stop in ticks", Description="Indicates the number of ticks for a short stop. Used to get the current values when the risk management buttons are clicked." , Order=14, GroupName="0. Features")]
//        public int RiskShortStopInTicks
//        {
//            get { return riskShortStopInTicks; }
//            set { riskShortStopInTicks = Math.Max(1, value); }
//        }
//        [NinjaScriptProperty]
//        [Display(Name="RM short target in ticks", Description="Indicates the number of ticks for a short target. Used to get the current values when the risk management buttons are clicked." , Order=15, GroupName="0. Features")]
//        public int RiskShortTargetInTicks
//        {
//            get { return riskShortTargetInTicks; }
//            set { riskShortTargetInTicks = Math.Max(1, value); }
//        }
//        [NinjaScriptProperty]
//        [Display(Name="Account size", Description="Represents the account size from which the quantity for a trade is calculated based on the account risk." , Order=16, GroupName="0. Features")]
//        public double AccountSize
//        {
//            get { return accountSize; }
//            set { accountSize = Math.Max(1.0, value); }
//        }
//        [NinjaScriptProperty]
//        [Display(Name="Account risk per trade", Description="Represents the percentage of the account size which is risked for each trade." , Order=17, GroupName="0. Features")]
//        public double AccountRisk
//        {
//            get { return accountRisk; }
//            set { accountRisk = Math.Max(0.001, value); }
//        }
        [NinjaScriptProperty]
        [Display(Name="Swing extensions", Description="Indicates if a swing extension is drawn on the chart." , Order=18, GroupName="0. Features")]
           public bool AddSwingExtension
        {
            get { return addSwingExtension; }
            set { addSwingExtension = value; }
        }
        [NinjaScriptProperty]
        [Display(Name="Swing retracement (current)", Description="Indicates if a swing retracement is drawn on the chart for the current swing." , Order=19, GroupName="0. Features")]
        public bool AddSwingRetracementFast
        {
            get { return addSwingRetracementFast; }
            set { addSwingRetracementFast = value; }
        }
        [NinjaScriptProperty]
        [Display(Name="Swing retracement (last)", Description="Indicates if a swing retracement is drawn on the chart for the last swing." , Order=20, GroupName="0. Features")]
        public bool AddSwingRetracementSlow
        {
            get { return addSwingRetracementSlow; }
            set { addSwingRetracementSlow = value; }
        }
        //=========================================================================================
        #endregion

        #region Swings Values
        //=========================================================================================
        [NinjaScriptProperty]
        [Display(Name = "Length", Description = "Represents the swing length visualization type for the swings.", Order = 1, GroupName = "1. Swing Values")]
        public SwingLengthStyle SwingLengthType
        {
            get { return swingLengthType; }
            set { swingLengthType = value; }
        }

        [NinjaScriptProperty]
        [Display(Name = "Duration", Description = "Represents the swing duration visualization type for the swings.", Order = 2, GroupName = "1. Swing Values")]
        public SwingDurationStyle SwingDurationType
        {
            get { return swingDurationType; }
            set { swingDurationType = value; }
        }

        [NinjaScriptProperty]
        [Display(Name = "Show Price", Description = "Indicates if the swing price is shown for the swings.", Order = 3, GroupName = "1. Swing Values")]
        public bool ShowSwingPrice
        {
            get { return showSwingPrice; }
            set { showSwingPrice = value; }
        }

        [NinjaScriptProperty]
        [Display(Name = "Show Labels", Description = "Indicates if the swing label is shown (HH, HL, LL, LH, DB, DT).", Order = 4, GroupName = "1. Swing Values")]
        public bool ShowSwingLabel
        {
            get { return showSwingLabel; }
            set { showSwingLabel = value; }
        }

        [NinjaScriptProperty]
        [Display(Name = "Percentage", Description = "Indicates if the swing percentage in relation to the last swing is shown.", Order = 5, GroupName = "1. Swing Values")]
        public bool ShowSwingPercent
        {
            get { return showSwingPercent; }
            set { showSwingPercent = value; }
        }

        [NinjaScriptProperty]
        [Display(Name = "Time", Description = "Represents the swing time visualization type for the swings.", Order = 6, GroupName = "1. Swing Values")]
        public SwingTimeStyle SwingTimeType
        {
            get { return swingTimeType; }
            set { swingTimeType = value; }
        }

        [NinjaScriptProperty]
        [Display(Name = "Volume", Description = "Represents the swing volume visualization type for the swings.", Order = 7, GroupName = "1. Swing Values")]
        public SwingVolumeStyle SwingVolumeType
        {
            get { return swingVolumeType; }
            set { swingVolumeType = value; }
        }
        //=========================================================================================
        #endregion

        #region Visualize Swings
        //=========================================================================================
        [NinjaScriptProperty]
        [Display(Name = "Visualization Type", Description = "Represents the swing visualization type for the swings.", Order = 1, GroupName = "2. Visualize Swings")]
        public VisualizationStyle VisualizationType
        {
            get { return visualizationType; }
            set { visualizationType = value; }
        }

        [NinjaScriptProperty]
        [Display(Name = "Text Font", Description = "Represents the text font for the swing value output.", Order = 2, GroupName = "2. Visualize Swings")]
        public NinjaTrader.Gui.Tools.SimpleFont TextFont
        {
            get { return textFont; }
            set { textFont = value; }
        }

        [XmlIgnore]
        [Display(Name = "Text Color Higher High", Description = "Represents the color of the swing value output for higher highs.", Order = 3, GroupName = "2. Visualize Swings")]
        public Brush TextColorHigherHigh
        {
            get { return textColorHigherHigh; }
            set { textColorHigherHigh = value; }
        }

        [Browsable(false)]
        public string TextColorHigherHighSerializable
        {
            get { return Serialize.BrushToString(textColorHigherHigh); }
            set { textColorHigherHigh = Serialize.StringToBrush(value); }
        }

        [XmlIgnore]
        [Display(Name = "Text Color Lower High", Description = "Represents the color of the swing value output for lower highs.", Order = 4, GroupName = "2. Visualize Swings")]
        public Brush TextColorLowerHigh
        {
            get { return textColorLowerHigh; }
            set { textColorLowerHigh = value; }
        }
        [Browsable(false)]
        public string TextColorLowerHighSerializable
        {
            get { return Serialize.BrushToString(textColorLowerHigh); }
            set { textColorLowerHigh = Serialize.StringToBrush(value); }
        }

        [XmlIgnore]
        [Display(Name = "Text Color Double Top", Description = "Represents the color of the swing value output for double tops.", Order = 5, GroupName = "2. Visualize Swings")]
        public Brush TextColorDoubleTop
        {
            get { return textColorDoubleTop; }
            set { textColorDoubleTop = value; }
        }
        [Browsable(false)]
        public string TextColorDoubleTopSerializable
        {
            get { return Serialize.BrushToString(textColorDoubleTop); }
            set { textColorDoubleTop = Serialize.StringToBrush(value); }
        }

        [XmlIgnore]
        [Display(Name = "Text Color Higher Low", Description = "Represents the color of the swing value output for higher lows.", Order = 6, GroupName = "2. Visualize Swings")]
        public Brush TextColorHigherLow
        {
            get { return textColorHigherLow; }
            set { textColorHigherLow = value; }
        }
        [Browsable(false)]
        public string TextColorHigherLowSerializable
        {
            get { return Serialize.BrushToString(textColorHigherLow); }
            set { textColorHigherLow = Serialize.StringToBrush(value); }
        }

        [XmlIgnore]
        [Display(Name = "Text Color Lower Low", Description = "Represents the color of the swing value output for lower lows.", Order = 7, GroupName = "2. Visualize Swings")]
        public Brush TextColorLowerLow
        {
            get { return textColorLowerLow; }
            set { textColorLowerLow = value; }
        }
        [Browsable(false)]
        public string TextColorLowerLowSerializable
        {
            get { return Serialize.BrushToString(textColorLowerLow); }
            set { textColorLowerLow = Serialize.StringToBrush(value); }
        }

        [XmlIgnore]
        [Display(Name = "Text Color Double Bottom", Description = "Represents the color of the swing value output for double bottoms.", Order = 8, GroupName = "2. Visualize Swings")]
        public Brush TextColorDoubleBottom
        {
            get { return textColorDoubleBottom; }
            set { textColorDoubleBottom = value; }
        }
        [Browsable(false)]
        public string TextColorDoubleBottomSerializable
        {
            get { return Serialize.BrushToString(textColorDoubleBottom); }
            set { textColorDoubleBottom = Serialize.StringToBrush(value); }
        }

        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "Text Offset Length/Duration", Description = "Represents the text offset in pixel for the swing length/duration.", Order = 9, GroupName = "2. Visualize Swings")]
        public int TextOffsetLength
        {
            get { return textOffsetLength; }
            set { textOffsetLength = Math.Max(1, value); }
        }

        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "Text Offset Volume", Description = "Represents the text offset in pixel for the swing volume.", Order = 10, GroupName = "2. Visualize Swings")]
        public int TextOffsetVolume
        {
            get { return textOffsetVolume; }
            set { textOffsetVolume = Math.Max(1, value); }
        }

        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "Text Offset Price", Description = "Represents the text offset in pixel for the swing price for the swings.", Order = 11, GroupName = "2. Visualize Swings")]
        public int TextOffsetPrice
        {
            get { return textOffsetPrice; }
            set { textOffsetPrice = Math.Max(1, value); }
        }

        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "Text Offset Swing Labels", Description = "Represents the text offset in pixel for the swing labels.", Order = 12, GroupName = "2. Visualize Swings")]
        public int TextOffsetLabel
        {
            get { return textOffsetLabel; }
            set { textOffsetLabel = Math.Max(1, value); }
        }

        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "Text Offset Time", Description = "Represents the text offset in pixel for the time value.", Order = 13, GroupName = "2. Visualize Swings")]
        public int TextOffsetTime
        {
            get { return textOffsetTime; }
            set { textOffsetTime = Math.Max(1, value); }
        }

        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "Text Offset Percent", Description = "Represents the text offset in pixel for the retracement value.", Order = 14, GroupName = "2. Visualize Swings")]
        public int TextOffsetPercent
        {
            get { return textOffsetPercent; }
            set { textOffsetPercent = Math.Max(1, value); }
        }

        [XmlIgnore]
        [Display(Name = "Zig-Zag Color Up", Description = "Represents the color of the zig-zag up lines.", Order = 15, GroupName = "2. Visualize Swings")]
        public Brush ZigZagColorUp
        {
            get { return zigZagColorUp; }
            set { zigZagColorUp = value; }
        }
        [Browsable(false)]
        public string ZigZagColorUpSerializable
        {
            get { return Serialize.BrushToString(zigZagColorUp); }
            set { zigZagColorUp = Serialize.StringToBrush(value); }
        }

        [XmlIgnore]
        [Display(Name = "Zig-Zag Color Down", Description = "Represents the color of the zig-zag down lines.", Order = 16, GroupName = "2. Visualize Swings")]
        public Brush ZigZagColorDn
        {
            get { return zigZagColorDn; }
            set { zigZagColorDn = value; }
        }
        [Browsable(false)]
        public string ZigZagColorDnSerializable
        {
            get { return Serialize.BrushToString(zigZagColorDn); }
            set { zigZagColorDn = Serialize.StringToBrush(value); }
        }

        [NinjaScriptProperty]
        [Display(Name = "Zig-Zag Style", Description = "Represents the line style of the zig-zag lines.", Order = 17, GroupName = "2. Visualize Swings")]
        public DashStyleHelper ZigZagStyle
        {
            get { return zigZagStyle; }
            set { zigZagStyle = value; }
        }

        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "Zig-Zag Width", Description = "Represents the line width of the zig-zag lines.", Order = 18, GroupName = "2. Visualize Swings")]
        public int ZigZagWidth
        {
            get { return zigZagWidth; }
            set { zigZagWidth = Math.Max(1, value); }
        }
        [NinjaScriptProperty]
        [Display(Name = "Swing switch", Description = "Indicates if the change from down to up or up to down swings is indicated on the chart for the swings.", Order = 18, GroupName = "2. Visualize Swings")]
        public bool ShowSwingSwitch
        {
            get { return showSwingSwitch; }
            set { showSwingSwitch = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "Swing switch offset in ticks", Description = "Represents the offset in ticks for the swing switch triangles.", Order = 20, GroupName = "2. Visualize Swings")]
        public int SwingSwitchOffsetInTicks
        {
            get { return swingSwitchOffsetInTicks; }
            set { swingSwitchOffsetInTicks = value; }
        }
     
        [XmlIgnore]
        [Display(Name = "Swing switch down color", Description = "Represents the color of the swing switch down triangle.", Order = 21, GroupName = "2. Visualize Swings")]
        public Brush SwingSwitchDownColor
        {
            get { return swingSwitchDownColor; }
            set { swingSwitchDownColor = value; }
        }
        [Browsable(false)]
        public string SwingSwitchDownColorSerialize
        {
            get { return Serialize.BrushToString(swingSwitchDownColor); }
            set { swingSwitchDownColor = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(Name = "Swing switch up color", Description = "Represents the color of the swing switch up triangle.", Order = 22, GroupName = "2. Visualize Swings")]
        public Brush SwingSwitchUpColor
        {
            get { return swingSwitchUpColor; }
            set { swingSwitchUpColor = value; }
        }
        [Browsable(false)]
        public string SwingSwitchUpColorSerialize
        {
            get { return Serialize.BrushToString(swingSwitchUpColor); }
            set { swingSwitchUpColor = Serialize.StringToBrush(value); }
        }
        //=========================================================================================
        #endregion

        #region ABC visualization
        //=====================================================================
        [NinjaScriptProperty]
        [Display(Name="Line style", Description="Represents the line style for pattern lines.", Order = 1, GroupName = "4. ABC Visualization")]
        public DashStyleHelper AbcLineStyle
        {
            get { return abcLineStyle; }
            set { abcLineStyle = value; }
        }
        [NinjaScriptProperty]
        [Display(Name="Line style ratio", Description="Represents the line style for pattern ratio lines.", Order = 2, GroupName = "4. ABC Visualization")]
        public DashStyleHelper AbcLineStyleRatio
        {
            get { return abcLineStyleRatio; }
            set { abcLineStyleRatio = value; }
        }
        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name="Line width", Description="Represents the line width for pattern lines.", Order = 3, GroupName = "4. ABC Visualization")]
        public int AbcLineWidth
        {
            get { return abcLineWidth; }
            set { abcLineWidth = Math.Max(1, value); }
        }
        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name="Line width ratio", Description="Represents the line width for pattern ratio lines.", Order = 4, GroupName = "4. ABC Visualization")]
        public int AbcLineWidthRatio
        {
            get { return abcLineWidthRatio; }
            set { abcLineWidthRatio = Math.Max(1, value); }
        }
        [XmlIgnore()]
        [NinjaScriptProperty]
        [Display(Name="Text font", Description="Represents the text font for the displayed swing information.", Order = 5, GroupName = "4. ABC Visualization")]
        public NinjaTrader.Gui.Tools.SimpleFont AbcTextFont
        {
            get { return abcTextFont; }
            set { abcTextFont = value; }
        }
        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name="Text offset label", Description="Represents the offset value in pixels from within the text box area that display the swing label.", Order = 6, GroupName = "4. ABC Visualization")]
        public int AbcTextOffsetLabel
        {
            get { return abcTextOffsetLabel; }
            set { abcTextOffsetLabel = Math.Max(1, value); }
        }
     
        [XmlIgnore]
        [Display(Name="Text color down", Description="Represents the text color for down patterns.", Order = 7, GroupName = "4. ABC Visualization")]
        public Brush AbcTextColorDn
        {
            get { return abcTextColorDn; }
            set { abcTextColorDn = value; }
        }
        [Browsable(false)]
        public string AbcTextColorDnSerialize
        {
            get { return Serialize.BrushToString(abcTextColorDn); }
            set { abcTextColorDn = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(Name="Text color up", Description="Represents the text color for up patterns.", Order = 8, GroupName = "4. ABC Visualization")]
        public Brush AbcTextColorUp
        {
            get { return abcTextColorUp; }
            set { abcTextColorUp = value; }
        }
        [Browsable(false)]
        public string AbcTextColorUpSerialize
        {
            get { return Serialize.BrushToString(abcTextColorUp); }
            set { abcTextColorUp = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(Name="Line color down", Description="Represents the line color for down patterns.", Order = 9, GroupName = "4. ABC Visualization")]
        public Brush AbcZigZagColorDn
        {
            get { return abcZigZagColorDn; }
            set { abcZigZagColorDn = value; }
        }
        [Browsable(false)]
        public string AbcZigZagColorDnSerialize
        {
            get { return Serialize.BrushToString(abcZigZagColorDn); }
            set { abcZigZagColorDn = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(Name="Line color up", Description="Represents the line color for up patterns.", Order = 10, GroupName = "4. ABC Visualization")]
        public Brush AbcZigZagColorUp
        {
            get { return abcZigZagColorUp; }
            set { abcZigZagColorUp = value; }
        }
        [Browsable(false)]
        public string AbcZigZagColorUpSerialize
        {
            get { return Serialize.BrushToString(abcZigZagColorUp); }
            set { abcZigZagColorUp = Serialize.StringToBrush(value); }
        }
        [Range(1, 99)]
        [NinjaScriptProperty]
        [Display(Name="Retracement maximum (percent)", Description="Represents the maximum value in percent for a retracement in relation to the last swing. The price must retrace between this two values, otherwise the pattern is not valid.", Order = 11, GroupName = "4. ABC Visualization")]
        public double AbcMaxRetracement
        {
            get { return abcMaxRetracement; }
            set { abcMaxRetracement = Math.Max(1, Math.Min(99, value)); }
        }
        [Range(1, 99)]
        [NinjaScriptProperty]
        [Display(Name="Retracement minimum (percent)", Description="Represents the minimum value in percent for a retracement in relation to the last swing. The price must retrace between this two values, otherwise the pattern is not valid.", Order = 12, GroupName = "4. ABC Visualization")]
        public double AbcMinRetracement
        {
            get { return abcMinRetracement; }
            set { abcMinRetracement = Math.Max(1, Math.Min(99, value)); }
        }
     
        [XmlIgnore]
        [Display(Name="Entry line color down", Description="Represents the entry line color for down patterns.", Order = 13, GroupName = "4. ABC Visualization")]
        public Brush EntryLineColorDn
        {
            get { return entryLineColorDn; }
            set { entryLineColorDn = value; }
        }
        [Browsable(false)]
        public string EntryLineColorDnSerialize
        {
            get { return Serialize.BrushToString(entryLineColorDn); }
            set { entryLineColorDn = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(Name="Entry line color up", Description="Represents the entry line color for up patterns.", Order = 14, GroupName = "4. ABC Visualization")]
        public Brush EntryLineColorUp
        {
            get { return entryLineColorUp; }
            set { entryLineColorUp = value; }
        }
        [Browsable(false)]
        public string EntryLineColorUpSerialize
        {
            get { return Serialize.BrushToString(entryLineColorUp); }
            set { entryLineColorUp = Serialize.StringToBrush(value); }
        }
        [NinjaScriptProperty]
        [Display(Name="Entry line style", Description="Represents the line style for the entry lines.", Order = 15, GroupName = "4. ABC Visualization")]
        public DashStyleHelper EntryLineStyle
        {
            get { return entryLineStyle; }
            set { entryLineStyle = value; }
        }
        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name="Entry line width", Description="Represents the line width for pattern lines.", Order = 16, GroupName = "4. ABC Visualization")]
        public int EntryLineWidth
        {
            get { return entryLineWidth; }
            set { entryLineWidth = Math.Max(1, value); }
        }
        [NinjaScriptProperty]
        [Display(Name="Entry retracement", Description="If bar close above/below the entry retracement an entry is triggered.", Order = 17, GroupName = "4. ABC Visualization")]
        public double RetracementEntryValue
        {
            get { return retracementEntryValue; }
            set { retracementEntryValue = Math.Max(1.0, Math.Min(99.0, value)); }
        }
        [NinjaScriptProperty]
        [Display(Name="Entry arrows", Description="Indicates if entry arrows are displayed.", Order = 18, GroupName = "4. ABC Visualization")]
        public bool ShowEntryArrows
        {
            get { return showEntryArrows; }
            set { showEntryArrows = value; }
        }
        [NinjaScriptProperty]
        [Display(Name="Entry line historical", Description="Indicates if historical entry lines are displayed.", Order = 19, GroupName = "4. ABC Visualization")]
        public bool ShowHistoricalEntryLine
        {
            get { return showHistoricalEntryLine; }
            set { showHistoricalEntryLine = value; }
        }
        [Range(0, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name="Entry arrows offset (ticks)", Description="Represents the offset value in ticks from the high/low that triggered the entry.", Order = 20, GroupName = "4. ABC Visualization")]
        public int YTickOffset
        {
            get { return yTickOffset; }
            set { yTickOffset = Math.Max(0, value); }
        }
        //=====================================================================
        #endregion

        #region Divergence Visualization
        //=========================================================================================
        [NinjaScriptProperty]
        [Display(Name="Show regular divergence", Description="Indicates if regalur divergence is shown.", Order = 1, GroupName = "5. Divergence Visualization")]
        public bool ShowDivergenceRegular
        {
            get { return showDivergenceRegular; }
            set { showDivergenceRegular = value; }
        }
        [NinjaScriptProperty]
        [Display(Name="Show hidden divergence", Description="Indicates if hidden divergence is shown.", Order = 2, GroupName = "5. Divergence Visualization")]
        public bool ShowDivergenceHidden
        {
            get { return showDivergenceHidden; }
            set { showDivergenceHidden = value; }
        }
        [NinjaScriptProperty]
        [Display(Name="Down line style", Description="Represents the line style for down divergence.", Order = 3, GroupName = "5. Divergence Visualization")]
        public DashStyleHelper DivDnLineStyle
        {
            get { return divDnLineStyle; }
            set { divDnLineStyle = value; }
        }
        [NinjaScriptProperty]
        [Display(Name="Up line style", Description="Represents the line style for hidden divergence.", Order = 4, GroupName = "5. Divergence Visualization")]
        public DashStyleHelper DivUpLineStyle
        {
            get { return divUpLineStyle; }
            set { divUpLineStyle = value; }
        }
        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name="Down line width", Description="Represents the line width for regular divergence.", Order = 5, GroupName = "5. Divergence Visualization")]
        public int DivDnLineWidth
        {
            get { return divDnLineWidth; }
            set { divDnLineWidth = Math.Max(1, value); }
        }
        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name="Up line widt", Description="Represents the line width for hidden divergence.", Order = 6, GroupName = "5. Divergence Visualization")]
        public int DivUpLineWidth
        {
            get { return divUpLineWidth; }
            set { divUpLineWidth = Math.Max(1, value); }
        }
     
        [XmlIgnore]
        [Display(Name="Down text color", Description="Represents the text color for regular divergence.", Order = 7, GroupName = "5. Divergence Visualization")]
        public Brush DivDnLineColor
        {
            get { return divDnLineColor; }
            set { divDnLineColor = value; }
        }
        [Browsable(false)]
        public string DivDnLineColorSerialize
        {
            get { return Serialize.BrushToString(divDnLineColor); }
            set { divDnLineColor = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(Name="Up text color", Description="Represents the text color for hidden divergence.", Order = 8, GroupName = "5. Divergence Visualization")]
        public Brush DivUpLineColor
        {
            get { return divUpLineColor; }
            set { divUpLineColor = value; }
        }
        [Browsable(false)]
        public string DivUpLineColorSerialize
        {
            get { return Serialize.BrushToString(divUpLineColor); }
            set { divUpLineColor = Serialize.StringToBrush(value); }
        }
        //=========================================================================================
        #endregion

        #region Naked swings visualization
        //=========================================================================================
        [NinjaScriptProperty]
        [Display(Name="Show historical naked swing lines", Description="Indicates if historical naked swing lines are shown.", Order = 1, GroupName = "6. Naked swings")]
        public bool ShowHistoricalNakedSwings
        {
            get { return showHistoricalNakedSwings; }
            set { showHistoricalNakedSwings = value; }
        }
     
        [XmlIgnore]
        [Display(Name="Naked swing high color", Description="Represents the color of the naked swing high lines.", Order = 2, GroupName = "6. Naked swings")]
        public Brush NakedSwingHighColor
        {
            get { return nakedSwingHighColor; }
            set { nakedSwingHighColor = value; }
        }
        [Browsable(false)]
        public string NakedSwingHighColorSerialize
        {
            get { return Serialize.BrushToString(nakedSwingHighColor); }
            set { nakedSwingHighColor = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(Name="Naked swing low color", Description="Represents the color of the naked swing low lines.", Order = 3, GroupName = "6. Naked swings")]
        public Brush NakedSwingLowColor
        {
            get { return nakedSwingLowColor; }
            set { nakedSwingLowColor = value; }
        }
        [Browsable(false)]
        public string NakedSwingLowColorSerialize
        {
            get { return Serialize.BrushToString(nakedSwingLowColor); }
            set { nakedSwingLowColor = Serialize.StringToBrush(value); }
        }
        [NinjaScriptProperty]
        [Display(Name="Naked swing line style", Description="Represents the line style of the naked swing lines.", Order = 4, GroupName = "6. Naked swings")]
        public DashStyleHelper NakedSwingDashStyle
        {
            get { return nakedSwingDashStyle; }
            set { nakedSwingDashStyle = value; }
        }
        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name="Naked swing line width", Description="Represents the line width of the naked swing lines.", Order = 5, GroupName = "6. Naked swings")]
        public int NakedSwingLineWidth
        {
            get { return nakedSwingLineWidth; }
            set { nakedSwingLineWidth = Math.Max(1, value); }
        }
        //=========================================================================================
        #endregion
     
        #region Gann Swings
        //=========================================================================================
        [NinjaScriptProperty]
        [Display(Name = "Ignore Inside Bars", Description = "Indicates if inside bars are ignored. If set to true it is possible that between consecutive up/down bars are inside bars. Only used if calculationSize > 1.", Order = 1, GroupName = "3. Gann Swings")]
        public bool IgnoreInsideBars
        {
            get { return ignoreInsideBars; }
            set { ignoreInsideBars = value; }
        }

        [NinjaScriptProperty]
        [Display(Name = "Use Breakouts", Description = "Indicates if the swings are updated if the last swing high/low is broken. Only used if calculationSize > 1.", Order = 2, GroupName = "3. Gann Swings")]
        public bool UseBreakouts
        {
            get { return useBreakouts; }
            set { useBreakouts = value; }
        }
        //=========================================================================================
        #endregion

        #region Alerts
        //=========================================================================================
        #region ABC
        //-----------------------------------------------------------------------------------------
        [NinjaScriptProperty]
        [Display(Name = "01. Alert ABC", Order = 01, GroupName = "7. Alerts")]
        public bool AlertAbc
        {
            get { return alertAbc; }
            set { alertAbc = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "02. Alert ABC entry", Order = 02, GroupName = "7. Alerts")]
        public bool AlertAbcEntry
        {
            get { return alertAbcEntry; }
            set { alertAbcEntry = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "03. Priority", Order = 03, GroupName = "7. Alerts")]
        public Priority AlertAbcPriority
        {
            get { return alertAbcPriority; }
            set { alertAbcPriority = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "04. Entry priority", Order = 04, GroupName = "7. Alerts")]
        public Priority AlertAbcEntryPriority
        {
            get { return alertAbcEntryPriority; }
            set { alertAbcEntryPriority = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "05. Long sound file name", Order = 05, GroupName = "7. Alerts")]
        public string AlertAbcLongSoundFileName
        {
            get { return alertAbcLongSoundFileName; }
            set { alertAbcLongSoundFileName = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "06. Long entry sound file name", Order = 06, GroupName = "7. Alerts")]
        public string AlertAbcLongEntrySoundFileName
        {
            get { return alertAbcLongEntrySoundFileName; }
            set { alertAbcLongEntrySoundFileName = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "07. Short sound file name", Order = 07, GroupName = "7. Alerts")]
        public string AlertAbcShortSoundFileName
        {
            get { return alertAbcShortSoundFileName; }
            set { alertAbcShortSoundFileName = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "08. Short entry sound file name", Order = 08, GroupName = "7. Alerts")]
        public string AlertAbcShortEntrySoundFileName
        {
            get { return alertAbcShortEntrySoundFileName; }
            set { alertAbcShortEntrySoundFileName = value; }
        }
        //-----------------------------------------------------------------------------------------
        #endregion

        #region Double bottem
        //-----------------------------------------------------------------------------------------
        [NinjaScriptProperty]
        [Display(Name = "11. Alert double bottem", Order = 11, GroupName = "7. Alerts")]
        public bool AlertDoubleBottom
        {
            get { return alertDoubleBottom; }
            set { alertDoubleBottom = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "12. Priority", Order = 12, GroupName = "7. Alerts")]
        public Priority AlertDoubleBottomPriority
        {
            get { return alertDoubleBottomPriority; }
            set { alertDoubleBottomPriority = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "13. Message", Order = 13, GroupName = "7. Alerts")]
        public string AlertDoubleBottomMessage
        {
            get { return alertDoubleBottomMessage; }
            set { alertDoubleBottomMessage = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "14. Sound file name", Order = 14, GroupName = "7. Alerts")]
        public string AlertDoubleBottomSoundFileName
        {
            get { return alertDoubleBottomSoundFileName; }
            set { alertDoubleBottomSoundFileName = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "15. Rearm seconds", Order = 15, GroupName = "7. Alerts")]
        public int AlertDoubleBottomRearmSeconds
        {
            get { return alertDoubleBottomRearmSeconds; }
            set { alertDoubleBottomRearmSeconds = value; }
        }
     
        [XmlIgnore]
        [Display(Name = "16. Back color", Order = 16, GroupName = "7. Alerts")]
        public Brush AlertDoubleBottomBackColor
        {
            get { return alertDoubleBottomBackColor; }
            set { alertDoubleBottomBackColor = value; }
        }
        [Browsable(false)]
        public string AlertDoubleBottomBackColorSerialize
        {
            get { return Serialize.BrushToString(alertDoubleBottomBackColor); }
            set { alertDoubleBottomBackColor = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(Name = "17. Fore color", Order = 17, GroupName = "7. Alerts")]
        public Brush AlertDoubleBottomForeColor
        {
            get { return alertDoubleBottomForeColor; }
            set { alertDoubleBottomForeColor = value; }
        }
        [Browsable(false)]
        public string AlertDoubleBottomForeColorSerialize
        {
            get { return Serialize.BrushToString(alertDoubleBottomForeColor); }
            set { alertDoubleBottomForeColor = Serialize.StringToBrush(value); }
        }
        //-----------------------------------------------------------------------------------------
        #endregion

        #region Double top
        //-----------------------------------------------------------------------------------------
        [NinjaScriptProperty]
        [Display(Name = "21. Alert double top", Order = 21, GroupName = "7. Alerts")]
        public bool AlertDoubleTop
        {
            get { return alertDoubleTop; }
            set { alertDoubleTop = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "22. Priority", Order = 22, GroupName = "7. Alerts")]
        public Priority AlertDoubleTopPriority
        {
            get { return alertDoubleTopPriority; }
            set { alertDoubleTopPriority = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "23. Message", Order = 23, GroupName = "7. Alerts")]
        public string AlertDoubleTopMessage
        {
            get { return alertDoubleTopMessage; }
            set { alertDoubleTopMessage = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "24. Sound file name", Order = 24, GroupName = "7. Alerts")]
        public string AlertDoubleTopSoundFileName
        {
            get { return alertDoubleTopSoundFileName; }
            set { alertDoubleTopSoundFileName = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "25. Rearm seconds", Order = 25, GroupName = "7. Alerts")]
        public int AlertDoubleTopRearmSeconds
        {
            get { return alertDoubleTopRearmSeconds; }
            set { alertDoubleTopRearmSeconds = value; }
        }
     
        [XmlIgnore]
        [Display(Name = "26. Back color", Order = 26, GroupName = "7. Alerts")]
        public Brush AlertDoubleTopBackColor
        {
            get { return alertDoubleTopBackColor; }
            set { alertDoubleTopBackColor = value; }
        }
        [Browsable(false)]
        public string AlertDoubleTopBackColorSerialize
        {
            get { return Serialize.BrushToString(alertDoubleTopBackColor); }
            set { alertDoubleTopBackColor = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(Name = "27. Fore color", Order = 27, GroupName = "7. Alerts")]
        public Brush AlertDoubleTopForeColor
        {
            get { return alertDoubleTopForeColor; }
            set { alertDoubleTopForeColor = value; }
        }
        [Browsable(false)]
        public string AlertDoubleTopForeColorSerialize
        {
            get { return Serialize.BrushToString(alertDoubleTopForeColor); }
            set { alertDoubleTopForeColor = Serialize.StringToBrush(value); }
        }
        //-----------------------------------------------------------------------------------------
        #endregion

        #region Higher low
        //-----------------------------------------------------------------------------------------
        [NinjaScriptProperty]
        [Display(Name = "31. Alert higher low", Order = 31, GroupName = "7. Alerts")]
        public bool AlertHigherLow
        {
            get { return alertHigherLow; }
            set { alertHigherLow = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "32. Priority", Order = 32, GroupName = "7. Alerts")]
        public Priority AlertHigherLowPriority
        {
            get { return alertHigherLowPriority; }
            set { alertHigherLowPriority = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "33. Message", Order = 33, GroupName = "7. Alerts")]
        public string AlertHigherLowMessage
        {
            get { return alertHigherLowMessage; }
            set { alertHigherLowMessage = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "34. Sound file name", Order = 34, GroupName = "7. Alerts")]
        public string AlertHigherLowSoundFileName
        {
            get { return alertHigherLowSoundFileName; }
            set { alertHigherLowSoundFileName = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "35. Rearm seconds", Order = 35, GroupName = "7. Alerts")]
        public int AlertHigherLowRearmSeconds
        {
            get { return alertHigherLowRearmSeconds; }
            set { alertHigherLowRearmSeconds = value; }
        }
     
        [XmlIgnore]
        [Display(Name = "36. Back color", Order = 36, GroupName = "7. Alerts")]
        public Brush AlertHigherLowBackColor
        {
            get { return alertHigherLowBackColor; }
            set { alertHigherLowBackColor = value; }
        }
        [Browsable(false)]
        public string AlertHigherLowBackColorSerialize
        {
            get { return Serialize.BrushToString(alertHigherLowBackColor); }
            set { alertHigherLowBackColor = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(Name = "37. Fore color", Order = 37, GroupName = "7. Alerts")]
        public Brush AlertHigherLowForeColor
        {
            get { return alertHigherLowForeColor; }
            set { alertHigherLowForeColor = value; }
        }
        [Browsable(false)]
        public string AlertHigherLowForeColorSerialize
        {
            get { return Serialize.BrushToString(alertHigherLowForeColor); }
            set { alertHigherLowForeColor = Serialize.StringToBrush(value); }
        }
        //-----------------------------------------------------------------------------------------
        #endregion

        #region Lower high
        //-----------------------------------------------------------------------------------------
        [NinjaScriptProperty]
        [Display(Name = "41. Alert lower high", Order = 41, GroupName = "7. Alerts")]
        public bool AlertLowerHigh
        {
            get { return alertLowerHigh; }
            set { alertLowerHigh = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "42. Priority", Order = 42, GroupName = "7. Alerts")]
        public Priority AlertLowerHighPriority
        {
            get { return alertLowerHighPriority; }
            set { alertLowerHighPriority = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "43. Message", Order = 43, GroupName = "7. Alerts")]
        public string AlertLowerHighMessage
        {
            get { return alertLowerHighMessage; }
            set { alertLowerHighMessage = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "44. Sound file name", Order = 44, GroupName = "7. Alerts")]
        public string AlertLowerHighSoundFileName
        {
            get { return alertLowerHighSoundFileName; }
            set { alertLowerHighSoundFileName = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "45. Rearm seconds", Order = 45, GroupName = "7. Alerts")]
        public int AlertLowerHighRearmSeconds
        {
            get { return alertLowerHighRearmSeconds; }
            set { alertLowerHighRearmSeconds = value; }
        }
     
        [XmlIgnore]
        [Display(Name = "46. Back color", Order = 46, GroupName = "7. Alerts")]
        public Brush AlertLowerHighBackColor
        {
            get { return alertLowerHighBackColor; }
            set { alertLowerHighBackColor = value; }
        }
        [Browsable(false)]
        public string AlertLowerHighBackColorSerialize
        {
            get { return Serialize.BrushToString(alertLowerHighBackColor); }
            set { alertLowerHighBackColor = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(Name = "47. Fore color", Order = 47, GroupName = "7. Alerts")]
        public Brush AlertLowerHighForeColor
        {
            get { return alertLowerHighForeColor; }
            set { alertLowerHighForeColor = value; }
        }
        [Browsable(false)]
        public string AlertLowerHighForeColorSerialize
        {
            get { return Serialize.BrushToString(alertLowerHighForeColor); }
            set { alertLowerHighForeColor = Serialize.StringToBrush(value); }
        }
        //-----------------------------------------------------------------------------------------
        #endregion

        #region Swing change
        //-----------------------------------------------------------------------------------------
        [NinjaScriptProperty]
        [Display(Name = "51. Alert swing change", Order = 51, GroupName = "7. Alerts")]
        public bool AlertSwingChange
        {
            get { return alertSwingChange; }
            set { alertSwingChange = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "52. Priority", Order = 52, GroupName = "7. Alerts")]
        public Priority AlertSwingChangePriority
        {
            get { return alertSwingChangePriority; }
            set { alertSwingChangePriority = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "53. Message", Order = 53, GroupName = "7. Alerts")]
        public string AlertSwingChangeMessage
        {
            get { return alertSwingChangeMessage; }
            set { alertSwingChangeMessage = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "54. Sound file name", Order = 54, GroupName = "7. Alerts")]
        public string AlertSwingChangeSoundFileName
        {
            get { return alertSwingChangeSoundFileName; }
            set { alertSwingChangeSoundFileName = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "55. Rearm seconds", Order = 55, GroupName = "7. Alerts")]
        public int AlertSwingChangeRearmSeconds
        {
            get { return alertSwingChangeRearmSeconds; }
            set { alertSwingChangeRearmSeconds = value; }
        }
     
        [XmlIgnore]
        [Display(Name = "56. Back color", Order = 56, GroupName = "7. Alerts")]
        public Brush AlertSwingChangeBackColor
        {
            get { return alertSwingChangeBackColor; }
            set { alertSwingChangeBackColor = value; }
        }
        [Browsable(false)]
        public string AlertSwingChangeBackColorSerialize
        {
            get { return Serialize.BrushToString(alertSwingChangeBackColor); }
            set { alertSwingChangeBackColor = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(Name = "57. Fore color", Order = 57, GroupName = "7. Alerts")]
        public Brush AlertSwingChangeForeColor
        {
            get { return alertSwingChangeForeColor; }
            set { alertSwingChangeForeColor = value; }
        }
        [Browsable(false)]
        public string AlertSwingChangeForeColorSerialize
        {
            get { return Serialize.BrushToString(alertSwingChangeForeColor); }
            set { alertSwingChangeForeColor = Serialize.StringToBrush(value); }
        }
        //-----------------------------------------------------------------------------------------
        #endregion

        #region Divergence regular high
        //-----------------------------------------------------------------------------------------
        [NinjaScriptProperty]
        [Display(Name = "61. Alert divergence regular high", Order = 61, GroupName = "7. Alerts")]
        public bool AlertDivergenceRegularHigh
        {
            get { return alertDivergenceRegularHigh; }
            set { alertDivergenceRegularHigh = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "62. Priority", Order = 62, GroupName = "7. Alerts")]
        public Priority AlertDivergenceRegularHighPriority
        {
            get { return alertDivergenceRegularHighPriority; }
            set { alertDivergenceRegularHighPriority = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "63. Message", Order = 63, GroupName = "7. Alerts")]
        public string AlertDivergenceRegularHighMessage
        {
            get { return alertDivergenceRegularHighMessage; }
            set { alertDivergenceRegularHighMessage = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "64. Sound file name", Order = 64, GroupName = "7. Alerts")]
        public string AlertDivergenceRegularHighSoundFileName
        {
            get { return alertDivergenceRegularHighSoundFileName; }
            set { alertDivergenceRegularHighSoundFileName = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "65. Rearm seconds", Order = 65, GroupName = "7. Alerts")]
        public int AlertDivergenceRegularHighRearmSeconds
        {
            get { return alertDivergenceRegularHighRearmSeconds; }
            set { alertDivergenceRegularHighRearmSeconds = value; }
        }
     
        [XmlIgnore]
        [Display(Name = "66. Back color", Order = 66, GroupName = "7. Alerts")]
        public Brush AlertDivergenceRegularHighBackColor
        {
            get { return alertDivergenceRegularHighBackColor; }
            set { alertDivergenceRegularHighBackColor = value; }
        }
        [Browsable(false)]
        public string AlertDivergenceRegularHighBackColorSerialize
        {
            get { return Serialize.BrushToString(alertDivergenceRegularHighBackColor); }
            set { alertDivergenceRegularHighBackColor = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(Name = "67. Fore color", Order = 67, GroupName = "7. Alerts")]
        public Brush AlertDivergenceRegularHighForeColor
        {
            get { return alertDivergenceRegularHighForeColor; }
            set { alertDivergenceRegularHighForeColor = value; }
        }
        [Browsable(false)]
        public string AlertDivergenceRegularHighForeColorSerialize
        {
            get { return Serialize.BrushToString(alertDivergenceRegularHighForeColor); }
            set { alertDivergenceRegularHighForeColor = Serialize.StringToBrush(value); }
        }
        //-----------------------------------------------------------------------------------------
        #endregion

        #region Divergence hidden high
        //-----------------------------------------------------------------------------------------
        [NinjaScriptProperty]
        [Display(Name = "71. Alert divergence hidden high", Order = 71, GroupName = "7. Alerts")]
        public bool AlertDivergenceHiddenHigh
        {
            get { return alertDivergenceHiddenHigh; }
            set { alertDivergenceHiddenHigh = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "72. Priority", Order = 72, GroupName = "7. Alerts")]
        public Priority AlertDivergenceHiddenHighPriority
        {
            get { return alertDivergenceHiddenHighPriority; }
            set { alertDivergenceHiddenHighPriority = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "73. Message", Order = 73, GroupName = "7. Alerts")]
        public string AlertDivergenceHiddenHighMessage
        {
            get { return alertDivergenceHiddenHighMessage; }
            set { alertDivergenceHiddenHighMessage = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "74. Sound file name", Order = 74, GroupName = "7. Alerts")]
        public string AlertDivergenceHiddenHighSoundFileName
        {
            get { return alertDivergenceHiddenHighSoundFileName; }
            set { alertDivergenceHiddenHighSoundFileName = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "75. Rearm seconds", Order = 75, GroupName = "7. Alerts")]
        public int AlertDivergenceHiddenHighRearmSeconds
        {
            get { return alertDivergenceHiddenHighRearmSeconds; }
            set { alertDivergenceHiddenHighRearmSeconds = value; }
        }
     
        [XmlIgnore]
        [Display(Name = "76. Back color", Order = 76, GroupName = "7. Alerts")]
        public Brush AlertDivergenceHiddenHighBackColor
        {
            get { return alertDivergenceHiddenHighBackColor; }
            set { alertDivergenceHiddenHighBackColor = value; }
        }
        [Browsable(false)]
        public string AlertDivergenceHiddenHighBackColorSerialize
        {
            get { return Serialize.BrushToString(alertDivergenceHiddenHighBackColor); }
            set { alertDivergenceHiddenHighBackColor = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(Name = "77. Fore color", Order = 77, GroupName = "7. Alerts")]
        public Brush AlertDivergenceHiddenHighForeColor
        {
            get { return alertDivergenceHiddenHighForeColor; }
            set { alertDivergenceHiddenHighForeColor = value; }
        }
        [Browsable(false)]
        public string AlertDivergenceHiddenHighForeColorSerialize
        {
            get { return Serialize.BrushToString(alertDivergenceHiddenHighForeColor); }
            set { alertDivergenceHiddenHighForeColor = Serialize.StringToBrush(value); }
        }
        //-----------------------------------------------------------------------------------------
        #endregion

        #region Divergence regular low
        //-----------------------------------------------------------------------------------------
        [NinjaScriptProperty]
        [Display(Name = "81. Alert divergence regular low", Order = 81, GroupName = "7. Alerts")]
        public bool AlertDivergenceRegularLow
        {
            get { return alertDivergenceRegularLow; }
            set { alertDivergenceRegularLow = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "82. Priority", Order = 82, GroupName = "7. Alerts")]
        public Priority AlertDivergenceRegularLowPriority
        {
            get { return alertDivergenceRegularLowPriority; }
            set { alertDivergenceRegularLowPriority = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "83. Message", Order = 83, GroupName = "7. Alerts")]
        public string AlertDivergenceRegularLowMessage
        {
            get { return alertDivergenceRegularLowMessage; }
            set { alertDivergenceRegularLowMessage = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "84. Sound file name", Order = 84, GroupName = "7. Alerts")]
        public string AlertDivergenceRegularLowSoundFileName
        {
            get { return alertDivergenceRegularLowSoundFileName; }
            set { alertDivergenceRegularLowSoundFileName = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "85. Rearm seconds", Order = 85, GroupName = "7. Alerts")]
        public int AlertDivergenceRegularLowRearmSeconds
        {
            get { return alertDivergenceRegularLowRearmSeconds; }
            set { alertDivergenceRegularLowRearmSeconds = value; }
        }
     
        [XmlIgnore]
        [Display(Name = "86. Back color", Order = 86, GroupName = "7. Alerts")]
        public Brush AlertDivergenceRegularLowBackColor
        {
            get { return alertDivergenceRegularLowBackColor; }
            set { alertDivergenceRegularLowBackColor = value; }
        }
        [Browsable(false)]
        public string AlertDivergenceRegularLowBackColorSerialize
        {
            get { return Serialize.BrushToString(alertDivergenceRegularLowBackColor); }
            set { alertDivergenceRegularLowBackColor = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(Name = "87. Fore color", Order = 87, GroupName = "7. Alerts")]
        public Brush AlertDivergenceRegularLowForeColor
        {
            get { return alertDivergenceRegularLowForeColor; }
            set { alertDivergenceRegularLowForeColor = value; }
        }
        [Browsable(false)]
        public string AlertDivergenceRegularLowForeColorSerialize
        {
            get { return Serialize.BrushToString(alertDivergenceRegularLowForeColor); }
            set { alertDivergenceRegularLowForeColor = Serialize.StringToBrush(value); }
        }
        //-----------------------------------------------------------------------------------------
        #endregion

        #region Divergence hidden low
        //-----------------------------------------------------------------------------------------
        [NinjaScriptProperty]
        [Display(Name = "91. Alert divergence hidden low", Order = 91, GroupName = "7. Alerts")]
        public bool AlertDivergenceHiddenLow
        {
            get { return alertDivergenceHiddenLow; }
            set { alertDivergenceHiddenLow = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "92. Priority", Order = 92, GroupName = "7. Alerts")]
        public Priority AlertDivergenceHiddenLowPriority
        {
            get { return alertDivergenceHiddenLowPriority; }
            set { alertDivergenceHiddenLowPriority = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "93. Message", Order = 93, GroupName = "7. Alerts")]
        public string AlertDivergenceHiddenLowMessage
        {
            get { return alertDivergenceHiddenLowMessage; }
            set { alertDivergenceHiddenLowMessage = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "94. Sound file name", Order = 94, GroupName = "7. Alerts")]
        public string AlertDivergenceHiddenLowSoundFileName
        {
            get { return alertDivergenceHiddenLowSoundFileName; }
            set { alertDivergenceHiddenLowSoundFileName = value; }
        }
        [NinjaScriptProperty]
        [Display(Name = "95. Rearm seconds", Order = 95, GroupName = "7. Alerts")]
        public int AlertDivergenceHiddenLowRearmSeconds
        {
            get { return alertDivergenceHiddenLowRearmSeconds; }
            set { alertDivergenceHiddenLowRearmSeconds = value; }
        }
     
        [XmlIgnore]
        [Display(Name = "96. Back color", Order = 96, GroupName = "7. Alerts")]
        public Brush AlertDivergenceHiddenLowBackColor
        {
            get { return alertDivergenceHiddenLowBackColor; }
            set { alertDivergenceHiddenLowBackColor = value; }
        }
        [Browsable(false)]
        public string AlertDivergenceHiddenLowBackColorSerialize
        {
            get { return Serialize.BrushToString(alertDivergenceHiddenLowBackColor); }
            set { alertDivergenceHiddenLowBackColor = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(Name = "97. Fore color", Order = 97, GroupName = "7. Alerts")]
        public Brush AlertDivergenceHiddenLowForeColor
        {
            get { return alertDivergenceHiddenLowForeColor; }
            set { alertDivergenceHiddenLowForeColor = value; }
        }
        [Browsable(false)]
        public string AlertDivergenceHiddenLowForeColorSerialize
        {
            get { return Serialize.BrushToString(alertDivergenceHiddenLowForeColor); }
            set { alertDivergenceHiddenLowForeColor = Serialize.StringToBrush(value); }
        }
        //-----------------------------------------------------------------------------------------
        #endregion
        //=========================================================================================
        #endregion
     
        #endregion

        #region Statistic
        //#########################################################################################
        #region UpStatistic()
        //=========================================================================================
        private void UpStatistic()
        {
            int upCount = swingHighs.Count - 1;
            if (upCount == 0)
                return;

            overallUpLength = overallUpLength + swingHighs[upCount].length;
            overallAvgUpLength = Math.Round(overallUpLength / upCount, 0,
                MidpointRounding.AwayFromZero);

            overallUpDuration = overallUpDuration + swingHighs[upCount].duration;
            overallAvgUpDuration = Math.Round(overallUpDuration / upCount, 0,
                MidpointRounding.AwayFromZero);

            if (upCount >= statisticLength)
            {
                upLength = 0;
                upDuration = 0;
                for (int i = 0; i < statisticLength; i++)
                {
                    upLength = upLength + swingHighs[upCount - i].length;
                    upDuration = upDuration + swingHighs[upCount - i].duration;
                }
                avgUpLength = Math.Round(upLength / statisticLength, 0,
                    MidpointRounding.AwayFromZero);
                avgUpDuration = Math.Round(upDuration / statisticLength, 0,
                    MidpointRounding.AwayFromZero);
            }

//            lengthList[1, 0].Value = upCount;
//            lengthList[2, 0].Value = overallAvgUpLength;
//            lengthList[3, 0].Value = avgUpLength;
//            lengthList[4, 0].Value = overallAvgUpDuration;
//            lengthList[5, 0].Value = avgUpDuration;

            if (swingHigh.LastRelation == 1)
            {
                hhCount++;

                if (swingHigh.CurRelation == 1) hhCountHH++;
                if (swingHigh.CurRelation == -1) hhCountLH++;
                if (swingLow.LastRelation == 1) hhCountHL++;
                if (swingLow.LastRelation == -1) hhCountLL++;

                hhCountLHPercent = Math.Round(100.0 / hhCount * hhCountLH, 1,
                    MidpointRounding.AwayFromZero);
                hhCountHHPercent = Math.Round(100.0 / hhCount * hhCountHH, 1,
                    MidpointRounding.AwayFromZero);
                hhCountHLPercent = Math.Round(100.0 / hhCount * hhCountHL, 1,
                    MidpointRounding.AwayFromZero);
                hhCountLLPercent = Math.Round(100.0 / hhCount * hhCountLL, 1,
                    MidpointRounding.AwayFromZero);
            }

            if (swingHigh.LastRelation == -1)
            {
                lhCount++;

                if (swingHigh.CurRelation == 1) lhCountHH++;
                if (swingHigh.CurRelation == -1) lhCountLH++;
                if (swingLow.LastRelation == 1) lhCountHL++;
                if (swingLow.LastRelation == -1) lhCountLL++;

                lhCountLHPercent = Math.Round(100.0 / lhCount * lhCountLH, 1,
                    MidpointRounding.AwayFromZero);
                lhCountHHPercent = Math.Round(100.0 / lhCount * lhCountHH, 1,
                    MidpointRounding.AwayFromZero);
                lhCountHLPercent = Math.Round(100.0 / lhCount * lhCountHL, 1,
                    MidpointRounding.AwayFromZero);
                lhCountLLPercent = Math.Round(100.0 / lhCount * lhCountLL, 1,
                    MidpointRounding.AwayFromZero);
            }

            if (swingHigh.LastRelation == 0)
            {
                dtCount++;

                if (swingHigh.CurRelation == 1) dtCountHH++;
                if (swingHigh.CurRelation == -1) dtCountLH++;
                if (swingLow.LastRelation == 1) dtCountHL++;
                if (swingLow.LastRelation == -1) dtCountLL++;

                dtCountLHPercent = Math.Round(100.0 / dtCount * dtCountLH, 1,
                    MidpointRounding.AwayFromZero);
                dtCountHHPercent = Math.Round(100.0 / dtCount * dtCountHH, 1,
                    MidpointRounding.AwayFromZero);
                dtCountHLPercent = Math.Round(100.0 / dtCount * dtCountHL, 1,
                    MidpointRounding.AwayFromZero);
                dtCountLLPercent = Math.Round(100.0 / dtCount * dtCountLL, 1,
                    MidpointRounding.AwayFromZero);
            }
//            relationList[1, 0].Value = hhCount;
//            relationList[2, 0].Value = hhCountHHPercent + "%";
//            relationList[3, 0].Value = hhCountLHPercent + "%";
//            relationList[4, 0].Value = hhCountHLPercent + "%";
//            relationList[5, 0].Value = hhCountLLPercent + "%";

//            relationList[1, 1].Value = lhCount;
//            relationList[2, 1].Value = lhCountHHPercent + "%";
//            relationList[3, 1].Value = lhCountLHPercent + "%";
//            relationList[4, 1].Value = lhCountHLPercent + "%";
//            relationList[5, 1].Value = lhCountLLPercent + "%";

//            relationList[1, 2].Value = dtCount;
//            relationList[2, 2].Value = dtCountHHPercent + "%";
//            relationList[3, 2].Value = dtCountLHPercent + "%";
//            relationList[4, 2].Value = dtCountHLPercent + "%";
//            relationList[5, 2].Value = dtCountLLPercent + "%";
        }
        //=========================================================================================
        #endregion

        #region DownStatistic()
        //=========================================================================================
        private void DownStatistic()
        {
            int dnCount = swingLows.Count - 1;
            if (dnCount == 0)
                return;

            overallDnLength = overallDnLength + swingLows[dnCount].length;
            overallAvgDnLength = Math.Round(overallDnLength / dnCount, 0,
                MidpointRounding.AwayFromZero);

            overallDnDuration = overallDnDuration + swingLows[dnCount].duration;
            overallAvgDnDuration = Math.Round(overallDnDuration / dnCount, 0,
                MidpointRounding.AwayFromZero);

            if (dnCount >= statisticLength)
            {
                dnLength = 0;
                dnDuration = 0;
                for (int i = 0; i < statisticLength; i++)
                {
                    dnLength = dnLength + swingLows[dnCount - i].length;
                    dnDuration = dnDuration + swingLows[dnCount - i].duration;
                }
                avgDnLength = Math.Round(dnLength / statisticLength, 0,
                    MidpointRounding.AwayFromZero);
                avgDnDuration = Math.Round(dnDuration / statisticLength, 0,
                    MidpointRounding.AwayFromZero);
            }

//            lengthList[1, 1].Value = dnCount;
//            lengthList[2, 1].Value = overallAvgDnLength;
//            lengthList[3, 1].Value = avgDnLength;
//            lengthList[4, 1].Value = overallAvgDnDuration;
//            lengthList[5, 1].Value = avgDnDuration;

            if (swingLow.LastRelation == -1)
            {
                llCount++;

                if (swingHigh.LastRelation == 1) llCountHH++;
                if (swingHigh.LastRelation == -1) llCountLH++;
                if (swingLow.CurRelation == 1) llCountHL++;
                if (swingLow.CurRelation == -1) llCountLL++;

                llCountLHPercent = Math.Round(100.0 / llCount * llCountLH, 1,
                    MidpointRounding.AwayFromZero);
                llCountHHPercent = Math.Round(100.0 / llCount * llCountHH, 1,
                    MidpointRounding.AwayFromZero);
                llCountHLPercent = Math.Round(100.0 / llCount * llCountHL, 1,
                    MidpointRounding.AwayFromZero);
                llCountLLPercent = Math.Round(100.0 / llCount * llCountLL, 1,
                    MidpointRounding.AwayFromZero);
            }

            if (swingLow.LastRelation == 1)
            {
                hlCount++;

                if (swingHigh.LastRelation == 1) hlCountHH++;
                if (swingHigh.LastRelation == -1) hlCountLH++;
                if (swingLow.CurRelation == 1) hlCountHL++;
                if (swingLow.CurRelation == -1) hlCountLL++;

                hlCountLHPercent = Math.Round(100.0 / hlCount * hlCountLH, 1,
                    MidpointRounding.AwayFromZero);
                hlCountHHPercent = Math.Round(100.0 / hlCount * hlCountHH, 1,
                    MidpointRounding.AwayFromZero);
                hlCountHLPercent = Math.Round(100.0 / hlCount * hlCountHL, 1,
                    MidpointRounding.AwayFromZero);
                hlCountLLPercent = Math.Round(100.0 / hlCount * hlCountLL, 1,
                    MidpointRounding.AwayFromZero);
            }

            if (swingLow.LastRelation == 0)
            {
                dbCount++;

                if (swingHigh.LastRelation == 1) dbCountHH++;
                if (swingHigh.LastRelation == -1) dbCountLH++;
                if (swingLow.CurRelation == 1) dbCountHL++;
                if (swingLow.CurRelation == -1) dbCountLL++;

                dbCountLHPercent = Math.Round(100.0 / dbCount * dbCountLH, 1,
                    MidpointRounding.AwayFromZero);
                dbCountHHPercent = Math.Round(100.0 / dbCount * dbCountHH, 1,
                    MidpointRounding.AwayFromZero);
                dbCountHLPercent = Math.Round(100.0 / dbCount * dbCountHL, 1,
                    MidpointRounding.AwayFromZero);
                dbCountLLPercent = Math.Round(100.0 / dbCount * dbCountLL, 1,
                    MidpointRounding.AwayFromZero);
            }
//            relationList[1, 3].Value = llCount;
//            relationList[2, 3].Value = llCountHHPercent + "%";
//            relationList[3, 3].Value = llCountLHPercent + "%";
//            relationList[4, 3].Value = llCountHLPercent + "%";
//            relationList[5, 3].Value = llCountLLPercent + "%";

//            relationList[1, 4].Value = hlCount;
//            relationList[2, 4].Value = hlCountHHPercent + "%";
//            relationList[3, 4].Value = hlCountLHPercent + "%";
//            relationList[4, 4].Value = hlCountHLPercent + "%";
//            relationList[5, 4].Value = hlCountLLPercent + "%";

//            relationList[1, 5].Value = dbCount;
//            relationList[2, 5].Value = dbCountHHPercent + "%";
//            relationList[3, 5].Value = dbCountLHPercent + "%";
//            relationList[4, 5].Value = dbCountHLPercent + "%";
//            relationList[5, 5].Value = dbCountLLPercent + "%";
        }
        //=========================================================================================
        #endregion
        //#########################################################################################
        #endregion

        #region CalculateLongRisk
        //#########################################################################################
        /// <summary>
        /// Calculate risk for a long trade.
        /// </summary>
        private void CalculateLongRisk(double entryPrice, double stopLossPrice,
            double takeProfitPrice)
        {
            double loss = Math.Round(((entryPrice - stopLossPrice) *
                Instrument.MasterInstrument.PointValue), 2, MidpointRounding.AwayFromZero);
            int quantity = (int)Math.Truncate(accountSize / 100.0 * accountRisk / loss);
            double win = Math.Round(((takeProfitPrice - entryPrice) *
                Instrument.MasterInstrument.PointValue), 2, MidpointRounding.AwayFromZero);
            double riskReward = Math.Round(win / loss, 2, MidpointRounding.AwayFromZero);

//            if (riskManagementPosition == RiskManagementStyle.ToolStrip)
//            {
//                this.toolStripNumericUpDownEntry.Value = (decimal)entryPrice;
//                this.toolStripNumericUpDownStop.Value = (decimal)stopLossPrice;
//                this.toolStripNumericUpDownTarget.Value = (decimal)takeProfitPrice;

//                this.toolStripLabelQty.Text = "Qty: " + quantity;
//                this.toolStripLabelQty.ForeColor = Color.Green;

//                this.toolStripLabelRiskReward.Text = "R/R: " + riskReward;
//                this.toolStripLabelLoss.Text = "Loss: " + loss;
//                this.toolStripLabelProfit.Text = "Win: " + win;
//                if (riskReward < 1.0)
//                    this.toolStripLabelRiskReward.ForeColor = Color.Red;
//                else if (riskReward < 1.6)
//                    this.toolStripLabelRiskReward.ForeColor = Color.Black;
//                else
//                    this.toolStripLabelRiskReward.ForeColor = Color.Green;
//            }
//            else
//            {
//                this.numericUpDownEntry.Value = (decimal)entryPrice;
//                this.numericUpDownStopLoss.Value = (decimal)stopLossPrice;
//                this.numericUpDownTakeProfit.Value = (decimal)takeProfitPrice;
//                this.labelQuantity.Text = "Qty: " + quantity;
//                this.labelQuantity.ForeColor = Color.Green;

//                this.labelRiskReward.Text = "R/R: " + riskReward;
//                this.labelLossValue.Text = "-" + String.Format("{0:F" + 2 + "}", loss);
//                this.labelWinValue.Text = String.Format("{0:F" + 2 + "}", win);
//                if (riskReward < 1.0)
//                    this.labelRiskReward.ForeColor = Color.Red;
//                else if (riskReward < 1.6)
//                    this.labelRiskReward.ForeColor = Color.Black;
//                else
//                    this.labelRiskReward.ForeColor = Color.Green;
//            }
        }
        //#########################################################################################
        #endregion

        #region CalculateShortRisk
        //#########################################################################################
        /// <summary>
        /// Calculate risk for a short trade.
        /// </summary>
        private void CalculateShortRisk(double entryPrice, double stopLossPrice,
            double takeProfitPrice)
        {
            double loss = Math.Round(((stopLossPrice - entryPrice) *
                Instrument.MasterInstrument.PointValue), 2, MidpointRounding.AwayFromZero);
            int quantity = (int)Math.Truncate(accountSize / 100.0 * accountRisk / loss);
            double win = Math.Round(((entryPrice - takeProfitPrice) *
                Instrument.MasterInstrument.PointValue), 2, MidpointRounding.AwayFromZero);
            double riskReward = Math.Round(win / loss, 2, MidpointRounding.AwayFromZero);

//            if (riskManagementPosition == RiskManagementStyle.ToolStrip)
//            {
//                this.toolStripNumericUpDownEntry.Value = (decimal)entryPrice;
//                this.toolStripNumericUpDownStop.Value = (decimal)stopLossPrice;
//                this.toolStripNumericUpDownTarget.Value = (decimal)takeProfitPrice;

//                this.toolStripLabelQty.Text = "Qty: " + quantity;
//                this.toolStripLabelQty.ForeColor = Color.Red;

//                this.toolStripLabelRiskReward.Text = "R/R: " + riskReward;
//                this.toolStripLabelLoss.Text = "Loss: " + loss;
//                this.toolStripLabelProfit.Text = "Win: " + win;
//                if (riskReward < 1.0)
//                    this.toolStripLabelRiskReward.ForeColor = Color.Red;
//                else if (riskReward < 1.6)
//                    this.toolStripLabelRiskReward.ForeColor = Color.Black;
//                else
//                    this.toolStripLabelRiskReward.ForeColor = Color.Green;
//            }
//            else
//            {
//                this.numericUpDownEntry.Value = (decimal)entryPrice;
//                this.numericUpDownStopLoss.Value = (decimal)stopLossPrice;
//                this.numericUpDownTakeProfit.Value = (decimal)takeProfitPrice;

//                this.labelQuantity.Text = "Qty: " + quantity;
//                this.labelQuantity.ForeColor = Color.Red;

//                this.labelRiskReward.Text = "R/R: " + riskReward;
//                this.labelLossValue.Text = "-" + String.Format("{0:F" + 2 + "}", loss);
//                this.labelWinValue.Text = String.Format("{0:F" + 2 + "}", win);
//                if (riskReward < 1.0)
//                    this.labelRiskReward.ForeColor = Color.Red;
//                else if (riskReward < 1.6)
//                    this.labelRiskReward.ForeColor = Color.Black;
//                else
//                    this.labelRiskReward.ForeColor = Color.Green;
//            }
        }
        //#########################################################################################
        #endregion
     
        #region DisplayName
        //#########################################################################################
        public override string DisplayName
        {
            get { return (displayName != null ? displayName : Name); }
        }    
        //#########################################################################################
        #endregion
    }
}


#region NinjaScript generated code. Neither change nor remove.

namespace NinjaTrader.NinjaScript.Indicators
{
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
        private PriceActionSwing.PriceActionSwingPro[] cachePriceActionSwingPro;
        public PriceActionSwing.PriceActionSwingPro PriceActionSwingPro(SwingStyle swingType, double swingSize, int dtbStrength, bool useCloseValues, AbcPatternMode abcPattern, DivergenceMode divergenceIndicatorMode, DivergenceDirection divergenceDirectionMode, int param1, int param2, int param3, bool showNakedSwings, bool addSwingExtension, bool addSwingRetracementFast, bool addSwingRetracementSlow, SwingLengthStyle swingLengthType, SwingDurationStyle swingDurationType, bool showSwingPrice, bool showSwingLabel, bool showSwingPercent, SwingTimeStyle swingTimeType, SwingVolumeStyle swingVolumeType, VisualizationStyle visualizationType, NinjaTrader.Gui.Tools.SimpleFont textFont, int textOffsetLength, int textOffsetVolume, int textOffsetPrice, int textOffsetLabel, int textOffsetTime, int textOffsetPercent, DashStyleHelper zigZagStyle, int zigZagWidth, bool showSwingSwitch, int swingSwitchOffsetInTicks, DashStyleHelper abcLineStyle, DashStyleHelper abcLineStyleRatio, int abcLineWidth, int abcLineWidthRatio, NinjaTrader.Gui.Tools.SimpleFont abcTextFont, int abcTextOffsetLabel, double abcMaxRetracement, double abcMinRetracement, DashStyleHelper entryLineStyle, int entryLineWidth, double retracementEntryValue, bool showEntryArrows, bool showHistoricalEntryLine, int yTickOffset, bool showDivergenceRegular, bool showDivergenceHidden, DashStyleHelper divDnLineStyle, DashStyleHelper divUpLineStyle, int divDnLineWidth, int divUpLineWidth, bool showHistoricalNakedSwings, DashStyleHelper nakedSwingDashStyle, int nakedSwingLineWidth, bool ignoreInsideBars, bool useBreakouts, bool alertAbc, bool alertAbcEntry, Priority alertAbcPriority, Priority alertAbcEntryPriority, string alertAbcLongSoundFileName, string alertAbcLongEntrySoundFileName, string alertAbcShortSoundFileName, string alertAbcShortEntrySoundFileName, bool alertDoubleBottom, Priority alertDoubleBottomPriority, string alertDoubleBottomMessage, string alertDoubleBottomSoundFileName, int alertDoubleBottomRearmSeconds, bool alertDoubleTop, Priority alertDoubleTopPriority, string alertDoubleTopMessage, string alertDoubleTopSoundFileName, int alertDoubleTopRearmSeconds, bool alertHigherLow, Priority alertHigherLowPriority, string alertHigherLowMessage, string alertHigherLowSoundFileName, int alertHigherLowRearmSeconds, bool alertLowerHigh, Priority alertLowerHighPriority, string alertLowerHighMessage, string alertLowerHighSoundFileName, int alertLowerHighRearmSeconds, bool alertSwingChange, Priority alertSwingChangePriority, string alertSwingChangeMessage, string alertSwingChangeSoundFileName, int alertSwingChangeRearmSeconds, bool alertDivergenceRegularHigh, Priority alertDivergenceRegularHighPriority, string alertDivergenceRegularHighMessage, string alertDivergenceRegularHighSoundFileName, int alertDivergenceRegularHighRearmSeconds, bool alertDivergenceHiddenHigh, Priority alertDivergenceHiddenHighPriority, string alertDivergenceHiddenHighMessage, string alertDivergenceHiddenHighSoundFileName, int alertDivergenceHiddenHighRearmSeconds, bool alertDivergenceRegularLow, Priority alertDivergenceRegularLowPriority, string alertDivergenceRegularLowMessage, string alertDivergenceRegularLowSoundFileName, int alertDivergenceRegularLowRearmSeconds, bool alertDivergenceHiddenLow, Priority alertDivergenceHiddenLowPriority, string alertDivergenceHiddenLowMessage, string alertDivergenceHiddenLowSoundFileName, int alertDivergenceHiddenLowRearmSeconds)
        {
            return PriceActionSwingPro(Input, swingType, swingSize, dtbStrength, useCloseValues, abcPattern, divergenceIndicatorMode, divergenceDirectionMode, param1, param2, param3, showNakedSwings, addSwingExtension, addSwingRetracementFast, addSwingRetracementSlow, swingLengthType, swingDurationType, showSwingPrice, showSwingLabel, showSwingPercent, swingTimeType, swingVolumeType, visualizationType, textFont, textOffsetLength, textOffsetVolume, textOffsetPrice, textOffsetLabel, textOffsetTime, textOffsetPercent, zigZagStyle, zigZagWidth, showSwingSwitch, swingSwitchOffsetInTicks, abcLineStyle, abcLineStyleRatio, abcLineWidth, abcLineWidthRatio, abcTextFont, abcTextOffsetLabel, abcMaxRetracement, abcMinRetracement, entryLineStyle, entryLineWidth, retracementEntryValue, showEntryArrows, showHistoricalEntryLine, yTickOffset, showDivergenceRegular, showDivergenceHidden, divDnLineStyle, divUpLineStyle, divDnLineWidth, divUpLineWidth, showHistoricalNakedSwings, nakedSwingDashStyle, nakedSwingLineWidth, ignoreInsideBars, useBreakouts, alertAbc, alertAbcEntry, alertAbcPriority, alertAbcEntryPriority, alertAbcLongSoundFileName, alertAbcLongEntrySoundFileName, alertAbcShortSoundFileName, alertAbcShortEntrySoundFileName, alertDoubleBottom, alertDoubleBottomPriority, alertDoubleBottomMessage, alertDoubleBottomSoundFileName, alertDoubleBottomRearmSeconds, alertDoubleTop, alertDoubleTopPriority, alertDoubleTopMessage, alertDoubleTopSoundFileName, alertDoubleTopRearmSeconds, alertHigherLow, alertHigherLowPriority, alertHigherLowMessage, alertHigherLowSoundFileName, alertHigherLowRearmSeconds, alertLowerHigh, alertLowerHighPriority, alertLowerHighMessage, alertLowerHighSoundFileName, alertLowerHighRearmSeconds, alertSwingChange, alertSwingChangePriority, alertSwingChangeMessage, alertSwingChangeSoundFileName, alertSwingChangeRearmSeconds, alertDivergenceRegularHigh, alertDivergenceRegularHighPriority, alertDivergenceRegularHighMessage, alertDivergenceRegularHighSoundFileName, alertDivergenceRegularHighRearmSeconds, alertDivergenceHiddenHigh, alertDivergenceHiddenHighPriority, alertDivergenceHiddenHighMessage, alertDivergenceHiddenHighSoundFileName, alertDivergenceHiddenHighRearmSeconds, alertDivergenceRegularLow, alertDivergenceRegularLowPriority, alertDivergenceRegularLowMessage, alertDivergenceRegularLowSoundFileName, alertDivergenceRegularLowRearmSeconds, alertDivergenceHiddenLow, alertDivergenceHiddenLowPriority, alertDivergenceHiddenLowMessage, alertDivergenceHiddenLowSoundFileName, alertDivergenceHiddenLowRearmSeconds);
        }

        public PriceActionSwing.PriceActionSwingPro PriceActionSwingPro(ISeries<double> input, SwingStyle swingType, double swingSize, int dtbStrength, bool useCloseValues, AbcPatternMode abcPattern, DivergenceMode divergenceIndicatorMode, DivergenceDirection divergenceDirectionMode, int param1, int param2, int param3, bool showNakedSwings, bool addSwingExtension, bool addSwingRetracementFast, bool addSwingRetracementSlow, SwingLengthStyle swingLengthType, SwingDurationStyle swingDurationType, bool showSwingPrice, bool showSwingLabel, bool showSwingPercent, SwingTimeStyle swingTimeType, SwingVolumeStyle swingVolumeType, VisualizationStyle visualizationType, NinjaTrader.Gui.Tools.SimpleFont textFont, int textOffsetLength, int textOffsetVolume, int textOffsetPrice, int textOffsetLabel, int textOffsetTime, int textOffsetPercent, DashStyleHelper zigZagStyle, int zigZagWidth, bool showSwingSwitch, int swingSwitchOffsetInTicks, DashStyleHelper abcLineStyle, DashStyleHelper abcLineStyleRatio, int abcLineWidth, int abcLineWidthRatio, NinjaTrader.Gui.Tools.SimpleFont abcTextFont, int abcTextOffsetLabel, double abcMaxRetracement, double abcMinRetracement, DashStyleHelper entryLineStyle, int entryLineWidth, double retracementEntryValue, bool showEntryArrows, bool showHistoricalEntryLine, int yTickOffset, bool showDivergenceRegular, bool showDivergenceHidden, DashStyleHelper divDnLineStyle, DashStyleHelper divUpLineStyle, int divDnLineWidth, int divUpLineWidth, bool showHistoricalNakedSwings, DashStyleHelper nakedSwingDashStyle, int nakedSwingLineWidth, bool ignoreInsideBars, bool useBreakouts, bool alertAbc, bool alertAbcEntry, Priority alertAbcPriority, Priority alertAbcEntryPriority, string alertAbcLongSoundFileName, string alertAbcLongEntrySoundFileName, string alertAbcShortSoundFileName, string alertAbcShortEntrySoundFileName, bool alertDoubleBottom, Priority alertDoubleBottomPriority, string alertDoubleBottomMessage, string alertDoubleBottomSoundFileName, int alertDoubleBottomRearmSeconds, bool alertDoubleTop, Priority alertDoubleTopPriority, string alertDoubleTopMessage, string alertDoubleTopSoundFileName, int alertDoubleTopRearmSeconds, bool alertHigherLow, Priority alertHigherLowPriority, string alertHigherLowMessage, string alertHigherLowSoundFileName, int alertHigherLowRearmSeconds, bool alertLowerHigh, Priority alertLowerHighPriority, string alertLowerHighMessage, string alertLowerHighSoundFileName, int alertLowerHighRearmSeconds, bool alertSwingChange, Priority alertSwingChangePriority, string alertSwingChangeMessage, string alertSwingChangeSoundFileName, int alertSwingChangeRearmSeconds, bool alertDivergenceRegularHigh, Priority alertDivergenceRegularHighPriority, string alertDivergenceRegularHighMessage, string alertDivergenceRegularHighSoundFileName, int alertDivergenceRegularHighRearmSeconds, bool alertDivergenceHiddenHigh, Priority alertDivergenceHiddenHighPriority, string alertDivergenceHiddenHighMessage, string alertDivergenceHiddenHighSoundFileName, int alertDivergenceHiddenHighRearmSeconds, bool alertDivergenceRegularLow, Priority alertDivergenceRegularLowPriority, string alertDivergenceRegularLowMessage, string alertDivergenceRegularLowSoundFileName, int alertDivergenceRegularLowRearmSeconds, bool alertDivergenceHiddenLow, Priority alertDivergenceHiddenLowPriority, string alertDivergenceHiddenLowMessage, string alertDivergenceHiddenLowSoundFileName, int alertDivergenceHiddenLowRearmSeconds)
        {
            if (cachePriceActionSwingPro != null)
                for (int idx = 0; idx < cachePriceActionSwingPro.Length; idx++)
                    if (cachePriceActionSwingPro[idx] != null && cachePriceActionSwingPro[idx].SwingType == swingType && cachePriceActionSwingPro[idx].SwingSize == swingSize && cachePriceActionSwingPro[idx].DtbStrength == dtbStrength && cachePriceActionSwingPro[idx].UseCloseValues == useCloseValues && cachePriceActionSwingPro[idx].AbcPattern == abcPattern && cachePriceActionSwingPro[idx].DivergenceIndicatorMode == divergenceIndicatorMode && cachePriceActionSwingPro[idx].DivergenceDirectionMode == divergenceDirectionMode && cachePriceActionSwingPro[idx].Param1 == param1 && cachePriceActionSwingPro[idx].Param2 == param2 && cachePriceActionSwingPro[idx].Param3 == param3 && cachePriceActionSwingPro[idx].ShowNakedSwings == showNakedSwings && cachePriceActionSwingPro[idx].AddSwingExtension == addSwingExtension && cachePriceActionSwingPro[idx].AddSwingRetracementFast == addSwingRetracementFast && cachePriceActionSwingPro[idx].AddSwingRetracementSlow == addSwingRetracementSlow && cachePriceActionSwingPro[idx].SwingLengthType == swingLengthType && cachePriceActionSwingPro[idx].SwingDurationType == swingDurationType && cachePriceActionSwingPro[idx].ShowSwingPrice == showSwingPrice && cachePriceActionSwingPro[idx].ShowSwingLabel == showSwingLabel && cachePriceActionSwingPro[idx].ShowSwingPercent == showSwingPercent && cachePriceActionSwingPro[idx].SwingTimeType == swingTimeType && cachePriceActionSwingPro[idx].SwingVolumeType == swingVolumeType && cachePriceActionSwingPro[idx].VisualizationType == visualizationType && cachePriceActionSwingPro[idx].TextFont == textFont && cachePriceActionSwingPro[idx].TextOffsetLength == textOffsetLength && cachePriceActionSwingPro[idx].TextOffsetVolume == textOffsetVolume && cachePriceActionSwingPro[idx].TextOffsetPrice == textOffsetPrice && cachePriceActionSwingPro[idx].TextOffsetLabel == textOffsetLabel && cachePriceActionSwingPro[idx].TextOffsetTime == textOffsetTime && cachePriceActionSwingPro[idx].TextOffsetPercent == textOffsetPercent && cachePriceActionSwingPro[idx].ZigZagStyle == zigZagStyle && cachePriceActionSwingPro[idx].ZigZagWidth == zigZagWidth && cachePriceActionSwingPro[idx].ShowSwingSwitch == showSwingSwitch && cachePriceActionSwingPro[idx].SwingSwitchOffsetInTicks == swingSwitchOffsetInTicks && cachePriceActionSwingPro[idx].AbcLineStyle == abcLineStyle && cachePriceActionSwingPro[idx].AbcLineStyleRatio == abcLineStyleRatio && cachePriceActionSwingPro[idx].AbcLineWidth == abcLineWidth && cachePriceActionSwingPro[idx].AbcLineWidthRatio == abcLineWidthRatio && cachePriceActionSwingPro[idx].AbcTextFont == abcTextFont && cachePriceActionSwingPro[idx].AbcTextOffsetLabel == abcTextOffsetLabel && cachePriceActionSwingPro[idx].AbcMaxRetracement == abcMaxRetracement && cachePriceActionSwingPro[idx].AbcMinRetracement == abcMinRetracement && cachePriceActionSwingPro[idx].EntryLineStyle == entryLineStyle && cachePriceActionSwingPro[idx].EntryLineWidth == entryLineWidth && cachePriceActionSwingPro[idx].RetracementEntryValue == retracementEntryValue && cachePriceActionSwingPro[idx].ShowEntryArrows == showEntryArrows && cachePriceActionSwingPro[idx].ShowHistoricalEntryLine == showHistoricalEntryLine && cachePriceActionSwingPro[idx].YTickOffset == yTickOffset && cachePriceActionSwingPro[idx].ShowDivergenceRegular == showDivergenceRegular && cachePriceActionSwingPro[idx].ShowDivergenceHidden == showDivergenceHidden && cachePriceActionSwingPro[idx].DivDnLineStyle == divDnLineStyle && cachePriceActionSwingPro[idx].DivUpLineStyle == divUpLineStyle && cachePriceActionSwingPro[idx].DivDnLineWidth == divDnLineWidth && cachePriceActionSwingPro[idx].DivUpLineWidth == divUpLineWidth && cachePriceActionSwingPro[idx].ShowHistoricalNakedSwings == showHistoricalNakedSwings && cachePriceActionSwingPro[idx].NakedSwingDashStyle == nakedSwingDashStyle && cachePriceActionSwingPro[idx].NakedSwingLineWidth == nakedSwingLineWidth && cachePriceActionSwingPro[idx].IgnoreInsideBars == ignoreInsideBars && cachePriceActionSwingPro[idx].UseBreakouts == useBreakouts && cachePriceActionSwingPro[idx].AlertAbc == alertAbc && cachePriceActionSwingPro[idx].AlertAbcEntry == alertAbcEntry && cachePriceActionSwingPro[idx].AlertAbcPriority == alertAbcPriority && cachePriceActionSwingPro[idx].AlertAbcEntryPriority == alertAbcEntryPriority && cachePriceActionSwingPro[idx].AlertAbcLongSoundFileName == alertAbcLongSoundFileName && cachePriceActionSwingPro[idx].AlertAbcLongEntrySoundFileName == alertAbcLongEntrySoundFileName && cachePriceActionSwingPro[idx].AlertAbcShortSoundFileName == alertAbcShortSoundFileName && cachePriceActionSwingPro[idx].AlertAbcShortEntrySoundFileName == alertAbcShortEntrySoundFileName && cachePriceActionSwingPro[idx].AlertDoubleBottom == alertDoubleBottom && cachePriceActionSwingPro[idx].AlertDoubleBottomPriority == alertDoubleBottomPriority && cachePriceActionSwingPro[idx].AlertDoubleBottomMessage == alertDoubleBottomMessage && cachePriceActionSwingPro[idx].AlertDoubleBottomSoundFileName == alertDoubleBottomSoundFileName && cachePriceActionSwingPro[idx].AlertDoubleBottomRearmSeconds == alertDoubleBottomRearmSeconds && cachePriceActionSwingPro[idx].AlertDoubleTop == alertDoubleTop && cachePriceActionSwingPro[idx].AlertDoubleTopPriority == alertDoubleTopPriority && cachePriceActionSwingPro[idx].AlertDoubleTopMessage == alertDoubleTopMessage && cachePriceActionSwingPro[idx].AlertDoubleTopSoundFileName == alertDoubleTopSoundFileName && cachePriceActionSwingPro[idx].AlertDoubleTopRearmSeconds == alertDoubleTopRearmSeconds && cachePriceActionSwingPro[idx].AlertHigherLow == alertHigherLow && cachePriceActionSwingPro[idx].AlertHigherLowPriority == alertHigherLowPriority && cachePriceActionSwingPro[idx].AlertHigherLowMessage == alertHigherLowMessage && cachePriceActionSwingPro[idx].AlertHigherLowSoundFileName == alertHigherLowSoundFileName && cachePriceActionSwingPro[idx].AlertHigherLowRearmSeconds == alertHigherLowRearmSeconds && cachePriceActionSwingPro[idx].AlertLowerHigh == alertLowerHigh && cachePriceActionSwingPro[idx].AlertLowerHighPriority == alertLowerHighPriority && cachePriceActionSwingPro[idx].AlertLowerHighMessage == alertLowerHighMessage && cachePriceActionSwingPro[idx].AlertLowerHighSoundFileName == alertLowerHighSoundFileName && cachePriceActionSwingPro[idx].AlertLowerHighRearmSeconds == alertLowerHighRearmSeconds && cachePriceActionSwingPro[idx].AlertSwingChange == alertSwingChange && cachePriceActionSwingPro[idx].AlertSwingChangePriority == alertSwingChangePriority && cachePriceActionSwingPro[idx].AlertSwingChangeMessage == alertSwingChangeMessage && cachePriceActionSwingPro[idx].AlertSwingChangeSoundFileName == alertSwingChangeSoundFileName && cachePriceActionSwingPro[idx].AlertSwingChangeRearmSeconds == alertSwingChangeRearmSeconds && cachePriceActionSwingPro[idx].AlertDivergenceRegularHigh == alertDivergenceRegularHigh && cachePriceActionSwingPro[idx].AlertDivergenceRegularHighPriority == alertDivergenceRegularHighPriority && cachePriceActionSwingPro[idx].AlertDivergenceRegularHighMessage == alertDivergenceRegularHighMessage && cachePriceActionSwingPro[idx].AlertDivergenceRegularHighSoundFileName == alertDivergenceRegularHighSoundFileName && cachePriceActionSwingPro[idx].AlertDivergenceRegularHighRearmSeconds == alertDivergenceRegularHighRearmSeconds && cachePriceActionSwingPro[idx].AlertDivergenceHiddenHigh == alertDivergenceHiddenHigh && cachePriceActionSwingPro[idx].AlertDivergenceHiddenHighPriority == alertDivergenceHiddenHighPriority && cachePriceActionSwingPro[idx].AlertDivergenceHiddenHighMessage == alertDivergenceHiddenHighMessage && cachePriceActionSwingPro[idx].AlertDivergenceHiddenHighSoundFileName == alertDivergenceHiddenHighSoundFileName && cachePriceActionSwingPro[idx].AlertDivergenceHiddenHighRearmSeconds == alertDivergenceHiddenHighRearmSeconds && cachePriceActionSwingPro[idx].AlertDivergenceRegularLow == alertDivergenceRegularLow && cachePriceActionSwingPro[idx].AlertDivergenceRegularLowPriority == alertDivergenceRegularLowPriority && cachePriceActionSwingPro[idx].AlertDivergenceRegularLowMessage == alertDivergenceRegularLowMessage && cachePriceActionSwingPro[idx].AlertDivergenceRegularLowSoundFileName == alertDivergenceRegularLowSoundFileName && cachePriceActionSwingPro[idx].AlertDivergenceRegularLowRearmSeconds == alertDivergenceRegularLowRearmSeconds && cachePriceActionSwingPro[idx].AlertDivergenceHiddenLow == alertDivergenceHiddenLow && cachePriceActionSwingPro[idx].AlertDivergenceHiddenLowPriority == alertDivergenceHiddenLowPriority && cachePriceActionSwingPro[idx].AlertDivergenceHiddenLowMessage == alertDivergenceHiddenLowMessage && cachePriceActionSwingPro[idx].AlertDivergenceHiddenLowSoundFileName == alertDivergenceHiddenLowSoundFileName && cachePriceActionSwingPro[idx].AlertDivergenceHiddenLowRearmSeconds == alertDivergenceHiddenLowRearmSeconds && cachePriceActionSwingPro[idx].EqualsInput(input))
                        return cachePriceActionSwingPro[idx];
            return CacheIndicator<PriceActionSwing.PriceActionSwingPro>(new PriceActionSwing.PriceActionSwingPro(){ SwingType = swingType, SwingSize = swingSize, DtbStrength = dtbStrength, UseCloseValues = useCloseValues, AbcPattern = abcPattern, DivergenceIndicatorMode = divergenceIndicatorMode, DivergenceDirectionMode = divergenceDirectionMode, Param1 = param1, Param2 = param2, Param3 = param3, ShowNakedSwings = showNakedSwings, AddSwingExtension = addSwingExtension, AddSwingRetracementFast = addSwingRetracementFast, AddSwingRetracementSlow = addSwingRetracementSlow, SwingLengthType = swingLengthType, SwingDurationType = swingDurationType, ShowSwingPrice = showSwingPrice, ShowSwingLabel = showSwingLabel, ShowSwingPercent = showSwingPercent, SwingTimeType = swingTimeType, SwingVolumeType = swingVolumeType, VisualizationType = visualizationType, TextFont = textFont, TextOffsetLength = textOffsetLength, TextOffsetVolume = textOffsetVolume, TextOffsetPrice = textOffsetPrice, TextOffsetLabel = textOffsetLabel, TextOffsetTime = textOffsetTime, TextOffsetPercent = textOffsetPercent, ZigZagStyle = zigZagStyle, ZigZagWidth = zigZagWidth, ShowSwingSwitch = showSwingSwitch, SwingSwitchOffsetInTicks = swingSwitchOffsetInTicks, AbcLineStyle = abcLineStyle, AbcLineStyleRatio = abcLineStyleRatio, AbcLineWidth = abcLineWidth, AbcLineWidthRatio = abcLineWidthRatio, AbcTextFont = abcTextFont, AbcTextOffsetLabel = abcTextOffsetLabel, AbcMaxRetracement = abcMaxRetracement, AbcMinRetracement = abcMinRetracement, EntryLineStyle = entryLineStyle, EntryLineWidth = entryLineWidth, RetracementEntryValue = retracementEntryValue, ShowEntryArrows = showEntryArrows, ShowHistoricalEntryLine = showHistoricalEntryLine, YTickOffset = yTickOffset, ShowDivergenceRegular = showDivergenceRegular, ShowDivergenceHidden = showDivergenceHidden, DivDnLineStyle = divDnLineStyle, DivUpLineStyle = divUpLineStyle, DivDnLineWidth = divDnLineWidth, DivUpLineWidth = divUpLineWidth, ShowHistoricalNakedSwings = showHistoricalNakedSwings, NakedSwingDashStyle = nakedSwingDashStyle, NakedSwingLineWidth = nakedSwingLineWidth, IgnoreInsideBars = ignoreInsideBars, UseBreakouts = useBreakouts, AlertAbc = alertAbc, AlertAbcEntry = alertAbcEntry, AlertAbcPriority = alertAbcPriority, AlertAbcEntryPriority = alertAbcEntryPriority, AlertAbcLongSoundFileName = alertAbcLongSoundFileName, AlertAbcLongEntrySoundFileName = alertAbcLongEntrySoundFileName, AlertAbcShortSoundFileName = alertAbcShortSoundFileName, AlertAbcShortEntrySoundFileName = alertAbcShortEntrySoundFileName, AlertDoubleBottom = alertDoubleBottom, AlertDoubleBottomPriority = alertDoubleBottomPriority, AlertDoubleBottomMessage = alertDoubleBottomMessage, AlertDoubleBottomSoundFileName = alertDoubleBottomSoundFileName, AlertDoubleBottomRearmSeconds = alertDoubleBottomRearmSeconds, AlertDoubleTop = alertDoubleTop, AlertDoubleTopPriority = alertDoubleTopPriority, AlertDoubleTopMessage = alertDoubleTopMessage, AlertDoubleTopSoundFileName = alertDoubleTopSoundFileName, AlertDoubleTopRearmSeconds = alertDoubleTopRearmSeconds, AlertHigherLow = alertHigherLow, AlertHigherLowPriority = alertHigherLowPriority, AlertHigherLowMessage = alertHigherLowMessage, AlertHigherLowSoundFileName = alertHigherLowSoundFileName, AlertHigherLowRearmSeconds = alertHigherLowRearmSeconds, AlertLowerHigh = alertLowerHigh, AlertLowerHighPriority = alertLowerHighPriority, AlertLowerHighMessage = alertLowerHighMessage, AlertLowerHighSoundFileName = alertLowerHighSoundFileName, AlertLowerHighRearmSeconds = alertLowerHighRearmSeconds, AlertSwingChange = alertSwingChange, AlertSwingChangePriority = alertSwingChangePriority, AlertSwingChangeMessage = alertSwingChangeMessage, AlertSwingChangeSoundFileName = alertSwingChangeSoundFileName, AlertSwingChangeRearmSeconds = alertSwingChangeRearmSeconds, AlertDivergenceRegularHigh = alertDivergenceRegularHigh, AlertDivergenceRegularHighPriority = alertDivergenceRegularHighPriority, AlertDivergenceRegularHighMessage = alertDivergenceRegularHighMessage, AlertDivergenceRegularHighSoundFileName = alertDivergenceRegularHighSoundFileName, AlertDivergenceRegularHighRearmSeconds = alertDivergenceRegularHighRearmSeconds, AlertDivergenceHiddenHigh = alertDivergenceHiddenHigh, AlertDivergenceHiddenHighPriority = alertDivergenceHiddenHighPriority, AlertDivergenceHiddenHighMessage = alertDivergenceHiddenHighMessage, AlertDivergenceHiddenHighSoundFileName = alertDivergenceHiddenHighSoundFileName, AlertDivergenceHiddenHighRearmSeconds = alertDivergenceHiddenHighRearmSeconds, AlertDivergenceRegularLow = alertDivergenceRegularLow, AlertDivergenceRegularLowPriority = alertDivergenceRegularLowPriority, AlertDivergenceRegularLowMessage = alertDivergenceRegularLowMessage, AlertDivergenceRegularLowSoundFileName = alertDivergenceRegularLowSoundFileName, AlertDivergenceRegularLowRearmSeconds = alertDivergenceRegularLowRearmSeconds, AlertDivergenceHiddenLow = alertDivergenceHiddenLow, AlertDivergenceHiddenLowPriority = alertDivergenceHiddenLowPriority, AlertDivergenceHiddenLowMessage = alertDivergenceHiddenLowMessage, AlertDivergenceHiddenLowSoundFileName = alertDivergenceHiddenLowSoundFileName, AlertDivergenceHiddenLowRearmSeconds = alertDivergenceHiddenLowRearmSeconds }, input, ref cachePriceActionSwingPro);
        }
    }
}

namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
        public Indicators.PriceActionSwing.PriceActionSwingPro PriceActionSwingPro(SwingStyle swingType, double swingSize, int dtbStrength, bool useCloseValues, AbcPatternMode abcPattern, DivergenceMode divergenceIndicatorMode, DivergenceDirection divergenceDirectionMode, int param1, int param2, int param3, bool showNakedSwings, bool addSwingExtension, bool addSwingRetracementFast, bool addSwingRetracementSlow, SwingLengthStyle swingLengthType, SwingDurationStyle swingDurationType, bool showSwingPrice, bool showSwingLabel, bool showSwingPercent, SwingTimeStyle swingTimeType, SwingVolumeStyle swingVolumeType, VisualizationStyle visualizationType, NinjaTrader.Gui.Tools.SimpleFont textFont, int textOffsetLength, int textOffsetVolume, int textOffsetPrice, int textOffsetLabel, int textOffsetTime, int textOffsetPercent, DashStyleHelper zigZagStyle, int zigZagWidth, bool showSwingSwitch, int swingSwitchOffsetInTicks, DashStyleHelper abcLineStyle, DashStyleHelper abcLineStyleRatio, int abcLineWidth, int abcLineWidthRatio, NinjaTrader.Gui.Tools.SimpleFont abcTextFont, int abcTextOffsetLabel, double abcMaxRetracement, double abcMinRetracement, DashStyleHelper entryLineStyle, int entryLineWidth, double retracementEntryValue, bool showEntryArrows, bool showHistoricalEntryLine, int yTickOffset, bool showDivergenceRegular, bool showDivergenceHidden, DashStyleHelper divDnLineStyle, DashStyleHelper divUpLineStyle, int divDnLineWidth, int divUpLineWidth, bool showHistoricalNakedSwings, DashStyleHelper nakedSwingDashStyle, int nakedSwingLineWidth, bool ignoreInsideBars, bool useBreakouts, bool alertAbc, bool alertAbcEntry, Priority alertAbcPriority, Priority alertAbcEntryPriority, string alertAbcLongSoundFileName, string alertAbcLongEntrySoundFileName, string alertAbcShortSoundFileName, string alertAbcShortEntrySoundFileName, bool alertDoubleBottom, Priority alertDoubleBottomPriority, string alertDoubleBottomMessage, string alertDoubleBottomSoundFileName, int alertDoubleBottomRearmSeconds, bool alertDoubleTop, Priority alertDoubleTopPriority, string alertDoubleTopMessage, string alertDoubleTopSoundFileName, int alertDoubleTopRearmSeconds, bool alertHigherLow, Priority alertHigherLowPriority, string alertHigherLowMessage, string alertHigherLowSoundFileName, int alertHigherLowRearmSeconds, bool alertLowerHigh, Priority alertLowerHighPriority, string alertLowerHighMessage, string alertLowerHighSoundFileName, int alertLowerHighRearmSeconds, bool alertSwingChange, Priority alertSwingChangePriority, string alertSwingChangeMessage, string alertSwingChangeSoundFileName, int alertSwingChangeRearmSeconds, bool alertDivergenceRegularHigh, Priority alertDivergenceRegularHighPriority, string alertDivergenceRegularHighMessage, string alertDivergenceRegularHighSoundFileName, int alertDivergenceRegularHighRearmSeconds, bool alertDivergenceHiddenHigh, Priority alertDivergenceHiddenHighPriority, string alertDivergenceHiddenHighMessage, string alertDivergenceHiddenHighSoundFileName, int alertDivergenceHiddenHighRearmSeconds, bool alertDivergenceRegularLow, Priority alertDivergenceRegularLowPriority, string alertDivergenceRegularLowMessage, string alertDivergenceRegularLowSoundFileName, int alertDivergenceRegularLowRearmSeconds, bool alertDivergenceHiddenLow, Priority alertDivergenceHiddenLowPriority, string alertDivergenceHiddenLowMessage, string alertDivergenceHiddenLowSoundFileName, int alertDivergenceHiddenLowRearmSeconds)
        {
            return indicator.PriceActionSwingPro(Input, swingType, swingSize, dtbStrength, useCloseValues, abcPattern, divergenceIndicatorMode, divergenceDirectionMode, param1, param2, param3, showNakedSwings, addSwingExtension, addSwingRetracementFast, addSwingRetracementSlow, swingLengthType, swingDurationType, showSwingPrice, showSwingLabel, showSwingPercent, swingTimeType, swingVolumeType, visualizationType, textFont, textOffsetLength, textOffsetVolume, textOffsetPrice, textOffsetLabel, textOffsetTime, textOffsetPercent, zigZagStyle, zigZagWidth, showSwingSwitch, swingSwitchOffsetInTicks, abcLineStyle, abcLineStyleRatio, abcLineWidth, abcLineWidthRatio, abcTextFont, abcTextOffsetLabel, abcMaxRetracement, abcMinRetracement, entryLineStyle, entryLineWidth, retracementEntryValue, showEntryArrows, showHistoricalEntryLine, yTickOffset, showDivergenceRegular, showDivergenceHidden, divDnLineStyle, divUpLineStyle, divDnLineWidth, divUpLineWidth, showHistoricalNakedSwings, nakedSwingDashStyle, nakedSwingLineWidth, ignoreInsideBars, useBreakouts, alertAbc, alertAbcEntry, alertAbcPriority, alertAbcEntryPriority, alertAbcLongSoundFileName, alertAbcLongEntrySoundFileName, alertAbcShortSoundFileName, alertAbcShortEntrySoundFileName, alertDoubleBottom, alertDoubleBottomPriority, alertDoubleBottomMessage, alertDoubleBottomSoundFileName, alertDoubleBottomRearmSeconds, alertDoubleTop, alertDoubleTopPriority, alertDoubleTopMessage, alertDoubleTopSoundFileName, alertDoubleTopRearmSeconds, alertHigherLow, alertHigherLowPriority, alertHigherLowMessage, alertHigherLowSoundFileName, alertHigherLowRearmSeconds, alertLowerHigh, alertLowerHighPriority, alertLowerHighMessage, alertLowerHighSoundFileName, alertLowerHighRearmSeconds, alertSwingChange, alertSwingChangePriority, alertSwingChangeMessage, alertSwingChangeSoundFileName, alertSwingChangeRearmSeconds, alertDivergenceRegularHigh, alertDivergenceRegularHighPriority, alertDivergenceRegularHighMessage, alertDivergenceRegularHighSoundFileName, alertDivergenceRegularHighRearmSeconds, alertDivergenceHiddenHigh, alertDivergenceHiddenHighPriority, alertDivergenceHiddenHighMessage, alertDivergenceHiddenHighSoundFileName, alertDivergenceHiddenHighRearmSeconds, alertDivergenceRegularLow, alertDivergenceRegularLowPriority, alertDivergenceRegularLowMessage, alertDivergenceRegularLowSoundFileName, alertDivergenceRegularLowRearmSeconds, alertDivergenceHiddenLow, alertDivergenceHiddenLowPriority, alertDivergenceHiddenLowMessage, alertDivergenceHiddenLowSoundFileName, alertDivergenceHiddenLowRearmSeconds);
        }

        public Indicators.PriceActionSwing.PriceActionSwingPro PriceActionSwingPro(ISeries<double> input , SwingStyle swingType, double swingSize, int dtbStrength, bool useCloseValues, AbcPatternMode abcPattern, DivergenceMode divergenceIndicatorMode, DivergenceDirection divergenceDirectionMode, int param1, int param2, int param3, bool showNakedSwings, bool addSwingExtension, bool addSwingRetracementFast, bool addSwingRetracementSlow, SwingLengthStyle swingLengthType, SwingDurationStyle swingDurationType, bool showSwingPrice, bool showSwingLabel, bool showSwingPercent, SwingTimeStyle swingTimeType, SwingVolumeStyle swingVolumeType, VisualizationStyle visualizationType, NinjaTrader.Gui.Tools.SimpleFont textFont, int textOffsetLength, int textOffsetVolume, int textOffsetPrice, int textOffsetLabel, int textOffsetTime, int textOffsetPercent, DashStyleHelper zigZagStyle, int zigZagWidth, bool showSwingSwitch, int swingSwitchOffsetInTicks, DashStyleHelper abcLineStyle, DashStyleHelper abcLineStyleRatio, int abcLineWidth, int abcLineWidthRatio, NinjaTrader.Gui.Tools.SimpleFont abcTextFont, int abcTextOffsetLabel, double abcMaxRetracement, double abcMinRetracement, DashStyleHelper entryLineStyle, int entryLineWidth, double retracementEntryValue, bool showEntryArrows, bool showHistoricalEntryLine, int yTickOffset, bool showDivergenceRegular, bool showDivergenceHidden, DashStyleHelper divDnLineStyle, DashStyleHelper divUpLineStyle, int divDnLineWidth, int divUpLineWidth, bool showHistoricalNakedSwings, DashStyleHelper nakedSwingDashStyle, int nakedSwingLineWidth, bool ignoreInsideBars, bool useBreakouts, bool alertAbc, bool alertAbcEntry, Priority alertAbcPriority, Priority alertAbcEntryPriority, string alertAbcLongSoundFileName, string alertAbcLongEntrySoundFileName, string alertAbcShortSoundFileName, string alertAbcShortEntrySoundFileName, bool alertDoubleBottom, Priority alertDoubleBottomPriority, string alertDoubleBottomMessage, string alertDoubleBottomSoundFileName, int alertDoubleBottomRearmSeconds, bool alertDoubleTop, Priority alertDoubleTopPriority, string alertDoubleTopMessage, string alertDoubleTopSoundFileName, int alertDoubleTopRearmSeconds, bool alertHigherLow, Priority alertHigherLowPriority, string alertHigherLowMessage, string alertHigherLowSoundFileName, int alertHigherLowRearmSeconds, bool alertLowerHigh, Priority alertLowerHighPriority, string alertLowerHighMessage, string alertLowerHighSoundFileName, int alertLowerHighRearmSeconds, bool alertSwingChange, Priority alertSwingChangePriority, string alertSwingChangeMessage, string alertSwingChangeSoundFileName, int alertSwingChangeRearmSeconds, bool alertDivergenceRegularHigh, Priority alertDivergenceRegularHighPriority, string alertDivergenceRegularHighMessage, string alertDivergenceRegularHighSoundFileName, int alertDivergenceRegularHighRearmSeconds, bool alertDivergenceHiddenHigh, Priority alertDivergenceHiddenHighPriority, string alertDivergenceHiddenHighMessage, string alertDivergenceHiddenHighSoundFileName, int alertDivergenceHiddenHighRearmSeconds, bool alertDivergenceRegularLow, Priority alertDivergenceRegularLowPriority, string alertDivergenceRegularLowMessage, string alertDivergenceRegularLowSoundFileName, int alertDivergenceRegularLowRearmSeconds, bool alertDivergenceHiddenLow, Priority alertDivergenceHiddenLowPriority, string alertDivergenceHiddenLowMessage, string alertDivergenceHiddenLowSoundFileName, int alertDivergenceHiddenLowRearmSeconds)
        {
            return indicator.PriceActionSwingPro(input, swingType, swingSize, dtbStrength, useCloseValues, abcPattern, divergenceIndicatorMode, divergenceDirectionMode, param1, param2, param3, showNakedSwings, addSwingExtension, addSwingRetracementFast, addSwingRetracementSlow, swingLengthType, swingDurationType, showSwingPrice, showSwingLabel, showSwingPercent, swingTimeType, swingVolumeType, visualizationType, textFont, textOffsetLength, textOffsetVolume, textOffsetPrice, textOffsetLabel, textOffsetTime, textOffsetPercent, zigZagStyle, zigZagWidth, showSwingSwitch, swingSwitchOffsetInTicks, abcLineStyle, abcLineStyleRatio, abcLineWidth, abcLineWidthRatio, abcTextFont, abcTextOffsetLabel, abcMaxRetracement, abcMinRetracement, entryLineStyle, entryLineWidth, retracementEntryValue, showEntryArrows, showHistoricalEntryLine, yTickOffset, showDivergenceRegular, showDivergenceHidden, divDnLineStyle, divUpLineStyle, divDnLineWidth, divUpLineWidth, showHistoricalNakedSwings, nakedSwingDashStyle, nakedSwingLineWidth, ignoreInsideBars, useBreakouts, alertAbc, alertAbcEntry, alertAbcPriority, alertAbcEntryPriority, alertAbcLongSoundFileName, alertAbcLongEntrySoundFileName, alertAbcShortSoundFileName, alertAbcShortEntrySoundFileName, alertDoubleBottom, alertDoubleBottomPriority, alertDoubleBottomMessage, alertDoubleBottomSoundFileName, alertDoubleBottomRearmSeconds, alertDoubleTop, alertDoubleTopPriority, alertDoubleTopMessage, alertDoubleTopSoundFileName, alertDoubleTopRearmSeconds, alertHigherLow, alertHigherLowPriority, alertHigherLowMessage, alertHigherLowSoundFileName, alertHigherLowRearmSeconds, alertLowerHigh, alertLowerHighPriority, alertLowerHighMessage, alertLowerHighSoundFileName, alertLowerHighRearmSeconds, alertSwingChange, alertSwingChangePriority, alertSwingChangeMessage, alertSwingChangeSoundFileName, alertSwingChangeRearmSeconds, alertDivergenceRegularHigh, alertDivergenceRegularHighPriority, alertDivergenceRegularHighMessage, alertDivergenceRegularHighSoundFileName, alertDivergenceRegularHighRearmSeconds, alertDivergenceHiddenHigh, alertDivergenceHiddenHighPriority, alertDivergenceHiddenHighMessage, alertDivergenceHiddenHighSoundFileName, alertDivergenceHiddenHighRearmSeconds, alertDivergenceRegularLow, alertDivergenceRegularLowPriority, alertDivergenceRegularLowMessage, alertDivergenceRegularLowSoundFileName, alertDivergenceRegularLowRearmSeconds, alertDivergenceHiddenLow, alertDivergenceHiddenLowPriority, alertDivergenceHiddenLowMessage, alertDivergenceHiddenLowSoundFileName, alertDivergenceHiddenLowRearmSeconds);
        }
    }
}

namespace NinjaTrader.NinjaScript.Strategies
{
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
        public Indicators.PriceActionSwing.PriceActionSwingPro PriceActionSwingPro(SwingStyle swingType, double swingSize, int dtbStrength, bool useCloseValues, AbcPatternMode abcPattern, DivergenceMode divergenceIndicatorMode, DivergenceDirection divergenceDirectionMode, int param1, int param2, int param3, bool showNakedSwings, bool addSwingExtension, bool addSwingRetracementFast, bool addSwingRetracementSlow, SwingLengthStyle swingLengthType, SwingDurationStyle swingDurationType, bool showSwingPrice, bool showSwingLabel, bool showSwingPercent, SwingTimeStyle swingTimeType, SwingVolumeStyle swingVolumeType, VisualizationStyle visualizationType, NinjaTrader.Gui.Tools.SimpleFont textFont, int textOffsetLength, int textOffsetVolume, int textOffsetPrice, int textOffsetLabel, int textOffsetTime, int textOffsetPercent, DashStyleHelper zigZagStyle, int zigZagWidth, bool showSwingSwitch, int swingSwitchOffsetInTicks, DashStyleHelper abcLineStyle, DashStyleHelper abcLineStyleRatio, int abcLineWidth, int abcLineWidthRatio, NinjaTrader.Gui.Tools.SimpleFont abcTextFont, int abcTextOffsetLabel, double abcMaxRetracement, double abcMinRetracement, DashStyleHelper entryLineStyle, int entryLineWidth, double retracementEntryValue, bool showEntryArrows, bool showHistoricalEntryLine, int yTickOffset, bool showDivergenceRegular, bool showDivergenceHidden, DashStyleHelper divDnLineStyle, DashStyleHelper divUpLineStyle, int divDnLineWidth, int divUpLineWidth, bool showHistoricalNakedSwings, DashStyleHelper nakedSwingDashStyle, int nakedSwingLineWidth, bool ignoreInsideBars, bool useBreakouts, bool alertAbc, bool alertAbcEntry, Priority alertAbcPriority, Priority alertAbcEntryPriority, string alertAbcLongSoundFileName, string alertAbcLongEntrySoundFileName, string alertAbcShortSoundFileName, string alertAbcShortEntrySoundFileName, bool alertDoubleBottom, Priority alertDoubleBottomPriority, string alertDoubleBottomMessage, string alertDoubleBottomSoundFileName, int alertDoubleBottomRearmSeconds, bool alertDoubleTop, Priority alertDoubleTopPriority, string alertDoubleTopMessage, string alertDoubleTopSoundFileName, int alertDoubleTopRearmSeconds, bool alertHigherLow, Priority alertHigherLowPriority, string alertHigherLowMessage, string alertHigherLowSoundFileName, int alertHigherLowRearmSeconds, bool alertLowerHigh, Priority alertLowerHighPriority, string alertLowerHighMessage, string alertLowerHighSoundFileName, int alertLowerHighRearmSeconds, bool alertSwingChange, Priority alertSwingChangePriority, string alertSwingChangeMessage, string alertSwingChangeSoundFileName, int alertSwingChangeRearmSeconds, bool alertDivergenceRegularHigh, Priority alertDivergenceRegularHighPriority, string alertDivergenceRegularHighMessage, string alertDivergenceRegularHighSoundFileName, int alertDivergenceRegularHighRearmSeconds, bool alertDivergenceHiddenHigh, Priority alertDivergenceHiddenHighPriority, string alertDivergenceHiddenHighMessage, string alertDivergenceHiddenHighSoundFileName, int alertDivergenceHiddenHighRearmSeconds, bool alertDivergenceRegularLow, Priority alertDivergenceRegularLowPriority, string alertDivergenceRegularLowMessage, string alertDivergenceRegularLowSoundFileName, int alertDivergenceRegularLowRearmSeconds, bool alertDivergenceHiddenLow, Priority alertDivergenceHiddenLowPriority, string alertDivergenceHiddenLowMessage, string alertDivergenceHiddenLowSoundFileName, int alertDivergenceHiddenLowRearmSeconds)
        {
            return indicator.PriceActionSwingPro(Input, swingType, swingSize, dtbStrength, useCloseValues, abcPattern, divergenceIndicatorMode, divergenceDirectionMode, param1, param2, param3, showNakedSwings, addSwingExtension, addSwingRetracementFast, addSwingRetracementSlow, swingLengthType, swingDurationType, showSwingPrice, showSwingLabel, showSwingPercent, swingTimeType, swingVolumeType, visualizationType, textFont, textOffsetLength, textOffsetVolume, textOffsetPrice, textOffsetLabel, textOffsetTime, textOffsetPercent, zigZagStyle, zigZagWidth, showSwingSwitch, swingSwitchOffsetInTicks, abcLineStyle, abcLineStyleRatio, abcLineWidth, abcLineWidthRatio, abcTextFont, abcTextOffsetLabel, abcMaxRetracement, abcMinRetracement, entryLineStyle, entryLineWidth, retracementEntryValue, showEntryArrows, showHistoricalEntryLine, yTickOffset, showDivergenceRegular, showDivergenceHidden, divDnLineStyle, divUpLineStyle, divDnLineWidth, divUpLineWidth, showHistoricalNakedSwings, nakedSwingDashStyle, nakedSwingLineWidth, ignoreInsideBars, useBreakouts, alertAbc, alertAbcEntry, alertAbcPriority, alertAbcEntryPriority, alertAbcLongSoundFileName, alertAbcLongEntrySoundFileName, alertAbcShortSoundFileName, alertAbcShortEntrySoundFileName, alertDoubleBottom, alertDoubleBottomPriority, alertDoubleBottomMessage, alertDoubleBottomSoundFileName, alertDoubleBottomRearmSeconds, alertDoubleTop, alertDoubleTopPriority, alertDoubleTopMessage, alertDoubleTopSoundFileName, alertDoubleTopRearmSeconds, alertHigherLow, alertHigherLowPriority, alertHigherLowMessage, alertHigherLowSoundFileName, alertHigherLowRearmSeconds, alertLowerHigh, alertLowerHighPriority, alertLowerHighMessage, alertLowerHighSoundFileName, alertLowerHighRearmSeconds, alertSwingChange, alertSwingChangePriority, alertSwingChangeMessage, alertSwingChangeSoundFileName, alertSwingChangeRearmSeconds, alertDivergenceRegularHigh, alertDivergenceRegularHighPriority, alertDivergenceRegularHighMessage, alertDivergenceRegularHighSoundFileName, alertDivergenceRegularHighRearmSeconds, alertDivergenceHiddenHigh, alertDivergenceHiddenHighPriority, alertDivergenceHiddenHighMessage, alertDivergenceHiddenHighSoundFileName, alertDivergenceHiddenHighRearmSeconds, alertDivergenceRegularLow, alertDivergenceRegularLowPriority, alertDivergenceRegularLowMessage, alertDivergenceRegularLowSoundFileName, alertDivergenceRegularLowRearmSeconds, alertDivergenceHiddenLow, alertDivergenceHiddenLowPriority, alertDivergenceHiddenLowMessage, alertDivergenceHiddenLowSoundFileName, alertDivergenceHiddenLowRearmSeconds);
        }

        public Indicators.PriceActionSwing.PriceActionSwingPro PriceActionSwingPro(ISeries<double> input , SwingStyle swingType, double swingSize, int dtbStrength, bool useCloseValues, AbcPatternMode abcPattern, DivergenceMode divergenceIndicatorMode, DivergenceDirection divergenceDirectionMode, int param1, int param2, int param3, bool showNakedSwings, bool addSwingExtension, bool addSwingRetracementFast, bool addSwingRetracementSlow, SwingLengthStyle swingLengthType, SwingDurationStyle swingDurationType, bool showSwingPrice, bool showSwingLabel, bool showSwingPercent, SwingTimeStyle swingTimeType, SwingVolumeStyle swingVolumeType, VisualizationStyle visualizationType, NinjaTrader.Gui.Tools.SimpleFont textFont, int textOffsetLength, int textOffsetVolume, int textOffsetPrice, int textOffsetLabel, int textOffsetTime, int textOffsetPercent, DashStyleHelper zigZagStyle, int zigZagWidth, bool showSwingSwitch, int swingSwitchOffsetInTicks, DashStyleHelper abcLineStyle, DashStyleHelper abcLineStyleRatio, int abcLineWidth, int abcLineWidthRatio, NinjaTrader.Gui.Tools.SimpleFont abcTextFont, int abcTextOffsetLabel, double abcMaxRetracement, double abcMinRetracement, DashStyleHelper entryLineStyle, int entryLineWidth, double retracementEntryValue, bool showEntryArrows, bool showHistoricalEntryLine, int yTickOffset, bool showDivergenceRegular, bool showDivergenceHidden, DashStyleHelper divDnLineStyle, DashStyleHelper divUpLineStyle, int divDnLineWidth, int divUpLineWidth, bool showHistoricalNakedSwings, DashStyleHelper nakedSwingDashStyle, int nakedSwingLineWidth, bool ignoreInsideBars, bool useBreakouts, bool alertAbc, bool alertAbcEntry, Priority alertAbcPriority, Priority alertAbcEntryPriority, string alertAbcLongSoundFileName, string alertAbcLongEntrySoundFileName, string alertAbcShortSoundFileName, string alertAbcShortEntrySoundFileName, bool alertDoubleBottom, Priority alertDoubleBottomPriority, string alertDoubleBottomMessage, string alertDoubleBottomSoundFileName, int alertDoubleBottomRearmSeconds, bool alertDoubleTop, Priority alertDoubleTopPriority, string alertDoubleTopMessage, string alertDoubleTopSoundFileName, int alertDoubleTopRearmSeconds, bool alertHigherLow, Priority alertHigherLowPriority, string alertHigherLowMessage, string alertHigherLowSoundFileName, int alertHigherLowRearmSeconds, bool alertLowerHigh, Priority alertLowerHighPriority, string alertLowerHighMessage, string alertLowerHighSoundFileName, int alertLowerHighRearmSeconds, bool alertSwingChange, Priority alertSwingChangePriority, string alertSwingChangeMessage, string alertSwingChangeSoundFileName, int alertSwingChangeRearmSeconds, bool alertDivergenceRegularHigh, Priority alertDivergenceRegularHighPriority, string alertDivergenceRegularHighMessage, string alertDivergenceRegularHighSoundFileName, int alertDivergenceRegularHighRearmSeconds, bool alertDivergenceHiddenHigh, Priority alertDivergenceHiddenHighPriority, string alertDivergenceHiddenHighMessage, string alertDivergenceHiddenHighSoundFileName, int alertDivergenceHiddenHighRearmSeconds, bool alertDivergenceRegularLow, Priority alertDivergenceRegularLowPriority, string alertDivergenceRegularLowMessage, string alertDivergenceRegularLowSoundFileName, int alertDivergenceRegularLowRearmSeconds, bool alertDivergenceHiddenLow, Priority alertDivergenceHiddenLowPriority, string alertDivergenceHiddenLowMessage, string alertDivergenceHiddenLowSoundFileName, int alertDivergenceHiddenLowRearmSeconds)
        {
            return indicator.PriceActionSwingPro(input, swingType, swingSize, dtbStrength, useCloseValues, abcPattern, divergenceIndicatorMode, divergenceDirectionMode, param1, param2, param3, showNakedSwings, addSwingExtension, addSwingRetracementFast, addSwingRetracementSlow, swingLengthType, swingDurationType, showSwingPrice, showSwingLabel, showSwingPercent, swingTimeType, swingVolumeType, visualizationType, textFont, textOffsetLength, textOffsetVolume, textOffsetPrice, textOffsetLabel, textOffsetTime, textOffsetPercent, zigZagStyle, zigZagWidth, showSwingSwitch, swingSwitchOffsetInTicks, abcLineStyle, abcLineStyleRatio, abcLineWidth, abcLineWidthRatio, abcTextFont, abcTextOffsetLabel, abcMaxRetracement, abcMinRetracement, entryLineStyle, entryLineWidth, retracementEntryValue, showEntryArrows, showHistoricalEntryLine, yTickOffset, showDivergenceRegular, showDivergenceHidden, divDnLineStyle, divUpLineStyle, divDnLineWidth, divUpLineWidth, showHistoricalNakedSwings, nakedSwingDashStyle, nakedSwingLineWidth, ignoreInsideBars, useBreakouts, alertAbc, alertAbcEntry, alertAbcPriority, alertAbcEntryPriority, alertAbcLongSoundFileName, alertAbcLongEntrySoundFileName, alertAbcShortSoundFileName, alertAbcShortEntrySoundFileName, alertDoubleBottom, alertDoubleBottomPriority, alertDoubleBottomMessage, alertDoubleBottomSoundFileName, alertDoubleBottomRearmSeconds, alertDoubleTop, alertDoubleTopPriority, alertDoubleTopMessage, alertDoubleTopSoundFileName, alertDoubleTopRearmSeconds, alertHigherLow, alertHigherLowPriority, alertHigherLowMessage, alertHigherLowSoundFileName, alertHigherLowRearmSeconds, alertLowerHigh, alertLowerHighPriority, alertLowerHighMessage, alertLowerHighSoundFileName, alertLowerHighRearmSeconds, alertSwingChange, alertSwingChangePriority, alertSwingChangeMessage, alertSwingChangeSoundFileName, alertSwingChangeRearmSeconds, alertDivergenceRegularHigh, alertDivergenceRegularHighPriority, alertDivergenceRegularHighMessage, alertDivergenceRegularHighSoundFileName, alertDivergenceRegularHighRearmSeconds, alertDivergenceHiddenHigh, alertDivergenceHiddenHighPriority, alertDivergenceHiddenHighMessage, alertDivergenceHiddenHighSoundFileName, alertDivergenceHiddenHighRearmSeconds, alertDivergenceRegularLow, alertDivergenceRegularLowPriority, alertDivergenceRegularLowMessage, alertDivergenceRegularLowSoundFileName, alertDivergenceRegularLowRearmSeconds, alertDivergenceHiddenLow, alertDivergenceHiddenLowPriority, alertDivergenceHiddenLowMessage, alertDivergenceHiddenLowSoundFileName, alertDivergenceHiddenLowRearmSeconds);
        }
    }
}

#endregion


D Value Area

Code:
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion

namespace _dValueEnums
{
    public enum dValueAreaTypes
    {
        VOC,
        TPO,
        VWTPO,
        VTPO
    }
}

//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
    #region noteFromTheAuthor
    // <summary> (origonal -> CalculateValueArea)
    // The Value Area is the price range where 70% of yesterdays volume traded
    // Written by Ben L. at [email protected]
    //   Theory taken from several sources, but summarized at: http://www.secretsoftraders.com/ValueAreaHelpGuide.htm
    // May God bless you and your trading!
    //

    //    Description of the "ProfileType" parameter:

    //        I've given the option of creating the profile in 3 different ways:
    //            1)  VOC - This method loads all the volume of a bar onto the closing price of that bar.
    //                        e.g.  A 5-minute bar has a volume of 280 and a range of 1.5 points with a close at 1534.25, then
    //                        all 280 hits of volume are loaded onto the 1534.25 closing price.
    //            2)  TPO - This method disregards volume altogether, and gives a single hit to each price in the range of the bar.
    //                        e.g.  A 5-minute bar has a range of 1.5 points with a High at 1534 and a Low at 1532.5, then
    //                        1 contract (or "hit") is loaded to the seven prices in that range: 1532.50, 1532.75, 1533.0, 1533.25, 1533.50, 1533.75, and 1534
    //            3)  VWTPO - This method distribues the volume of a bar over the price range of the bar.
    //                        e.g.  A 5-minute bar has a volume of 280 and a range of 1.5 points with a High at 1534 and a Low at 1532.5, then
    //                        40 contracts (=280/7) are loaded to each of the seven prices in that range: 1532.50, 1532.75, 1533.0, 1533.25, 1533.50, 1533.75, and 1534
    //            4)  VTPO - This method distribues the volume of a bar Evenly over the price range of the bar.
    //                        e.g.  A 5-minute bar has a volume of 280 and a range of 1.5 points with a High at 1534 and a Low at 1532.5, then
    //                        280 contracts are loaded to each of the seven prices in that range: 1532.50, 1532.75, 1533.0, 1533.25, 1533.50, 1533.75, and 1534
    //                        Since the calcs. are Relative to other bars / price points, more volume bars / price points will show that.
    //
    // Mods DeanV - 11/2008
    //    3/20/2010 - NT7 conversion (version 7.0)
    //        Adjusted call params for v7 requirements and non-equidistant charts, tweeked session detection, and re-positioned a few lables.
    //        Included a global enum namespace/file with distribution (_dValueEnums) so different versions don't have to deal with it).
    //    v7.0.1 - 3/23 - Added Session Template time override. Overwrites start / end settings with template in use settings.
    //    v7.0.2 - 3/28 - Added ZOrder flag... attempt to show behind other stuff.
    //    v7.0.3 - 4/07/10 - merged MDay's features... Map visable screen or combo's of days. Added / Changed these inputs
    //        ScreenMapType - 0=daily(daily maps), 1=screen(whatever is on screen), 2=combine days (uses PreviousSessions to determin # of days to combine)
    //        PreviousSessions - # of days to add to today's activity when ScreenMapType = 2. 0 = today only, 1 = today and yesterday.
    //        ShowDailyPlots - if true will show daily plot lines (regardless of SCreenMapType).
    //        * ShowEvolvingPOC's - added type 3 = Extended lines (full screen display of evolving lines in combo modes)
    //        * increase TotalSlots Maximum to 1000 (combo's probably need more slots for larger ranging)
    //        * combo's will include pre-sessions if part of chart display.
    //    v7.0.4 - 4/19-20 - Added Zero (Auto) setting on "Slot Min. Height".. 0 = fill in gaps between slots, etc., to display as contiguous verticals (no gaps or overprints)
    //        (when slots are combining ticks (TotalSlot<ticks in range & slot min. = 0), will increase POC & VA's buy about 1/2 tick... probably a little more accurate)
    //    v7.0.5 - 4/21 - Added -1 input (Auto slots seperated by 1 pix.) to "Slot Min. Height". -1 = separates slots by 1 pix.
    //        When "Slot Min. Height" <=0 - maps will adjust to center when slots are combining. Reworked POC, VA calc's to reflect centered slots.
    //
    #endregion

    public class DValueArea : Indicator
    {
        #region Variables
        private DateTime                cSEndTime;
        private DateTime                cSStartTime;
        private int                        eLineTransparency    = 40;
        private SharpDX.Direct2D1.Brush ePOCBrush;
        private SharpDX.Direct2D1.Brush eVAbBrush;
        private SharpDX.Direct2D1.Brush eVAtBrush;
        private Brush                    evolvingPOCColor    = Brushes.Red;
        private Brush                    evolvingVAbColor    = Brushes.Green;
        private Brush                    evolvingVAtColor    = Brushes.Green;
        private int                        lastSlotUsed;
        private int                        leftScrnBnum;    //left most bar# in display
        private int                        openHour;
        private int                        openMinute;
        private Rectangle                plotbounds;
        private double                    plotMax;
        private double                    plotMMDiff;
        private double                    plotMin;
        private SharpDX.Direct2D1.Brush    preSessBrush;
        private double[,]                priceHitsArray;// = new double[2,500];
        private double                    priceOfPOC            = 0.0;
        private int                        rightScrnBnum;    //right most bar# on screen.
        private int                        sEndBnum            = 0;
        private Series<int>                sesNum;
        private Brush                    sessColor;
        private SharpDX.Direct2D1.Brush sessBrush;
        private SessionIterator            sessionIterator;
        private double                    sessMaxHits            = 0.0;
        private double                    sessPriceOfPOC        = 0.0;
        private double                    sessVAtop            = 0.0;
        private double                    sessVAbot            = 0.0;
        private double                    slotHalfRange;
        private Brush                    slotPreSessionColor = Brushes.Red;
        private Brush                    slotSessionColor    = Brushes.Lime;
        private int                        slotTransparency    = 60;
        private int                        sStartBnum            = 0;    //first date bar# we care about
        private string                    textForm            = "0.";
        private double                    theSessionHigh;
        private double                    theSessionLow;
        private int                        ticksPerSlot;
        private double                    vAbot                = 0.0;
        private double                    vAtop                = 0.0;
        #endregion

        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description                            = @"";
                Name                                = "DValueArea";
                Calculate                            = Calculate.OnBarClose;
                IsOverlay                            = true;
                DisplayInDataBox                    = true;
                DrawOnPricePanel                    = true;
                DrawHorizontalGridLines                = true;
                DrawVerticalGridLines                = true;
                PaintPriceMarkers                    = true;
                IsAutoScale                            = false;
                ScaleJustification                    = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                //See Help Guide for additional information.
                IsSuspendedWhileInactive            = true;
             
                ELineTransparency                    = 40;
                ETextDecimals                        = 2;
                ETextPosition                        = 0;
                ELineHeight                            = 2;
                InclWeekendVol                        = false;
                OpenTime                            = new TimeSpan(8, 30, 0);
                PctOfVolumeInVA                        = 0.7;
                PresentMethod                        = 2;
                PreviousSessions                    = 2;
                ProfileType                            = _dValueEnums.dValueAreaTypes.VWTPO;
                ScreenMapType                        = 0;
                ScreenPercent                        = 100;
                ScreenPosition                        = 1;
                SessionLengthHours                    = 6.75;
                ShowDailyPlots                        = true;
                ShowEvolvingPOCs                    = 2;
                SlotMinHeight                        = 0;
                SlotTransparency                    = 60;
                TotalSlots                            = 300;
                VACalcType                            = 2;
                ZOrderPutBehind                        = false;

                AddPlot(Brushes.Chocolate, "RtPOC");
                AddPlot(Brushes.Green, "POC");
                AddPlot(new Stroke(Brushes.Pink, 1), PlotStyle.Dot, "VAb");
                AddPlot(new Stroke(Brushes.LightGreen, 1), PlotStyle.Dot, "VAt");
            }
            else if (State == State.DataLoaded)
            {
                sesNum = new Series<int>(this, MaximumBarsLookBack.Infinite);
            }
            else if (State == State.Historical)
            {
                sessionIterator = new SessionIterator(BarsArray[0]);

                openHour = OpenTime.Hours;
                openMinute = OpenTime.Minutes;

                priceHitsArray = new double[2, TotalSlots];
             
                for (int i = ETextDecimals; i > 0; i--)
                    textForm += "0";

                if (ZOrderPutBehind)
                    ZOrder = -1;
                else
                    ZOrder = 0;
            }
            else if (State == State.Terminated)
            {
                if (sessBrush != null)
                    sessBrush.Dispose();

                if (preSessBrush != null)
                    preSessBrush.Dispose();

                if (ePOCBrush != null)
                    ePOCBrush.Dispose();

                if (eVAtBrush != null)
                    eVAtBrush.Dispose();

                if (eVAbBrush != null)
                    eVAbBrush.Dispose();
            }
        }

        private void DetermineHL_BarRange()
        {
            // use bar number range from SetSessionTimes(>0).
            theSessionHigh = Bars.GetHigh(sEndBnum);
            theSessionLow = Bars.GetLow(sEndBnum);
 
            for (int x = sEndBnum; x >= sStartBnum; x--)
            {
                if (Bars.GetHigh(x) > theSessionHigh)
                    theSessionHigh = Bars.GetHigh(x);

                if (Bars.GetLow(x) < theSessionLow)
                    theSessionLow = Bars.GetLow(x);
            }
        }

        private void DrawEvolving(int ThisSesNum, SharpDX.Direct2D1.Brush eBrush, double ePrice)
        {
            int x, yPos, vPos, vHeight;
            double price;
            int hWidth;

            int barPaintWidth = ChartControl.GetBarPaintWidth(ChartBars);
            int halfBarWidth = (int)(barPaintWidth * 0.5);

            int sbarNum = leftScrnBnum;    //default is off screen to left
            int barsInRange = 0;
            for (x = leftScrnBnum; x <= rightScrnBnum; x++)
            {
                //scan left to right
                if (sesNum.GetValueAt(x) == ThisSesNum)
                {
                    if (PresentMethod > 0 && x < sStartBnum)
                        continue; //wait till we get an open session bar.
                    if (PresentMethod == 2 && x > sEndBnum)
                        break; //stop wen we get an open session bar if sEB says it's a presession.
                    barsInRange++;
                }

                if (barsInRange == 1)
                    sbarNum = x;    //found first valid bar
            }

            if (--barsInRange < 1)
                return;    //have at least 1 bar to paint. Do paint last bar.

            int ebarNum = sbarNum + barsInRange;

            int leftMostPos = ChartControl.GetXByBarIndex(ChartBars, sbarNum) - halfBarWidth;
            int rightMostPos = ChartControl.GetXByBarIndex(ChartBars, ebarNum) + halfBarWidth;

            if (sEndBnum + 1 >= CurrentBar)
                rightMostPos = Convert.ToInt32(ChartPanel.W);

            int totalHeight = Convert.ToInt32(ChartPanel.Y + ChartPanel.H);

            price = ePrice;
            hWidth = (int)((rightMostPos - leftMostPos));

            yPos = (int)((totalHeight) - ((price - plotMin) / plotMMDiff) * ChartPanel.H);
            vPos = yPos + ELineHeight;
            if (yPos >= totalHeight)
                return;    //too low or high to display
            if (vPos <= 1)
                vPos = 1;

            //take out any negitive portion
            yPos += (yPos < 0 ? yPos * -1 : 0);

            if (vPos > totalHeight)
                vPos = totalHeight;
            vHeight = vPos - yPos;

            SharpDX.RectangleF rect = new SharpDX.RectangleF(leftMostPos, yPos, hWidth, vHeight);
            RenderTarget.FillRectangle(rect, eBrush);
        }
 
        private void DrawSlotsUV(ChartScale chartScale, int slotHeight, int ThisSesNum, SharpDX.Direct2D1.Brush eBrush)
        {
            // draw slots universal
            // left or right based, and percentage of area

            int x, yPos, vPos, vHeight;
            double price;
            int hWidth;
            int halfslotHeight = 0;

            //if(slotHeight < minSlotHeight) HalfslotHeight = minSlotHeight /2;
            if (SlotMinHeight > 0 && slotHeight < SlotMinHeight)
                halfslotHeight = SlotMinHeight / 2;

            int barPaintWidth = ChartControl.GetBarPaintWidth(ChartBars);
            int halfBarWidth = (int)(barPaintWidth * 0.5);

            int sbarNum = leftScrnBnum;    //default is left most screen bar.
            int barsInRange = 0;

            //determine barsInRage based on screenMapType..
            if (ScreenMapType == 1)
                barsInRange = rightScrnBnum - leftScrnBnum;

            else if (ScreenMapType == 2)
            {    //day's combined
                barsInRange = rightScrnBnum - leftScrnBnum;
                if (sesNum.GetValueAt(leftScrnBnum) < ThisSesNum)
                { //find first onscreen bar
                    for (x = leftScrnBnum; x <= rightScrnBnum; x++)
                    {    //scan left to right
                        if (sesNum.GetValueAt(x) == ThisSesNum)
                        {
                            sbarNum = x;
                            x = rightScrnBnum + 1;    //break
                        }
                        else barsInRange--;
                    }
                }
            }
            else
            {    //daily only        
                for (x = leftScrnBnum; x <= rightScrnBnum; x++)
                {    //scan left to right
                    if (sesNum.GetValueAt(x) == ThisSesNum)
                    {
                        if (PresentMethod > 0 && x < sStartBnum)
                            continue; //wait till we get an open session bar.
                        if (PresentMethod == 2 && x > sEndBnum)
                            break; //stop wen we get an open session bar if sEB says it's a presession.
                        barsInRange++;
                    }
                    if (barsInRange == 1)
                        sbarNum = x;    //found first valid bar
                }
            }//end screenMapType

            if (--barsInRange < 1)
                return;    //have at least 1 bar to paint. Don't paint last bar.
            int ebarNum = sbarNum + barsInRange;

            int leftMostPos        = ChartControl.GetXByBarIndex(ChartBars, sbarNum) - (ScreenPosition == 1 ? halfBarWidth : 0);
            int rightMostPos    = ChartControl.GetXByBarIndex(ChartBars, ebarNum) + (ScreenPosition == 2 ? halfBarWidth : 0);

            //adjust right screen display area if combo draws.
            if (ScreenMapType > 0)
                rightMostPos = Convert.ToInt32(ChartPanel.W);

            //now for some draw stuff...
            int totalHeight = Convert.ToInt32(ChartPanel.Y + ChartPanel.H);

            //reduce pix to show % amount of it.
            price = ((rightMostPos - leftMostPos) * ((100 - ScreenPercent) * 0.01));    //temp usage of price

            //reset left or right depending on screenposition..
            if (ScreenPosition == 1)
                rightMostPos -= (int)price;
            else
                leftMostPos += (int)price;
            int totalWidth = rightMostPos - leftMostPos;

            int prevYpos = 0;
            for (x = 0; x <= lastSlotUsed; x++)
            {
                price = priceHitsArray[0, x] + slotHalfRange;    //take it from mid to top.
                hWidth = (int)((totalWidth) * (priceHitsArray[1, x] / (sessMaxHits)));

                yPos = chartScale.GetYByValue(price);

                vPos = yPos + slotHeight + halfslotHeight;
                if (SlotMinHeight == 0 && x != 0)
                    vPos = prevYpos;
                if (SlotMinHeight == -1 && x != 0)
                    vPos = prevYpos - 1;

                yPos = yPos - halfslotHeight;
                prevYpos = yPos;    //incase we continue here.
                if (yPos >= totalHeight || vPos <= 1)
                    continue;    //too low or high to display

                //take out any negitive portion
                yPos += (yPos < 0 ? yPos * -1 : 0);

                if (vPos > totalHeight)
                    vPos = totalHeight;
                vHeight = vPos - yPos;
                prevYpos = yPos;

                SharpDX.RectangleF rect = new SharpDX.RectangleF(leftMostPos + (totalWidth - hWidth), yPos, hWidth, vHeight);

                if (ScreenPosition == 1)
                    rect = new SharpDX.RectangleF(leftMostPos, yPos, hWidth, vHeight);

                RenderTarget.FillRectangle(rect, eBrush);
            }

            //draw evolving here if not daily (screenMapType > 0)
            if (ScreenMapType > 0)
            {
                if (ShowEvolvingPOCs >= 2)
                {
                    int leftPos = leftMostPos;    //defaults are screen %
                    int rightWidth = totalWidth;

                    if (ShowEvolvingPOCs == 3)
                    {    //show evolving lines full screen
                        leftPos = ChartPanel.X;
                        rightWidth = Convert.ToInt32(ChartPanel.Width);
                    }
                    if (EvolvingPOCColor != Brushes.Transparent)
                    {
                        SharpDX.RectangleF rect = new SharpDX.RectangleF(leftPos, chartScale.GetYByValue(sessPriceOfPOC), rightWidth, ELineHeight);
                        RenderTarget.FillRectangle(rect, ePOCBrush);
                    }
                    if (EvolvingVAbColor != Brushes.Transparent)
                    {
                        SharpDX.RectangleF rect = new SharpDX.RectangleF(leftPos, chartScale.GetYByValue(sessVAbot), rightWidth, ELineHeight);
                        RenderTarget.FillRectangle(rect, eVAbBrush);
                    }
                    if (EvolvingVAtColor != Brushes.Transparent)
                    {
                        SharpDX.RectangleF rect = new SharpDX.RectangleF(leftPos, chartScale.GetYByValue(sessVAtop), rightWidth, ELineHeight);
                        RenderTarget.FillRectangle(rect, eVAtBrush);
                    }
                }
                else if (ShowEvolvingPOCs == 1)
                {
                    DrawTextValue(chartScale, ePOCBrush, sessPriceOfPOC);
                    DrawTextValue(chartScale, eVAbBrush, sessVAbot);
                    DrawTextValue(chartScale, eVAtBrush, sessVAtop);
                }
            }
        }

        private void DrawTextValue(ChartScale chartScale, SharpDX.Direct2D1.Brush eBrush, double eValue)
        {
            int yPos = chartScale.GetYByValue(eValue) - (int)(ChartControl.Properties.LabelFont.Size * 0.5);
            int rightMostPos = ChartControl.GetXByBarIndex(ChartBars, Bars.Count + ETextPosition);

            int recWidth = (int)(ChartControl.Properties.LabelFont.Size * eValue.ToString(textForm).Length);

            SharpDX.DirectWrite.Factory fontFactory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Isolated);
            RenderTarget.DrawText(eValue.ToString(textForm), new SharpDX.DirectWrite.TextFormat(fontFactory, "Arial", 13f), new SharpDX.RectangleF(rightMostPos, yPos, recWidth, 100), eBrush);
        }

        private void NewSessStart()
        {
            //it's a new session, increment and calc POC from yesterday.
            if (!InclWeekendVol && (Time[1].DayOfWeek == DayOfWeek.Saturday || Time[1].DayOfWeek == DayOfWeek.Sunday))
                return;

            SetSessionBars(0);    //calc for just completed (1 session ago) session
            //Do this in any case to correct start,end times.
            SetCurSessEndTime();    //get current session End date/time, so we can compare on next bar, regardless.
            //cancel session increment with no live hrs. Sess bars
            if (sEndBnum - sStartBnum == 0)
            {    //nothing in Previous session
                //Print(Time[0] +" " +CurrentBar+" " +SesNum[0] +" No Live Session"  +" " +sStartBnum +" "+sEndBnum);
                return;
            }

            //increment session number.
            //SesNum's switch on first bar after last bar of defined session.
            //  They include any pre / post bars displayed, as well as open hours.
            sesNum[0] = sesNum[0] + 1;

            SetSessionBars(1);  //calc for Real (current bar excluded), just completed (1 session ago) session

            DetermineHL_BarRange();    //using previous call.

            if (!StuffHits_BarRange())
                return;

            vAtop = sessVAtop;
            vAbot = sessVAbot;
            priceOfPOC = sessPriceOfPOC;

        }

        protected override void OnBarUpdate()
        {
            if (CurrentBar < 3)
            {
                if (UseSessTemplate)
                {
                    if (CurrentBar == 0)
                        sessionIterator.GetNextSession(Time[0], true);

                    openHour = sessionIterator.ActualSessionBegin.Hour;
                    openMinute = sessionIterator.ActualSessionBegin.Minute;

                    SessionLengthHours = (sessionIterator.ActualSessionEnd - sessionIterator.ActualSessionBegin).TotalHours;
                }

                cSStartTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, openHour, openMinute, 0, 0, DateTimeKind.Utc);
                cSEndTime = cSStartTime.AddHours(SessionLengthHours);

                if (CurrentBar > 1)
                    SetCurSessEndTime();    //get it started (skip bad 1st bar data issue).

                sesNum[0] = 0;
                return;
            }

            sesNum[0] = sesNum[1];    //copy previous # for default.

            // (do on first (complete) bar, outside of session range. Show previous session.)
            if (Time[0].CompareTo(cSEndTime) > 0)
                NewSessStart();

            if (vAtop > 0.0 && ShowDailyPlots)
            {
                VAt[0] = vAtop;
                VAb[0] = vAbot;
                POC[0] = priceOfPOC;
            }

            //recalc for real time.
            if (ShowRtPOC && ShowDailyPlots)
            {
                SetSessionBars(0);    //current session

                if (Time[0].CompareTo(cSStartTime) <= 0)
                    SetPreSessBars(0);    // could be pre-session
                if (sEndBnum - sStartBnum == 0)
                    return;    //must have at least 2 bars

                DetermineHL_BarRange();

                if (!StuffHits_BarRange())
                    return;

                RtPOC[0] = sessPriceOfPOC;
            }
        }

        protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            base.OnRender(chartControl, chartScale);

            if (PresentMethod < 1 || BarsArray[0].Count < 2 || chartControl.SlotsPainted < 2 || IsInHitTest)
                return;

            int x;

            rightScrnBnum    = Math.Min(ChartBars.ToIndex, CurrentBar); //limit to actual bars vs. white space on right.
            leftScrnBnum    = Math.Min(ChartBars.FromIndex, CurrentBar); //not bigger than CurrentBar (ie. only 1 bar on screen).
         
            int leftMostSessNum        = sesNum.GetValueAt(leftScrnBnum);
            int rightMostSessNum    = sesNum.GetValueAt(rightScrnBnum);

            //set these globals 1x, before any calls that use them
            plotMin        = chartScale.MinValue;
            plotMax        = chartScale.MaxValue;
            plotMMDiff    = chartScale.MaxMinusMin; //don't know why we do it this way?

            // Find lowest screen price for ref to calc slot pix's.
            double chartLowPrice = double.MaxValue;
            for (int i = leftScrnBnum; i <= rightScrnBnum; i++)
                chartLowPrice = Math.Min(chartLowPrice, Bars.GetLow(i));

            int screenVLowPos = chartScale.GetYByValue(chartLowPrice);    //low value screen position

            //draw combo's or daily...
            if (ScreenPosition > 0 && ScreenMapType == 1)
            {
                //use bars on screen. Dispaly on right side.
                sEndBnum = (rightScrnBnum);
                sStartBnum = (leftScrnBnum);

                if (sEndBnum > sStartBnum)
                {//Have some bars, should be OK.
                    DetermineHL_BarRange();

                    if (!StuffHits_BarRange())
                        return;

                    //calc slot height for this BarRange (needed SlotHalfRange).
                    int slotVHeight = screenVLowPos - chartScale.GetYByValue(chartLowPrice + (slotHalfRange * 2.0));//-1;    //at least 1
                    if (slotVHeight < 1)
                        slotVHeight = 1;

                    DrawSlotsUV(chartScale, slotVHeight, 0, sessBrush);
                }
            }
            else if (ScreenPosition > 0 && ScreenMapType == 2)
            {
                //combine day's
                int oldestSnum = sesNum.GetValueAt(CurrentBar) - PreviousSessions;
                if (oldestSnum < 0)
                    oldestSnum = 0;

                SetSessBarDays(PreviousSessions);
                //SetSessionBars(SesNum[0] - x);
                if (sEndBnum > sStartBnum)
                {    //regular session should be OK.
                    DetermineHL_BarRange();

                    if (!StuffHits_BarRange())
                        return;

                    //calc slot height for this BarRange.
                    int slotVHeight = screenVLowPos - chartScale.GetYByValue(chartLowPrice + (slotHalfRange * 2.0));//-1;    //at least 1
                    if (slotVHeight < 1)
                        slotVHeight = 1;

                    DrawSlotsUV(chartScale, slotVHeight, oldestSnum, sessBrush);
                }
            }
            //daily stuff...
            else if (ScreenMapType == 0 && leftMostSessNum <= sesNum.GetValueAt(CurrentBar))
            {
                //current or previous session is in the display.
                //loop through screen dipslay day history            
                for (x = leftMostSessNum; x <= rightMostSessNum; x++)
                {
                    //do pre-session first
                    if (PresentMethod == 2)
                    {
                        SetSessionBars(sesNum.GetValueAt(CurrentBar) - x);    //have to do this first.
                        SetPreSessBars(sesNum.GetValueAt(CurrentBar) - x);

                        if (sEndBnum > sStartBnum)
                        {    //1st bar of presession, or presess hasn't started yet.

                            DetermineHL_BarRange();    //using previous call.
                            if (!StuffHits_BarRange())
                                continue;
                         
                            int SlotVHeight = screenVLowPos - chartScale.GetYByValue(chartLowPrice + (slotHalfRange * 2.0));
                            if (SlotVHeight < 1)
                                SlotVHeight = 1;    //at least 1

                            DrawSlotsUV(chartScale, SlotVHeight, x, preSessBrush);

                            if (ShowEvolvingPOCs > 1 && x == sesNum.GetValueAt(CurrentBar))
                            {
                                if (EvolvingPOCColor != Brushes.Transparent)
                                    DrawEvolving(sesNum.GetValueAt(CurrentBar), ePOCBrush, sessPriceOfPOC);
                                if (EvolvingVAbColor != Brushes.Transparent)
                                    DrawEvolving(sesNum.GetValueAt(CurrentBar), eVAbBrush, sessVAbot);
                                if (EvolvingVAtColor != Brushes.Transparent)
                                    DrawEvolving(sesNum.GetValueAt(CurrentBar), eVAtBrush, sessVAtop);
                            }
                        }
                    }

                    //now do defined session
                    SetSessionBars(sesNum.GetValueAt(CurrentBar) - x);
                    if (sEndBnum > sStartBnum)
                    {    //regular session should be OK.
                        DetermineHL_BarRange();    //using previous call.

                        if (!StuffHits_BarRange())
                            return;

                        //calc slot height for this BarRange.
                        int slotVHeight = screenVLowPos - chartScale.GetYByValue(chartLowPrice + (slotHalfRange * 2.0));
                        if (slotVHeight < 1)
                            slotVHeight = 1;

                        DrawSlotsUV(chartScale, slotVHeight, x, sessBrush);

                        if (ShowEvolvingPOCs > 1 && x == sesNum.GetValueAt(CurrentBar))
                        {
                            if (EvolvingPOCColor != Brushes.Transparent)
                                DrawEvolving(sesNum.GetValueAt(CurrentBar), ePOCBrush, sessPriceOfPOC);
                            if (EvolvingVAbColor != Brushes.Transparent)
                                DrawEvolving(sesNum.GetValueAt(CurrentBar), eVAbBrush, sessVAbot);
                            if (EvolvingVAtColor != Brushes.Transparent)
                                DrawEvolving(sesNum.GetValueAt(CurrentBar), eVAtBrush, sessVAtop);
                        }
                    }

                    //do text for either pre or reg session...
                    if (ShowEvolvingPOCs == 1 && x == sesNum.GetValueAt(CurrentBar))
                    {
                        DrawTextValue(chartScale, ePOCBrush, sessPriceOfPOC);
                        DrawTextValue(chartScale, eVAbBrush, sessVAbot);
                        DrawTextValue(chartScale, eVAtBrush, sessVAtop);
                    }
                }
            }
        }
     
        public override void OnRenderTargetChanged()
        {
            if (sessBrush != null)
                sessBrush.Dispose();

            if (preSessBrush != null)
                preSessBrush.Dispose();

            if (ePOCBrush != null)
                ePOCBrush.Dispose();

            if (eVAtBrush != null)
                eVAtBrush.Dispose();

            if (eVAbBrush != null)
                eVAbBrush.Dispose();

            if (RenderTarget != null)
            {
                try
                {
                    sessBrush        = SlotSessionColor.ToDxBrush(RenderTarget);
                    preSessBrush    = SlotPreSessionColor.ToDxBrush(RenderTarget);
                    ePOCBrush        = EvolvingPOCColor.ToDxBrush(RenderTarget);
                    eVAtBrush        = EvolvingVAtColor.ToDxBrush(RenderTarget);
                    eVAbBrush        = EvolvingVAbColor.ToDxBrush(RenderTarget);
                }
                catch (Exception e) { }
            }
        }

        private void SetCurSessEndTime()
        {
            double slenAdd = SessionLengthHours >= 24 ? 24.0 - 1.0 / 60.0 : SessionLengthHours;
            cSEndTime = cSStartTime.AddHours(slenAdd);
            while (cSEndTime.CompareTo(Time[0]) < 0)
            {    //already happened, so add days for catch (weekends)
                cSEndTime = cSEndTime.AddHours(24);
                cSStartTime = cSStartTime.AddHours(24);
            }
        }

        private void SetPreSessBars(int SessionAgo)
        {
            //reg session has to be set before this call.
            int sNum = sesNum.GetValueAt(CurrentBar) - SessionAgo;
            int x = 1;

            sEndBnum = sStartBnum - 1;

            for (x = CurrentBar - sEndBnum; x < CurrentBar; x++)
                if (sesNum.GetValueAt(CurrentBar - x) != sNum)
                    break;

            sStartBnum = CurrentBar - x + 1;

            //EBnum will be -1 from SBnum, if no pre-ses bars found.
        }

        private void SetSessBarDays(int DaysAgo)
        {
            //find start/end bars going back DaysAgo days (end is always CurrentBar)
            // days are really SesNum's.
            //have to have a default. Usefull if sessionago == 0.
            int sNum = sesNum.GetValueAt(CurrentBar) - DaysAgo;    //last sess num we car about
            if (sNum < 0)
                sNum = 0;            //not less than zero.

            sEndBnum = sStartBnum = CurrentBar;

            //now find first sNum bar, looking forwards
            for (int x = 1; x < CurrentBar; x++)
            {
                //start at oldest barago and go forwards
                if (sesNum.GetValueAt(x) == sNum)
                { // first bar of session range (could be pre - session)
                    sStartBnum = x; //combo's include pre-session, if part of chart.
                    break;
                }
            }
        }

        private void SetSessionBars(int SessionAgo)
        {
            //have to have a default. Usefull if sessionago == 0.
            DateTime StartTime = cSStartTime;
            DateTime EndTime;
            int sNum = sesNum.GetValueAt(CurrentBar) - SessionAgo;

            if (sNum == sesNum.GetValueAt(CurrentBar) || sNum < 0)
            {    //not a previous session
                sEndBnum = sStartBnum = CurrentBar;

                for (int x = CurrentBar; x > 0; x--)
                {
                    if (Bars.GetTime(x).CompareTo(StartTime) <= 0)
                    {
                        sStartBnum = x + 1;
                        break;
                    }
                    if (sesNum.GetValueAt(x) != sesNum.GetValueAt(CurrentBar))
                        break;
                }
            }
            else
            { //find and set pervious session date/times and barnumber range we care about.
                sStartBnum    = 1;
                sEndBnum    = 0;
             
                int y = 0;
                int z = 0;
                for (int x = 1; x < CurrentBar; x++)
                {
                    z = CurrentBar - x;

                    //start at newest barago and go backwards to catch right date
                    if (sEndBnum == 0 && sesNum.GetValueAt(z) == sNum)
                    {   // last bar of session range
                        //skip weekends? (Weekends are included with Mondays sess# when skipped)
                        sEndBnum = CurrentBar - x;// +1;
                                                  //use last bar of session count to set correct date/times of session.
                        StartTime = new DateTime(Bars.GetTime(z).Year, Bars.GetTime(z).Month, Bars.GetTime(z).Day, openHour, openMinute, 0, 0, DateTimeKind.Utc);
                        if (Bars.GetTime(z).CompareTo(StartTime) < 0) //it's a previous day, so subtract 24 hrs
                            StartTime = StartTime.AddHours(-24);
                        //keep going till we find the ses start.
                        EndTime = StartTime.AddHours(SessionLengthHours);

                        if (Bars.GetTime(z - 1).CompareTo(EndTime) > 0)
                        {   //no sess bars showing
                            sStartBnum = sEndBnum;
                            break;
                        }

                        for (y = x; y < CurrentBar; y++)
                        {
                            z = CurrentBar - y;
                            if (Bars.GetTime(z).CompareTo(StartTime) <= 0)
                            {
                                if (sesNum.GetValueAt(z) == sNum)
                                    sStartBnum = CurrentBar - y + 1;
                                else
                                    sStartBnum = sEndBnum;
                                break;
                            }
                        }
                    }

                    z = CurrentBar - x;

                    if (sEndBnum > 0 && Bars.GetTime(z).CompareTo(StartTime) <= 0)
                    {   // 1 bar too far.
                        sStartBnum = CurrentBar - x + 1;    //don't need pre-session bars.
                        break;  //end
                    }
                }

                if (sEndBnum == 0)
                    sEndBnum = CurrentBar;    //safety if havn't got there yet.
            }
        }

        private bool StuffHits_BarRange()
        {
            int x;

            int ticksInRange = (int)Math.Round((theSessionHigh - theSessionLow) / TickSize, 0);

            //fit ticks into array by so many TicksPerSlot
            ticksPerSlot = (ticksInRange / TotalSlots) + 1;    //should just drop the fract part.
            lastSlotUsed = ticksInRange / ticksPerSlot;    //Zero based, drop fract part.

            double comboSlotOffset;
            if (SlotMinHeight > 0)
            {
                slotHalfRange = ((TickSize * ticksPerSlot) - TickSize) / 2;
                comboSlotOffset = (ticksPerSlot > 1 ? slotHalfRange : 0);
            }
            else
            {
                slotHalfRange = ((TickSize * ticksPerSlot)) / 2;
                comboSlotOffset = (ticksPerSlot > 1 ? slotHalfRange - (((theSessionLow + ((lastSlotUsed + 1) * TickSize * ticksPerSlot)) - theSessionHigh) / 2) : 0);    //move down to center it.
            }

            //clear counts in any case.
            for (x = 0; x <= lastSlotUsed; x++)
            {
                // 0 -> 999, reset from bottom up.
                priceHitsArray[0, x] = (x * TickSize * ticksPerSlot) + comboSlotOffset; //Lowest Tick Value/Slot upped to mid value point
                priceHitsArray[0, x] += theSessionLow; //add it to the bottom
                priceHitsArray[1, x] = 0.0;    //clear counts per value.
            }

            if (ticksInRange > 0)
            {
                double    BarH;
                double    BarL;
                int        index = 0;

                int    i = sStartBnum;

                while (i <= sEndBnum)
                {
                    BarH = Bars.GetHigh(i);
                    BarL = Bars.GetLow(i);

                    if (ProfileType == _dValueEnums.dValueAreaTypes.VOC)
                    {
                        //Volume On Close - puts all the volume for that bar on the close price
                        index = (int)Math.Round((Bars.GetClose(i) - theSessionLow) / TickSize, 0);
                        index /= ticksPerSlot;  //drop fract part.
                        priceHitsArray[1, index] += Bars.GetVolume(i);
                    }

                    if (ProfileType == _dValueEnums.dValueAreaTypes.TPO)
                    {
                        //Time Price Opportunity - disregards volume, only counts number of times prices are touched
                        //BarH=High[i]; BarL=Low[i];
                        while (BarL <= BarH)
                        {
                            index = (int)Math.Round((BarL - theSessionLow) / TickSize, 0);  //ticks from bottom
                            index /= ticksPerSlot;  //drop fract part.
                            priceHitsArray[1, index] += 1;  //increment this value count.
                            BarL = BarL + TickSize; //up 1 tick
                        }
                    }

                    if (ProfileType == _dValueEnums.dValueAreaTypes.VWTPO)
                    {
                        //Volume Weighted Time Price Opportunity - Disperses the Volume of the bar over the range of the bar so each price touched is weighted with volume
                        //BarH=High[i]; BarL=Low[i];
                        int TicksInBar = (int)Math.Round((BarH - Bars.GetLow(i)) / TickSize + 1, 0);
                        while (BarL <= BarH)
                        {
                            index = (int)Math.Round((BarL - theSessionLow) / TickSize, 0);
                            index /= ticksPerSlot;  //drop fract part.
                            priceHitsArray[1, index] += Bars.GetVolume(i) / TicksInBar;
                            BarL = BarL + TickSize;
                        }
                    }

                    if (ProfileType == _dValueEnums.dValueAreaTypes.VTPO)
                    {
                        //Volume  Time Price Opportunity - Counts raw Volume
                        //BarH=High[i]; BarL=Low[i];
                        while (BarL <= BarH)
                        {
                            index = (int)Math.Round((BarL - theSessionLow) / TickSize, 0);
                            index /= ticksPerSlot;  //drop fract part.
                            priceHitsArray[1, index] += Bars.GetVolume(i);
                            BarL = BarL + TickSize;
                        }
                    }
                    i++;
                }
             

                //arrays are stuffed.
                //Calculate the Average price as weighted by the hit counts AND find the price with the highest hits (POC price)
                i = 0;
                double tHxP = 0.0; //Total of Hits multiplied by Price at that volume
                double hitsTotal = 0.0;
                sessPriceOfPOC = 0.0;
                sessMaxHits = 0.0;
                int pOCIndex = 0;    //track POC slot#

                double midPoint = theSessionLow + ((theSessionHigh - theSessionLow) * .5);
                double midUpCnt = 0, midDnCnt = 0;    //counts above/below midpoint.

                while (i <= lastSlotUsed)
                {    //Sum up Volume*Price in THxP...and sum up Volume in VolumeTotal
                    if (priceHitsArray[1, i] > 0.0)
                    {
                        tHxP += (priceHitsArray[1, i] * priceHitsArray[0, i]);
                        hitsTotal += priceHitsArray[1, i];
                        if (priceHitsArray[1, i] > sessMaxHits)
                        { //used to determine POC level
                            sessMaxHits = priceHitsArray[1, i];
                            sessPriceOfPOC = priceHitsArray[0, i];
                            pOCIndex = i;    //OK if only 1
                        }
                        //sum up hits for possable later use
                        if (priceHitsArray[0, i] > midPoint)
                            midUpCnt += priceHitsArray[1, i];    //don't count equals
                        if (priceHitsArray[0, i] < midPoint)
                            midDnCnt += priceHitsArray[1, i];
                    }
                    i++;
                }

                if (hitsTotal == 0)
                    return false;    //nothing to do.

                //now lowest (or only) sessMaxHits/POC is known.
                //determine in others match, and pick best choice.
                //
                //Rules to use are:
                // 1. If there is more than 1 price with the same 'most' TPO's then the price closest to the mid-point of the range (high - low) is used.
                // 2. If the 2 'most' TPO prices are equi-distance from the mid-point then the price on the side of the mid-point with the most TPO's is used.
                // 3. If there are equal number of TPO's on each side then the lower price is used.
                //
                int pOCcount = 0;
                double mid1 = midPoint, mid2 = midPoint;    //Distance from midPoint, set larger than possable
                int mid1Dx = 0, mid2Dx = 0;    //array index count of finds.

                i = 0;
                while (i <= lastSlotUsed)
                {    //scan known array from bottom to top
                    if (priceHitsArray[1, i] == sessMaxHits)
                    {    //should be at least 1.
                        pOCcount++;
                        //find 2 closest to midpoint
                        if (Math.Abs(midPoint - priceHitsArray[0, i]) <= mid1)
                        {
                            mid2 = mid1;//rotate next closest
                            mid2Dx = mid1Dx;
                            mid1 = Math.Abs(midPoint - priceHitsArray[0, i]);    //how far away from midpoint
                            mid1Dx = i;
                        }
                    }
                    i++;
                }

                if (pOCcount > 1)
                {
                    if (mid1 != mid2)
                    {    //found it, rule #1
                        sessPriceOfPOC = priceHitsArray[0, mid1Dx];
                        pOCIndex = mid1Dx;
                    }
                    else
                    {    //they are equal, Rule #2 may apply
                        if (midUpCnt == midDnCnt)
                        {    //must use Rule #3
                            sessPriceOfPOC = priceHitsArray[0, mid2Dx];    //use the lower.
                            pOCIndex = mid2Dx;
                        }
                        else
                        {    //Rule #2
                            if (midUpCnt > midDnCnt)
                            {
                                sessPriceOfPOC = priceHitsArray[0, mid1Dx];    //mid1 = upper of 2
                                pOCIndex = mid1Dx;
                            }
                            else
                            {
                                sessPriceOfPOC = priceHitsArray[0, mid2Dx];    //must be the lower.
                                pOCIndex = mid2Dx;
                            }
                        }//end Rule #2
                    }
                }
                //end of finding best fit for POC

                if (VACalcType == 1)
                {    //start mid-range and expand
                    //AvgPrice = THxP/HitsTotal;
                    sessVAtop = tHxP / hitsTotal;
                    sessVAbot = sessVAtop;

                    //This loop calculates the percentage of hits contained within the Value Area
                    double viA = 0.0;
                    double tV = 0.00001;
                    double adj = 0.0;
                    while (viA / tV < PctOfVolumeInVA)
                    {
                        sessVAbot = sessVAbot - adj;
                        sessVAtop = sessVAtop + adj;
                        viA = 0.0;
                        tV = 0.00001;
                        for (i = 0; i <= lastSlotUsed; i++)
                        {
                            if (priceHitsArray[0, i] > sessVAbot - adj && priceHitsArray[0, i] < sessVAtop + adj)
                                viA += priceHitsArray[1, i];
                            tV += priceHitsArray[1, i];
                        }
                        adj = TickSize;
                    }
                }
                else
                {    //start at POC Slot and expand by slots.
                    //start at POC and add largest of each side till done.
                    double viA = priceHitsArray[1, pOCIndex];
                    int upSlot = pOCIndex + 1, dnSlot = pOCIndex - 1;
                    double upCnt, dnCnt;

                    while (viA / hitsTotal < PctOfVolumeInVA)
                    {
                        if (upSlot <= lastSlotUsed)
                            upCnt = priceHitsArray[1, upSlot];
                        else upCnt = 0;
                        if (dnSlot >= 0)
                            dnCnt = priceHitsArray[1, dnSlot];
                        else dnCnt = 0;
                        if (upCnt == dnCnt)
                        {    //if both equal, add this one.
                            if (pOCIndex - dnSlot < upSlot - pOCIndex)
                                upCnt = 0;    //use closest
                            else
                                dnCnt = 0;    //use upper if the same.
                        }
                        if (upCnt >= dnCnt)
                        {    //if still equal (i.e. zero), do it.
                            viA += upCnt;
                            if (upSlot <= lastSlotUsed)
                                upSlot++;
                        }
                        if (upCnt <= dnCnt)
                        {    //need equals to increment counts.
                            viA += dnCnt;
                            if (dnSlot >= 0)
                                dnSlot--;
                        }
                        if (upSlot > lastSlotUsed && dnSlot < 0)
                        {    //error.
                            upSlot = lastSlotUsed;
                            dnSlot = 0;
                            break;
                        }
                    }
                    //index's have gone one too far...
                    sessVAtop = priceHitsArray[0, --upSlot];
                    sessVAbot = priceHitsArray[0, ++dnSlot];
                }
            }    //ticksinRange
            return true;
        }

        #region Properties
        [Range(1, 100)]
        [NinjaScriptProperty]
        [Display(Name = "Evolving Line Transparency", Order = 5, GroupName = "Display Settings")]
        public int ELineTransparency
        {
            get { return eLineTransparency; }
            set
            {
                eLineTransparency = value;

                Brush newBrush;

                if (evolvingPOCColor != null)
                {
                    newBrush = evolvingPOCColor.Clone();
                    newBrush.Opacity = eLineTransparency / 100d;
                    newBrush.Freeze();
                    evolvingPOCColor = newBrush;
                }

                if (evolvingVAtColor != null)
                {
                    newBrush = evolvingVAtColor.Clone();
                    newBrush.Opacity = eLineTransparency / 100d;
                    newBrush.Freeze();
                    evolvingVAtColor = newBrush;
                }

                if (evolvingVAbColor != null)
                {
                    newBrush = EvolvingVAbColor.Clone();
                    newBrush.Opacity = eLineTransparency / 100d;
                    newBrush.Freeze();
                    EvolvingVAbColor = newBrush;
                }
            }
        }

        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name="E-Text Decimals", Order = 1, GroupName="Display Settings")]
        public int ETextDecimals
        { get; set; }

        [Range(0, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "E-Text Position", Order = 2, GroupName = "Display Settings")]
        public int ETextPosition
        { get; set; }

        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "Evolving Line Height", Order = 4, GroupName = "Display Settings")]
        public int ELineHeight
        { get; set; }

        [XmlIgnore]
        [Display(Name = "Evolving POC Color", Order = 7, GroupName = "Display Settings")]
        public Brush EvolvingPOCColor
        {
            get { return evolvingPOCColor; }
            set
            {
                evolvingPOCColor = value;
                if (evolvingPOCColor == null)
                    return;

                if (evolvingPOCColor.IsFrozen)
                    evolvingPOCColor = evolvingPOCColor.Clone();

                evolvingPOCColor.Opacity = eLineTransparency / 100d;
                evolvingPOCColor.Freeze();
            }
        }

        [Browsable(false)]
        public string EvolvingPOCColorSerializable
        {
            get { return Serialize.BrushToString(EvolvingPOCColor); }
            set { EvolvingPOCColor = Serialize.StringToBrush(value); }
        }        

        [XmlIgnore]
        [Display(Name = "Evolving VAb Color", Order = 8, GroupName = "Display Settings")]
        public Brush EvolvingVAbColor
        {
            get { return evolvingVAbColor; }
            set
            {
                evolvingVAbColor = value;
                if (evolvingVAbColor == null)
                    return;

                if (evolvingVAbColor.IsFrozen)
                    evolvingVAbColor = evolvingVAbColor.Clone();

                evolvingVAbColor.Opacity = eLineTransparency / 100d;
                evolvingVAbColor.Freeze();
            }
        }

        [Browsable(false)]
        public string EvolvingVAbColorSerializable
        {
            get { return Serialize.BrushToString(EvolvingVAbColor); }
            set { EvolvingVAbColor = Serialize.StringToBrush(value); }
        }        

        [XmlIgnore]
        [Display(Name = "Evolving VAt Color", Order = 7, GroupName = "Display Settings")]
        public Brush EvolvingVAtColor
        {
            get { return evolvingVAtColor; }
            set
            {
                evolvingVAtColor = value;

                if (evolvingVAtColor == null)
                    return;

                if (evolvingVAtColor.IsFrozen)
                    evolvingVAtColor = evolvingVAtColor.Clone();

                evolvingVAtColor.Opacity = eLineTransparency / 100d;
                evolvingVAtColor.Freeze();
            }
        }

        [Browsable(false)]
        public string EvolvingVAtColorSerializable
        {
            get { return Serialize.BrushToString(EvolvingVAtColor); }
            set { EvolvingVAtColor = Serialize.StringToBrush(value); }
        }

        [NinjaScriptProperty]
        [Display(Name = "InclWeekendVol", Order = 1, GroupName = "Parameters", Description = "Include Weekend Volume")]
        public bool InclWeekendVol
        { get; set; }

        [XmlIgnore]
        [NinjaScriptProperty]
        [Display(Name = "Open Time", Order = 2, GroupName = "Parameters")]
        public TimeSpan OpenTime
        { get; set; }

        [Browsable(false)]
        public string OpenTimeSerializable
        {
            get { return OpenTime.ToString(); }
            set { OpenTime = TimeSpan.Parse(value); }
        }

        [Range(0, double.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "Percent of Volume in VA", Order = 6, GroupName = "Parameters")]
        public double PctOfVolumeInVA
        { get; set; }

        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "Present Method", Order = 4, GroupName = "Parameters")]
        public int PresentMethod
        { get; set; }

        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "PreviousSessions", Order = 5, GroupName = "Parameters")]
        public int PreviousSessions
        { get; set; }

        [NinjaScriptProperty]
        [Display(Name = "Profile Type", Order = 6, GroupName = "Parameters", Description = "Type of profile (VOC = Volume at Close, TPO = Price, VWTPO = Volume Weighted Price, VTPO = Volume)")]
        public _dValueEnums.dValueAreaTypes ProfileType
        { get; set; }

        [Range(0, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "ScreenMapType", Order = 8, GroupName = "Parameters")]
        public int ScreenMapType
        { get; set; }

        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "ScreenPercent", Order = 9, GroupName = "Parameters")]
        public int ScreenPercent
        { get; set; }

        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "ScreenPosition", Order = 10, GroupName = "Parameters")]
        public int ScreenPosition
        { get; set; }

        [Range(1, double.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "Session Length", Order = 5, GroupName = "Parameters", Description = "In hours")]
        public double SessionLengthHours
        { get; set; }

        [NinjaScriptProperty]
        [Display(Name = "Show Daily Plots", Order = 11, GroupName = "Parameters")]
        public bool ShowDailyPlots
        { get; set; }

        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "Show Evolving POCs", Order = 3, GroupName = "Display Settings")]
        public int ShowEvolvingPOCs
        { get; set; }

        [NinjaScriptProperty]
        [Display(Name = "Show Real-time POC", Order = 13, GroupName = "Display Settings")]
        public bool ShowRtPOC
        { get; set; }

        [Range(0, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "Slot Min Height", Order = 9, GroupName = "Display Settings")]
        public int SlotMinHeight
        { get; set; }

        [XmlIgnore]
        [Display(Name = "Slot Pre-session Color", Order = 11, GroupName = "Display Settings")]
        public Brush SlotPreSessionColor
        {
            get { return slotPreSessionColor; }
            set
            {
                slotPreSessionColor = value;

                if (slotPreSessionColor == null)
                    return;

                if (slotPreSessionColor.IsFrozen)
                    slotPreSessionColor = slotPreSessionColor.Clone();

                slotPreSessionColor.Opacity = slotTransparency / 100d;
                slotPreSessionColor.Freeze();
            }
        }

        [Browsable(false)]
        public string SlotPreSessionColorSerializable
        {
            get { return Serialize.BrushToString(SlotPreSessionColor); }
            set { SlotPreSessionColor = Serialize.StringToBrush(value); }
        }        

        [XmlIgnore]
        [Display(Name = "Slot Session Color", Order = 10, GroupName = "Display Settings")]
        public Brush SlotSessionColor
        {
            get { return slotSessionColor; }
            set
            {
                slotSessionColor = value;

                if (slotSessionColor == null)
                    return;

                if (slotSessionColor.IsFrozen)
                    slotSessionColor = slotSessionColor.Clone();

                slotSessionColor.Opacity = slotTransparency / 100d;
                slotSessionColor.Freeze();
            }
        }

        [Browsable(false)]
        public string SlotSessionColorSerializable
        {
            get { return Serialize.BrushToString(SlotSessionColor); }
            set { SlotSessionColor = Serialize.StringToBrush(value); }
        }        

        [Range(1, 100)]
        [NinjaScriptProperty]
        [Display(Name = "Slot Transparency", Order = 12, GroupName = "Display Settings")]
        public int SlotTransparency
        {
            get { return slotTransparency; }
            set
            {
                slotTransparency = value;

                Brush newBrush;

                if (slotSessionColor != null)
                {
                    newBrush = slotSessionColor.Clone();
                    newBrush.Opacity = slotTransparency / 100d;
                    newBrush.Freeze();
                    slotSessionColor = newBrush;
                }

                if (slotPreSessionColor != null)
                {
                    newBrush = slotPreSessionColor.Clone();
                    newBrush.Opacity = slotTransparency / 100d;
                    newBrush.Freeze();
                    slotPreSessionColor = newBrush;
                }
            }
        }

        [Range(1, int.MaxValue)]
        [NinjaScriptProperty]
        [Display(Name = "TotalSlots", Order = 12, GroupName = "Parameters")]
        public int TotalSlots
        { get; set; }

        [NinjaScriptProperty]
        [Display(Name = "Use Session Template", Order = 2, GroupName = "Parameters", Description = "Use Session Template for Open Hours and Length (Changes Input settings).")]
        public bool UseSessTemplate
        { get; set; }

        [Range(1, 2)]
        [NinjaScriptProperty]
        [Display(Name = "VACalcType", Order = 13, GroupName = "Parameters", Description = "Old (midrange based) or New (POC / Slot based) VA calc type (1=old, 2=new).")]
        public int VACalcType
        { get; set; }

        [NinjaScriptProperty]
        [Display(Name = "ZOrderPutBehind", Order = 15, GroupName = "Display Settings")]
        public bool ZOrderPutBehind
        { get; set; }

        [Browsable(false)]
        [XmlIgnore]
        public Series<double> RtPOC
        {
            get { return Values[0]; }
        }

        [Browsable(false)]
        [XmlIgnore]
        public Series<double> POC
        {
            get { return Values[1]; }
        }

        [Browsable(false)]
        [XmlIgnore]
        public Series<double> VAb
        {
            get { return Values[2]; }
        }

        [Browsable(false)]
        [XmlIgnore]
        public Series<double> VAt
        {
            get { return Values[3]; }
        }
        #endregion

    }
}

#region NinjaScript generated code. Neither change nor remove.

namespace NinjaTrader.NinjaScript.Indicators
{
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
        private DValueArea[] cacheDValueArea;
        public DValueArea DValueArea(int eLineTransparency, int eTextDecimals, int eTextPosition, int eLineHeight, bool inclWeekendVol, TimeSpan openTime, double pctOfVolumeInVA, int presentMethod, int previousSessions, _dValueEnums.dValueAreaTypes profileType, int screenMapType, int screenPercent, int screenPosition, double sessionLengthHours, bool showDailyPlots, int showEvolvingPOCs, bool showRtPOC, int slotMinHeight, int slotTransparency, int totalSlots, bool useSessTemplate, int vACalcType, bool zOrderPutBehind)
        {
            return DValueArea(Input, eLineTransparency, eTextDecimals, eTextPosition, eLineHeight, inclWeekendVol, openTime, pctOfVolumeInVA, presentMethod, previousSessions, profileType, screenMapType, screenPercent, screenPosition, sessionLengthHours, showDailyPlots, showEvolvingPOCs, showRtPOC, slotMinHeight, slotTransparency, totalSlots, useSessTemplate, vACalcType, zOrderPutBehind);
        }

        public DValueArea DValueArea(ISeries<double> input, int eLineTransparency, int eTextDecimals, int eTextPosition, int eLineHeight, bool inclWeekendVol, TimeSpan openTime, double pctOfVolumeInVA, int presentMethod, int previousSessions, _dValueEnums.dValueAreaTypes profileType, int screenMapType, int screenPercent, int screenPosition, double sessionLengthHours, bool showDailyPlots, int showEvolvingPOCs, bool showRtPOC, int slotMinHeight, int slotTransparency, int totalSlots, bool useSessTemplate, int vACalcType, bool zOrderPutBehind)
        {
            if (cacheDValueArea != null)
                for (int idx = 0; idx < cacheDValueArea.Length; idx++)
                    if (cacheDValueArea[idx] != null && cacheDValueArea[idx].ELineTransparency == eLineTransparency && cacheDValueArea[idx].ETextDecimals == eTextDecimals && cacheDValueArea[idx].ETextPosition == eTextPosition && cacheDValueArea[idx].ELineHeight == eLineHeight && cacheDValueArea[idx].InclWeekendVol == inclWeekendVol && cacheDValueArea[idx].OpenTime == openTime && cacheDValueArea[idx].PctOfVolumeInVA == pctOfVolumeInVA && cacheDValueArea[idx].PresentMethod == presentMethod && cacheDValueArea[idx].PreviousSessions == previousSessions && cacheDValueArea[idx].ProfileType == profileType && cacheDValueArea[idx].ScreenMapType == screenMapType && cacheDValueArea[idx].ScreenPercent == screenPercent && cacheDValueArea[idx].ScreenPosition == screenPosition && cacheDValueArea[idx].SessionLengthHours == sessionLengthHours && cacheDValueArea[idx].ShowDailyPlots == showDailyPlots && cacheDValueArea[idx].ShowEvolvingPOCs == showEvolvingPOCs && cacheDValueArea[idx].ShowRtPOC == showRtPOC && cacheDValueArea[idx].SlotMinHeight == slotMinHeight && cacheDValueArea[idx].SlotTransparency == slotTransparency && cacheDValueArea[idx].TotalSlots == totalSlots && cacheDValueArea[idx].UseSessTemplate == useSessTemplate && cacheDValueArea[idx].VACalcType == vACalcType && cacheDValueArea[idx].ZOrderPutBehind == zOrderPutBehind && cacheDValueArea[idx].EqualsInput(input))
                        return cacheDValueArea[idx];
            return CacheIndicator<DValueArea>(new DValueArea(){ ELineTransparency = eLineTransparency, ETextDecimals = eTextDecimals, ETextPosition = eTextPosition, ELineHeight = eLineHeight, InclWeekendVol = inclWeekendVol, OpenTime = openTime, PctOfVolumeInVA = pctOfVolumeInVA, PresentMethod = presentMethod, PreviousSessions = previousSessions, ProfileType = profileType, ScreenMapType = screenMapType, ScreenPercent = screenPercent, ScreenPosition = screenPosition, SessionLengthHours = sessionLengthHours, ShowDailyPlots = showDailyPlots, ShowEvolvingPOCs = showEvolvingPOCs, ShowRtPOC = showRtPOC, SlotMinHeight = slotMinHeight, SlotTransparency = slotTransparency, TotalSlots = totalSlots, UseSessTemplate = useSessTemplate, VACalcType = vACalcType, ZOrderPutBehind = zOrderPutBehind }, input, ref cacheDValueArea);
        }
    }
}

namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
        public Indicators.DValueArea DValueArea(int eLineTransparency, int eTextDecimals, int eTextPosition, int eLineHeight, bool inclWeekendVol, TimeSpan openTime, double pctOfVolumeInVA, int presentMethod, int previousSessions, _dValueEnums.dValueAreaTypes profileType, int screenMapType, int screenPercent, int screenPosition, double sessionLengthHours, bool showDailyPlots, int showEvolvingPOCs, bool showRtPOC, int slotMinHeight, int slotTransparency, int totalSlots, bool useSessTemplate, int vACalcType, bool zOrderPutBehind)
        {
            return indicator.DValueArea(Input, eLineTransparency, eTextDecimals, eTextPosition, eLineHeight, inclWeekendVol, openTime, pctOfVolumeInVA, presentMethod, previousSessions, profileType, screenMapType, screenPercent, screenPosition, sessionLengthHours, showDailyPlots, showEvolvingPOCs, showRtPOC, slotMinHeight, slotTransparency, totalSlots, useSessTemplate, vACalcType, zOrderPutBehind);
        }

        public Indicators.DValueArea DValueArea(ISeries<double> input , int eLineTransparency, int eTextDecimals, int eTextPosition, int eLineHeight, bool inclWeekendVol, TimeSpan openTime, double pctOfVolumeInVA, int presentMethod, int previousSessions, _dValueEnums.dValueAreaTypes profileType, int screenMapType, int screenPercent, int screenPosition, double sessionLengthHours, bool showDailyPlots, int showEvolvingPOCs, bool showRtPOC, int slotMinHeight, int slotTransparency, int totalSlots, bool useSessTemplate, int vACalcType, bool zOrderPutBehind)
        {
            return indicator.DValueArea(input, eLineTransparency, eTextDecimals, eTextPosition, eLineHeight, inclWeekendVol, openTime, pctOfVolumeInVA, presentMethod, previousSessions, profileType, screenMapType, screenPercent, screenPosition, sessionLengthHours, showDailyPlots, showEvolvingPOCs, showRtPOC, slotMinHeight, slotTransparency, totalSlots, useSessTemplate, vACalcType, zOrderPutBehind);
        }
    }
}

namespace NinjaTrader.NinjaScript.Strategies
{
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
        public Indicators.DValueArea DValueArea(int eLineTransparency, int eTextDecimals, int eTextPosition, int eLineHeight, bool inclWeekendVol, TimeSpan openTime, double pctOfVolumeInVA, int presentMethod, int previousSessions, _dValueEnums.dValueAreaTypes profileType, int screenMapType, int screenPercent, int screenPosition, double sessionLengthHours, bool showDailyPlots, int showEvolvingPOCs, bool showRtPOC, int slotMinHeight, int slotTransparency, int totalSlots, bool useSessTemplate, int vACalcType, bool zOrderPutBehind)
        {
            return indicator.DValueArea(Input, eLineTransparency, eTextDecimals, eTextPosition, eLineHeight, inclWeekendVol, openTime, pctOfVolumeInVA, presentMethod, previousSessions, profileType, screenMapType, screenPercent, screenPosition, sessionLengthHours, showDailyPlots, showEvolvingPOCs, showRtPOC, slotMinHeight, slotTransparency, totalSlots, useSessTemplate, vACalcType, zOrderPutBehind);
        }

        public Indicators.DValueArea DValueArea(ISeries<double> input , int eLineTransparency, int eTextDecimals, int eTextPosition, int eLineHeight, bool inclWeekendVol, TimeSpan openTime, double pctOfVolumeInVA, int presentMethod, int previousSessions, _dValueEnums.dValueAreaTypes profileType, int screenMapType, int screenPercent, int screenPosition, double sessionLengthHours, bool showDailyPlots, int showEvolvingPOCs, bool showRtPOC, int slotMinHeight, int slotTransparency, int totalSlots, bool useSessTemplate, int vACalcType, bool zOrderPutBehind)
        {
            return indicator.DValueArea(input, eLineTransparency, eTextDecimals, eTextPosition, eLineHeight, inclWeekendVol, openTime, pctOfVolumeInVA, presentMethod, previousSessions, profileType, screenMapType, screenPercent, screenPosition, sessionLengthHours, showDailyPlots, showEvolvingPOCs, showRtPOC, slotMinHeight, slotTransparency, totalSlots, useSessTemplate, vACalcType, zOrderPutBehind);
        }
    }
}

#endregion

DAILY PIVOTS

Code:
 //+----------------------------------------------------------------------------------------------+
//| Copyright © <2018>  <LizardIndicators.com - powered by AlderLab UG>
//
//| This program is free software: you can redistribute it and/or modify
//| it under the terms of the GNU General Public License as published by
//| the Free Software Foundation, either version 3 of the License, or
//| any later version.
//|
//| This program is distributed in the hope that it will be useful,
//| but WITHOUT ANY WARRANTY; without even the implied warranty of
//| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//| GNU General Public License for more details.
//|
//| By installing this software you confirm acceptance of the GNU
//| General Public License terms. You may find a copy of the license
//| here; http://www.gnu.org/licenses/
//+----------------------------------------------------------------------------------------------+

#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Core;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.NinjaScript.Indicators.LizardIndicators;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
using SharpDX.Direct2D1;
using SharpDX.DirectWrite;
#endregion


// This namespace holds indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators.LizardIndicators
{
    /// <summary>
    /// The Daily Pivots indicator can be used to display floor pivots, Globex pivots and the high, low and close of the prior day.
    /// </summary>
    ///
    [Gui.CategoryOrder("Algorithmic Options", 0)]
    [Gui.CategoryOrder("Display Options", 20)]
    [Gui.CategoryOrder("Data Series", 30)]
    [Gui.CategoryOrder("Set up", 40)]
    [Gui.CategoryOrder("Visual", 50)]
    [Gui.CategoryOrder("Plot Colors", 60)]
    [Gui.CategoryOrder("Plot Parameters", 70)]
    [Gui.CategoryOrder("Shaded Areas", 80)]
    [Gui.CategoryOrder("Version", 90)]
    [TypeConverter("NinjaTrader.NinjaScript.Indicators.amaPivotsDailyTypeConverter")]
    public class amaPivotsDaily : Indicator
    {
        private DateTime                            sessionDateTmp0                    = Globals.MinDate;
        private DateTime                            cacheSessionDate0                = Globals.MinDate;
        private DateTime                            sessionDateTmp1                    = Globals.MinDate;
        private DateTime                            dailyBarDate                    = Globals.MinDate;
        private DateTime                            priorDailyBarDate                = Globals.MinDate;
        private double                                currentDailyHigh                = 0.0;
        private double                                currentDailyLow                    = 0.0;
        private double                                currentDailyClose                = 0.0;
        private double                                priorDailyHigh                    = 0.0;
        private double                                priorDailyLow                    = 0.0;
        private double                                priorDailyClose                    = 0.0;
        private double                                priorHigh                        = 0.0;
        private double                                priorLow                        = 0.0;
        private double                                priorClose                        = 0.0;
        private double                                priorRange                        = 0.0;
        private    double                                pp                                = 0.0;
        private    double                                upside                            = 0.0;
        private    double                                downside                        = 0.0;
        private    double                                r1                                = 0.0;
        private    double                                s1                                = 0.0;
        private    double                                r2                                = 0.0;
        private    double                                s2                                = 0.0;
        private    double                                r3                                = 0.0;
        private    double                                s3                                = 0.0;
        private    double                                r4                                = 0.0;
        private    double                                s4                                = 0.0;
        private    double                                rmid                            = 0.0;
        private    double                                smid                            = 0.0;
        private    double                                r12mid                            = 0.0;
        private    double                                s12mid                            = 0.0;
        private    double                                r23mid                            = 0.0;
        private    double                                s23mid                            = 0.0;
        private    double                                r34mid                            = 0.0;
        private    double                                s34mid                            = 0.0;
        private    double                                cp                                = 0.0;
        private    double                                dp                                = 0.0;
        private double                                displaySize                        = 0.0;
        private int                                    displacement                    = 0;
        private int                                    count                            = 0;
        private int                                    cacheLastBarPainted                = 0;
        private bool                                showPP                            = true;
        private bool                                showCP                            = true;
        private bool                                showDP                            = true;
        private bool                                showPivots                        = true;
        private bool                                showPriorHLC                    = true;
        private bool                                showMidpivots                    = false;
        private bool                                showPivotRange                    = true;
        private bool                                showJacksonZones                = true;
        private bool                                showLabels                        = true;
        private bool                                isIntraday0                        = true;
        private bool                                calcOpen                        = false;
        private bool                                continuationTick                = false;
        private bool                                timeBased0                        = false;
        private bool                                breakAtEOD                        = true;
        private bool                                errorMessage                    = true;
        private bool                                basicError                        = false;
        private bool                                sundaySessionError                = false;
        private bool                                dailyBarsError                    = false;
        private bool                                initBarSeries0                    = false;
        private bool                                calculateFromPriceData            = true;
        private bool                                calculateFromIntradayData        = false;
        private bool                                lastBarStartsNewPeriod            = false;
        private amaPivotFormulaPD                    pivotFormula                    = amaPivotFormulaPD.Floor_Trader_Pivots;
        private amaSessionTypePD                    sessionType                        = amaSessionTypePD.Daily_Bars;
        private amaCalcModePD                        calcMode                        = amaCalcModePD.Daily_Data;
        private readonly List<int>                    newSessionBarIdxArr                = new List<int>();
        private SessionIterator                        sessionIterator0                = null;
        private System.Windows.Media.Brush            pivotBrush                        = Brushes.MidnightBlue;
        private System.Windows.Media.Brush            centralPivotBrush                = Brushes.MidnightBlue;
        private System.Windows.Media.Brush            directionalPivotBrush            = Brushes.MidnightBlue;
        private System.Windows.Media.Brush          resistanceBrush                    = Brushes.MidnightBlue;
        private System.Windows.Media.Brush            supportBrush                    = Brushes.MidnightBlue;
        private System.Windows.Media.Brush          resistanceMidBrush                = Brushes.MidnightBlue;
        private System.Windows.Media.Brush          supportMidBrush                    = Brushes.MidnightBlue;
        private System.Windows.Media.Brush            priorHighBrush                    = Brushes.DarkGreen;
        private System.Windows.Media.Brush            priorLowBrush                     = Brushes.Firebrick;
        private System.Windows.Media.Brush            priorCloseBrush                 = Brushes.DarkOrange;
        private System.Windows.Media.Brush            pivotRangeBrushS                = Brushes.RoyalBlue;
        private System.Windows.Media.Brush            centralRangeBrushS                = Brushes.DarkSlateGray;
        private System.Windows.Media.Brush            jacksonZonesBrushS                = Brushes.DarkSlateGray;
        private System.Windows.Media.Brush            pivotRangeBrush                    = null;
        private System.Windows.Media.Brush            centralRangeBrush                = null;
        private System.Windows.Media.Brush            jacksonZonesBrush                = null;
        private System.Windows.Media.Brush            errorBrush                        = Brushes.Black;
        private SharpDX.Direct2D1.Brush             pivotRangeBrushDX                 = null;
        private    SharpDX.Direct2D1.Brush             centralRangeBrushDX             = null;
        private    SharpDX.Direct2D1.Brush             jacksonZonesBrushDX                = null;
        private    SharpDX.Direct2D1.SolidColorBrush     transparentBrushDX                = null;
        private    SharpDX.Direct2D1.Brush[]             brushesDX                        = null;
        private SimpleFont                            errorFont                        = null;
        private string                                errorText1                        = "The amaPivotsDaily indicator only works on price data.";
        private string                                errorText2                        = "The amaPivotsDaily indicator cannot be used on weekly or monthly charts.";
        private string                                errorText3                        = "The amaPivotsDaily indicator cannot be used with a displacement.";
        private string                                errorText4                        = "The amaPivotsDaily indicator cannot be used when the Break EOD data series property is unselected.";
        private string                                errorText5                        = "The amaPivotsDaily indicator requires the setting 'DailyBars' when it is used on daily charts.";
        private string                                errorText6                        = "amaPivotsDaily: Pivots may not be calculated from fractional Sunday sessions. Please change your trading hours template.";
        private string                                errorText7                        = "amaPivotsDaily: Insufficient daily data! Please reload daily data or calculate pivots from intraday data.";
        private string                                errorText8                        = "amaPivotsDaily: Insufficient historical data. Please increase the chart look back period.";
        private int                                    pivotRangeOpacity                = 60;
        private int                                    centralRangeOpacity                = 60;
        private int                                    jacksonZonesOpacity                = 60;
        private int                                    plot0Width                        = 2;
        private int                                    plot1Width                        = 3;
        private int                                    plot2Width                        = 1;
        private int                                    textFontSize                    = 14;
        private int                                    shiftLabelOffset                = 10;
        private PlotStyle                            plot0Style                        = PlotStyle.Line;
        private DashStyleHelper                        dash0Style                        = DashStyleHelper.Solid;
        private PlotStyle                            plot1Style                        = PlotStyle.Line;
        private DashStyleHelper                        dash1Style                        = DashStyleHelper.Dot;
        private PlotStyle                            plot2Style                        = PlotStyle.Line;
        private DashStyleHelper                        dash2Style                        = DashStyleHelper.Dash;
        private string                                versionString                    = "v 2.6  -  July 4, 2018";
        private Series<DateTime>                    tradingDate0;
        private Series<DateTime>                    tradingDate1;
        private Series<int>                            countDown;
        private Series<double>                        currentHistoricalHigh;
        private Series<double>                        currentHistoricalLow;
        private Series<double>                        currentHistoricalClose;
        private Series<double>                        currentPrimaryBarsHigh;
        private Series<double>                        currentPrimaryBarsLow;
        private Series<double>                        currentPrimaryBarsClose;
 
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description                    = "\r\nThe Daily Pivots indicator can be used to display floor pivots, Globex pivots and the high, low and close of the prior day.";
                Name                        = "amaPivotsDaily";
                IsSuspendedWhileInactive    = false;
                IsOverlay                    = true;
                IsAutoScale                    = false;
                ArePlotsConfigurable        = false;
                if(Calculate == Calculate.OnEachTick)
                    Calculate = Calculate.OnPriceChange;
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"PP");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"CP");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"DP");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"R1");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"S1");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"R2");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"S2");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"R3");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"S3");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"R4");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"S4");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"Y-High");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"Y-Low");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"Y-Close");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"RMid");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"SMid");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"R12Mid");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"S12Mid");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"R23Mid");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"S23Mid");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"R34Mid");
                AddPlot(new Stroke(Brushes.Gray,1), PlotStyle.Hash,"S34Mid");
            }
            else if (State == State.Configure)
            {
                if(sessionType == amaSessionTypePD.Daily_Bars || calcMode == amaCalcModePD.Daily_Data)
                    AddDataSeries(BarsPeriodType.Day, 1);
                BarsRequiredToPlot = 3;
                displacement = Displacement;
                pivotRangeBrush = pivotRangeBrushS.Clone();
                pivotRangeBrush.Opacity = (float) pivotRangeOpacity/100.0;
                pivotRangeBrush.Freeze();
                centralRangeBrush = centralRangeBrushS.Clone();
                centralRangeBrush.Opacity = (float) centralRangeOpacity/100.0;
                centralRangeBrush.Freeze();
                jacksonZonesBrush = jacksonZonesBrushS.Clone();
                jacksonZonesBrush.Opacity = (float) jacksonZonesOpacity/100.0;
                jacksonZonesBrush.Freeze();
                if(showPP)
                    Plots[0].Brush = pivotBrush;
                else
                    Plots[0].Brush = Brushes.Transparent;
                if(showCP)
                    Plots[1].Brush = centralPivotBrush;
                else
                    Plots[1].Brush = Brushes.Transparent;
                if(showDP)
                    Plots[2].Brush = directionalPivotBrush;
                else
                    Plots[2].Brush = Brushes.Transparent;
                if(showPivots)
                {
                    Plots[3].Brush = resistanceBrush;
                    Plots[4].Brush = supportBrush;
                    Plots[5].Brush = resistanceBrush;
                    Plots[6].Brush = supportBrush;
                    Plots[7].Brush = resistanceBrush;
                    Plots[8].Brush = supportBrush;
                    Plots[9].Brush = resistanceBrush;
                    Plots[10].Brush = supportBrush;
                }
                else
                {
                    Plots[3].Brush = Brushes.Transparent;
                    Plots[4].Brush = Brushes.Transparent;
                    Plots[5].Brush = Brushes.Transparent;
                    Plots[6].Brush = Brushes.Transparent;
                    Plots[7].Brush = Brushes.Transparent;
                    Plots[8].Brush = Brushes.Transparent;
                    Plots[9].Brush = Brushes.Transparent;
                    Plots[10].Brush = Brushes.Transparent;
                }
                if(showPriorHLC)
                {
                    Plots[11].Brush = priorHighBrush;
                    Plots[12].Brush = priorLowBrush;
                    Plots[13].Brush = priorCloseBrush;
                }
                else
                {
                    Plots[11].Brush = Brushes.Transparent;
                    Plots[12].Brush = Brushes.Transparent;
                    Plots[13].Brush = Brushes.Transparent;
                }
                if(showMidpivots && pivotFormula != amaPivotFormulaPD.Jackson_Zones && pivotFormula != amaPivotFormulaPD.Fibonacci_Pivots)
                {
                    Plots[14].Brush = resistanceMidBrush;
                    Plots[15].Brush = supportMidBrush;
                    Plots[16].Brush = resistanceMidBrush;
                    Plots[17].Brush = supportMidBrush;
                    Plots[18].Brush = resistanceMidBrush;
                    Plots[19].Brush = supportMidBrush;
                    Plots[20].Brush = resistanceMidBrush;
                    Plots[21].Brush = supportMidBrush;
                }
                else
                {
                    Plots[14].Brush = Brushes.Transparent;
                    Plots[15].Brush = Brushes.Transparent;
                    Plots[16].Brush = Brushes.Transparent;
                    Plots[17].Brush = Brushes.Transparent;
                    Plots[18].Brush = Brushes.Transparent;
                    Plots[19].Brush = Brushes.Transparent;
                    Plots[20].Brush = Brushes.Transparent;
                    Plots[21].Brush = Brushes.Transparent;
                }
                for (int i = 0; i < 11; i++)
                {
                    Plots[i].Width = plot0Width;
                    Plots[i].DashStyleHelper = dash0Style;
                }
                for (int i = 11; i < 14; i++)
                {
                    Plots[i].Width = plot1Width;
                    Plots[i].DashStyleHelper = dash1Style;
                }
                for (int i = 14; i < 22; i++)
                {
                    Plots[i].Width = plot2Width;
                    Plots[i].DashStyleHelper = dash2Style;
                }
                if (pivotFormula == amaPivotFormulaPD.Jackson_Zones)
                {
                    Plots[3].Name = "R1";
                    Plots[4].Name = "S1";
                    Plots[5].Name = "RB1";
                    Plots[6].Name = "SB1";
                    Plots[7].Name = "R2";
                    Plots[8].Name = "S2";
                    Plots[9].Name = "RB2";
                    Plots[10].Name = "SB2";
                }
                else
                {
                    Plots[3].Name = "R1";
                    Plots[4].Name = "S1";
                    Plots[5].Name = "R2";
                    Plots[6].Name = "S2";
                    Plots[7].Name = "R3";
                    Plots[8].Name = "S3";
                    Plots[9].Name = "R4";
                    Plots[10].Name = "S4";
                }
                brushesDX = new SharpDX.Direct2D1.Brush[Values.Length];
            }
              else if (State == State.DataLoaded)
             {
                if(BarsArray[0].BarsType.IsIntraday)
                    isIntraday0 = true;
                else
                    isIntraday0 = false;
                tradingDate0 = new Series<DateTime>(BarsArray[0], MaximumBarsLookBack.TwoHundredFiftySix);
                countDown = new Series<int>(BarsArray[0], MaximumBarsLookBack.TwoHundredFiftySix);
                if(isIntraday0 && (sessionType == amaSessionTypePD.Daily_Bars || calcMode == amaCalcModePD.Daily_Data))
                {
                    tradingDate1 = new Series<DateTime>(BarsArray[1], MaximumBarsLookBack.TwoHundredFiftySix);
                    currentHistoricalHigh = new Series<double>(BarsArray[0], MaximumBarsLookBack.TwoHundredFiftySix);
                    currentHistoricalLow = new Series<double>(BarsArray[0], MaximumBarsLookBack.TwoHundredFiftySix);
                    currentHistoricalClose = new Series<double>(BarsArray[0], MaximumBarsLookBack.TwoHundredFiftySix);
                }
                if((isIntraday0 && sessionType != amaSessionTypePD.Daily_Bars) || !isIntraday0)
                {
                    currentPrimaryBarsHigh = new Series<double>(BarsArray[0], MaximumBarsLookBack.TwoHundredFiftySix);
                    currentPrimaryBarsLow = new Series<double>(BarsArray[0], MaximumBarsLookBack.TwoHundredFiftySix);
                    currentPrimaryBarsClose = new Series<double>(BarsArray[0], MaximumBarsLookBack.TwoHundredFiftySix);
                }
                if (Instrument.MasterInstrument.InstrumentType == InstrumentType.Forex && (TickSize == 0.00001 || TickSize == 0.001))
                    displaySize = 5 * TickSize;
                else
                    displaySize = TickSize;
                if (BarsArray[0].BarsType.IsTimeBased)
                    timeBased0 = true;
                else
                    timeBased0 = false;
                if(Input is PriceSeries)
                    calculateFromPriceData = true;
                else
                    calculateFromPriceData = false;
                if(calcMode    != amaCalcModePD.Daily_Data && sessionType != amaSessionTypePD.Daily_Bars)
                    calculateFromIntradayData = true;
                else
                    calculateFromIntradayData = false;
                sessionIterator0 = new SessionIterator(BarsArray[0]);
              }
            else if (State == State.Historical)
            {
                if(ChartBars != null)
                {
                    breakAtEOD = ChartBars.Bars.IsResetOnNewTradingDay;
                    errorBrush = ChartControl.Properties.AxisPen.Brush;
                    errorBrush.Freeze();
                    errorFont = new SimpleFont("Arial", 24);
                }
                this.ZOrder = -2; //SetZOrder(-2);
                errorMessage = false;
                if(!calculateFromPriceData)
                {
                    Draw.TextFixed(this, "error text 1", errorText1, TextPosition.Center, errorBrush, errorFont, Brushes.Transparent, Brushes.Transparent, 0);
                    errorMessage = true;
                    basicError = true;
                }
                else if(BarsArray[0].BarsPeriod.BarsPeriodType == BarsPeriodType.Week || BarsArray[0].BarsPeriod.BarsPeriodType == BarsPeriodType.Month)
                {
                    Draw.TextFixed(this, "error text 2", errorText2, TextPosition.Center, errorBrush, errorFont, Brushes.Transparent, Brushes.Transparent, 0);
                    errorMessage = true;
                    basicError = true;
                }
                else if(displacement != 0)
                {
                    Draw.TextFixed(this, "error text 3", errorText3, TextPosition.Center, errorBrush, errorFont, Brushes.Transparent, Brushes.Transparent, 0);
                    errorMessage = true;
                    basicError = true;
                }
                else if(!breakAtEOD)
                {
                    Draw.TextFixed(this, "error text 4", errorText4, TextPosition.Center, errorBrush, errorFont, Brushes.Transparent, Brushes.Transparent, 0);
                    errorMessage = true;
                    basicError = true;
                }
                else if (!isIntraday0 && sessionType != amaSessionTypePD.Daily_Bars)
                {
                    Draw.TextFixed(this, "error text 5", errorText5, TextPosition.Center, errorBrush, errorFont, Brushes.Transparent, Brushes.Transparent, 0);
                    errorMessage = true;
                    basicError = true;
                }
            }
        }

        protected override void OnBarUpdate()
        {
            if(BarsInProgress == 0)
            {
                if(IsFirstTickOfBar)
                {
                    if(errorMessage)
                    {
                        if(basicError)
                            return;
                        else if(sundaySessionError)
                        {
                            Draw.TextFixed(this, "error text 6", errorText6, TextPosition.Center, errorBrush, errorFont, Brushes.Transparent, Brushes.Transparent, 0);
                            return;
                        }
                        else if(dailyBarsError)
                        {
                            Draw.TextFixed(this, "error text 7", errorText7, TextPosition.Center, errorBrush, errorFont, Brushes.Transparent, Brushes.Transparent, 0);
                            return;
                        }
                    }
                }
                 
                if (!initBarSeries0 || CurrentBars[0] == 0)
                {
                    if(!initBarSeries0)
                    {
                        tradingDate0[0] = GetLastBarSessionDate0(Times[0][0]);
                        countDown[0] = 2;
                        if(isIntraday0 && (sessionType == amaSessionTypePD.Daily_Bars || calcMode == amaCalcModePD.Daily_Data))
                        {
                            currentHistoricalHigh.Reset();
                            currentHistoricalLow.Reset();
                            currentHistoricalClose.Reset();
                        }
                        if((isIntraday0 && sessionType != amaSessionTypePD.Daily_Bars) || !isIntraday0)
                        {
                            currentPrimaryBarsHigh.Reset();
                            currentPrimaryBarsLow.Reset();
                            currentPrimaryBarsClose.Reset();
                        }
                        PP.Reset();
                        CP.Reset();
                        DP.Reset();
                        R1.Reset();
                        S1.Reset();
                        R2.Reset();
                        S2.Reset();
                        R3.Reset();
                        S3.Reset();
                        R4.Reset();
                        S4.Reset();
                        PriorHigh.Reset();
                        PriorLow.Reset();
                        PriorClose.Reset();
                        RMid.Reset();
                        SMid.Reset();
                        R12Mid.Reset();
                        S12Mid.Reset();
                        R23Mid.Reset();
                        S23Mid.Reset();
                        R34Mid.Reset();
                        S34Mid.Reset();
                        initBarSeries0 = true;
                    }
                    return;
                }
             
                if(IsFirstTickOfBar)
                {
                    if(BarsArray[0].IsFirstBarOfSession || !isIntraday0)
                    {
                        tradingDate0[0] = GetLastBarSessionDate0(Times[0][0]);
                        if(tradingDate0[0].DayOfWeek == DayOfWeek.Sunday)
                        {
                            sundaySessionError = true;
                            errorMessage = true;
                            return;
                        }
                        if(tradingDate0[0] != tradingDate0[1])
                        {
                            if((sessionType == amaSessionTypePD.Daily_Bars || calcMode == amaCalcModePD.Daily_Data) && CurrentBars[1] < 0)
                                dailyBarsError = true;
                            else
                                dailyBarsError = false;
                            countDown[0] = countDown[1] - 1;
                            if(countDown[0] <= 0) // calculations are only performed for the third day with intraday data (first day maybe incomplete, second day is needed for collecting data)
                            {
                                if (dailyBarsError)
                                {
                                    errorMessage = true;
                                    return;
                                }
                                if(!isIntraday0) // daily pivots displayed on a daily chart
                                {
                                    priorHigh = currentPrimaryBarsHigh[1];
                                    priorLow = currentPrimaryBarsLow[1];
                                    priorClose = currentPrimaryBarsClose[1];
                                }
                                else if(sessionType == amaSessionTypePD.Daily_Bars) // daily pivots calculated from daily data
                                {
                                    if(IsConnected())
                                    {
                                        if(tradingDate0[0] > tradingDate1[0])
                                        {
                                            priorHigh = currentDailyHigh;
                                            priorLow = currentDailyLow;
                                            priorClose = currentDailyClose;
                                        }
                                        else
                                        {
                                            priorHigh = priorDailyHigh;
                                            priorLow = priorDailyLow;
                                            priorClose = priorDailyClose;
                                        }
                                    }
                                    else // workaround needed because of NinjaTrader bar processing bug
                                    {
                                        priorHigh = currentHistoricalHigh[1];
                                        priorLow = currentHistoricalLow[1];
                                        priorClose = currentHistoricalClose[1];
                                        count = 0;
                                        priorDailyBarDate = BarsArray[1].GetTime(BarsArray[1].GetBar(Times[0][1]));
                                        dailyBarDate = BarsArray[1].GetTime(BarsArray[1].GetBar(Times[0][0]));
                                        if(priorDailyBarDate == dailyBarDate && BarsArray[1].Count - 2 > CurrentBars[1])
                                        {
                                            while (priorDailyBarDate >= dailyBarDate)
                                            {
                                                count = count - 1;
                                                priorDailyBarDate = BarsArray[1].GetTime(BarsArray[1].GetBar(Times[0][1].AddDays(count)));
                                                if (count == -5)
                                                    break;
                                            }
                                            priorHigh = BarsArray[1].GetHigh(BarsArray[1].GetBar(Times[0][1].AddDays(count)));
                                            priorLow = BarsArray[1].GetLow(BarsArray[1].GetBar(Times[0][1].AddDays(count)));
                                            priorClose = BarsArray[1].GetClose(BarsArray[1].GetBar(Times[0][1].AddDays(count)));
                                        }
                                    }
                                }
                                else if(calcMode == amaCalcModePD.Daily_Data) // daily pivots calculated with highs and low taken from intraday data, but daily close taken from daily data
                                {
                                    priorHigh = currentPrimaryBarsHigh[1];
                                    priorLow = currentPrimaryBarsLow[1];
                                    if(IsConnected())
                                    {
                                        if(tradingDate0[0] > tradingDate1[0])
                                            priorClose = currentDailyClose;
                                        else
                                            priorClose = priorDailyClose;
                                    }
                                    else // workaround needed because of NinjaTrader bar processing bug
                                    {
                                        priorClose = currentHistoricalClose[1];
                                        count = 0;
                                        priorDailyBarDate = BarsArray[1].GetTime(BarsArray[1].GetBar(Times[0][1]));
                                        dailyBarDate = BarsArray[1].GetTime(BarsArray[1].GetBar(Times[0][0]));
                                        if(priorDailyBarDate == dailyBarDate && BarsArray[1].Count - 2 > CurrentBars[1])
                                        {
                                            while (priorDailyBarDate >= dailyBarDate)
                                            {
                                                count = count - 1;
                                                priorDailyBarDate = BarsArray[1].GetTime(BarsArray[1].GetBar(Times[0][1].AddDays(count)));
                                                if (count == -5)
                                                    break;
                                            }
                                            priorClose = BarsArray[1].GetClose(BarsArray[1].GetBar(Times[0][1].AddDays(count)));
                                        }
                                    }
                                }
                                else // daily pivots calculated from intraday data
                                {
                                    priorHigh = currentPrimaryBarsHigh[1];
                                    priorLow = currentPrimaryBarsLow[1];
                                    priorClose = currentPrimaryBarsClose[1];
                                }
                                pp                = (priorHigh + priorLow + priorClose)/3.0;
                                cp                = (priorHigh + priorLow) / 2.0;
                                priorRange         = priorHigh - priorLow;                    
                                upside          = pp - priorLow;
                                downside        = priorHigh - pp;
                                if(pivotFormula == amaPivotFormulaPD.Floor_Trader_Pivots)
                                {
                                    r1        = pp + upside;
                                    s1        = pp - downside;
                                    r2        = pp + priorRange;
                                    s2        = pp - priorRange;
                                    r3        = r1 + priorRange;
                                    s3        = s1 - priorRange;
                                    r4        = r3 + upside;
                                    s4        = s3 - downside;
                                }
                                else if (pivotFormula == amaPivotFormulaPD.Wide_Pivots)
                                {
                                    r1        = pp + upside;
                                    s1        = pp - downside;
                                    r2        = pp + priorRange;
                                    s2        = pp - priorRange;
                                    r3        = r2 + priorRange;
                                    s3        = s2 - priorRange;
                                    r4        = r3 + priorRange;
                                    s4        = s3 - priorRange;
                                }
                                else if (pivotFormula == amaPivotFormulaPD.Jackson_Zones)
                                {
                                    r1        = pp + 0.5*priorRange;
                                    s1        = pp - 0.5*priorRange;
                                    r2        = pp + 0.618*priorRange;
                                    s2        = pp - 0.618*priorRange;
                                    r3        = pp + priorRange;
                                    s3        = pp - priorRange;
                                    r4        = pp + 1.382*priorRange;
                                    s4        = pp - 1.382*priorRange;
                                }
                                else if (pivotFormula == amaPivotFormulaPD.Fibonacci_Pivots)
                                {
                                    r1        = pp + 0.382*priorRange;
                                    s1        = pp - 0.382*priorRange;
                                    r2        = pp + 0.618*priorRange;
                                    s2        = pp - 0.618*priorRange;
                                    r3        = pp + priorRange;
                                    s3        = pp - priorRange;
                                    r4        = pp + 1.382*priorRange;
                                    s4        = pp - 1.382*priorRange;
                                }
                                rmid        = 0.5*(pp+r1);
                                smid        = 0.5*(pp+s1);
                                r12mid        = 0.5*(r1+r2);
                                s12mid        = 0.5*(s1+s2);
                                r23mid        = 0.5*(r2+r3);
                                s23mid        = 0.5*(s2+s3);
                                r34mid        = 0.5*(r3+r4);
                                s34mid        = 0.5*(s3+s4);
                                if(countDown[0] <= 0)
                                {
                                    PP[0] = Math.Round(pp/displaySize) * displaySize;
                                    CP[0] = Math.Round((cp + 0.01*displaySize)/displaySize)*displaySize;
                                    DP[0] = 2.0*PP[0] - CP[0];
                                    R1[0] = Math.Round(r1/displaySize) * displaySize;
                                    S1[0] = Math.Round(s1/displaySize) * displaySize;
                                    R2[0] = Math.Round(r2/displaySize) * displaySize;
                                    S2[0] = Math.Round(s2/displaySize) * displaySize;
                                    R3[0] = Math.Round(r3/displaySize) * displaySize;
                                    S3[0] = Math.Round(s3/displaySize) * displaySize;
                                    R4[0] = Math.Round(r4/displaySize) * displaySize;
                                    S4[0] = Math.Round(s4/displaySize) * displaySize;
                                    PriorHigh[0] = priorHigh;
                                    PriorLow[0] = priorLow;
                                    PriorClose[0] = priorClose;
                                    RMid[0] = Math.Round(rmid/displaySize)* displaySize;
                                    SMid[0] = Math.Round(smid/displaySize)* displaySize;
                                    R12Mid[0] = Math.Round(r12mid/displaySize)* displaySize;
                                    S12Mid[0] = Math.Round(s12mid/displaySize)* displaySize;
                                    R23Mid[0] = Math.Round(r23mid/displaySize)* displaySize;
                                    S23Mid[0] = Math.Round(s23mid/displaySize)* displaySize;
                                    R34Mid[0] = Math.Round(r34mid/displaySize)* displaySize;
                                    S34Mid[0] = Math.Round(s34mid/displaySize)* displaySize;
                                }
                            }
                        }
                        else // case where Bars.IsFirstBarOfSession is true inside the trading day
                        {
                            tradingDate0[0] = tradingDate0[1];
                            countDown[0] = countDown[1];
                            if (countDown[0] <= 0)
                            {
                                PP[0] = PP[1];
                                CP[0] = CP[1];
                                DP[0] = DP[1];
                                R1[0] = R1[1];
                                S1[0] = S1[1];
                                R2[0] = R2[1];
                                S2[0] = S2[1];
                                R3[0] = R3[1];
                                S3[0] = S3[1];
                                R4[0] = R4[1];
                                S4[0] = S4[1];
                                PriorHigh[0] = PriorHigh[1];
                                PriorLow[0] = PriorLow[1];
                                PriorClose[0] = PriorClose[1];
                                RMid[0] = RMid[1];
                                SMid[0] = SMid[1];
                                R12Mid[0] = R12Mid[1];
                                S12Mid[0] = S12Mid[1];
                                R23Mid[0] = R23Mid[1];
                                S23Mid[0] = S23Mid[1];
                                R34Mid[0] = R34Mid[1];
                                S34Mid[0] = S34Mid[1];
                            }
                        }
                    }
                    else // case where Bars.IsFirstBarOfSession is false
                    {
                        tradingDate0[0] = tradingDate0[1];
                        countDown[0] = countDown[1];
                        if (countDown[0] <= 0)
                        {
                            PP[0] = PP[1];
                            CP[0] = CP[1];
                            DP[0] = DP[1];
                            R1[0] = R1[1];
                            S1[0] = S1[1];
                            R2[0] = R2[1];
                            S2[0] = S2[1];
                            R3[0] = R3[1];
                            S3[0] = S3[1];
                            R4[0] = R4[1];
                            S4[0] = S4[1];
                            PriorHigh[0] = PriorHigh[1];
                            PriorLow[0] = PriorLow[1];
                            PriorClose[0] = PriorClose[1];
                            RMid[0] = RMid[1];
                            SMid[0] = SMid[1];
                            R12Mid[0] = R12Mid[1];
                            S12Mid[0] = S12Mid[1];
                            R23Mid[0] = R23Mid[1];
                            S23Mid[0] = S23Mid[1];
                            R34Mid[0] = R34Mid[1];
                            S34Mid[0] = S34Mid[1];
                        }
                    }
                 
                    if(countDown[0] > 0)
                    {
                        PP.Reset();
                        CP.Reset();
                        DP.Reset();
                        R1.Reset();
                        S1.Reset();
                        R2.Reset();
                        S2.Reset();
                        R3.Reset();
                        S3.Reset();
                        R4.Reset();
                        S4.Reset();
                        PriorHigh.Reset();
                        PriorLow.Reset();
                        PriorClose.Reset();
                        RMid.Reset();
                        SMid.Reset();
                        R12Mid.Reset();
                        S12Mid.Reset();
                        R23Mid.Reset();
                        S23Mid.Reset();
                        R34Mid.Reset();
                        S34Mid.Reset();
                    }
                 
                    // needed as a workaround for NinjaTrader bar processing bug
                    if(isIntraday0 && (sessionType == amaSessionTypePD.Daily_Bars || calcMode == amaCalcModePD.Daily_Data) && CurrentBars[1] >= 0)
                    {
                        if(CurrentBars[1] >= 0)
                        {
                            currentHistoricalHigh[0] = BarsArray[1].GetHigh(BarsArray[1].GetBar(Times[0][0]));
                            currentHistoricalLow[0] = BarsArray[1].GetLow(BarsArray[1].GetBar(Times[0][0]));
                            currentHistoricalClose[0] = BarsArray[1].GetClose(BarsArray[1].GetBar(Times[0][0]));
                        }
                        else
                        {
                            currentHistoricalHigh.Reset();
                            currentHistoricalLow.Reset();
                            currentHistoricalClose.Reset();
                        }
                    }
                }
             
                if((isIntraday0 && sessionType != amaSessionTypePD.Daily_Bars) || !isIntraday0)
                {
                    if (tradingDate0[0] != tradingDate0[1])
                    {
                        currentPrimaryBarsHigh[0]    = Highs[0][0];
                        currentPrimaryBarsLow[0]     = Lows[0][0];
                        currentPrimaryBarsClose[0]    = Closes[0][0];
                    }
                    else
                    {
                        currentPrimaryBarsHigh[0]    = Math.Max(currentPrimaryBarsHigh[1], Highs[0][0]);
                        currentPrimaryBarsLow[0]     = Math.Min(currentPrimaryBarsLow[1], Lows[0][0]);
                        currentPrimaryBarsClose[0]    = Closes[0][0];
                    }
                }
            }
             
            if(BarsInProgress == 1 && isIntraday0)
            {
                if(CurrentBars[1] == 0)
                {
                    if(IsFirstTickOfBar)
                        tradingDate1[0] = GetLastBarSessionDate1(Times[1][0]);
                    currentDailyHigh    = Highs[1][0];
                    currentDailyLow         = Lows[1][0];
                    currentDailyClose    = Closes[1][0];
                    return;
                }
             
                if(IsFirstTickOfBar)
                {
                    tradingDate1[0] = GetLastBarSessionDate1(Times[1][0]);
                    if(tradingDate1[0] != tradingDate1[1])
                    {
                        priorDailyHigh         = currentDailyHigh;
                        priorDailyLow          = currentDailyLow;
                        priorDailyClose     = currentDailyClose;
                        currentDailyHigh    = Highs[1][0];
                        currentDailyLow         = Lows[1][0];
                        currentDailyClose    = Closes[1][0];
                    }
                    else
                    {
                        currentDailyHigh    = Math.Max(currentDailyHigh, Highs[1][0]);
                        currentDailyLow         = Math.Min(currentDailyLow, Lows[1][0]);
                        currentDailyClose    = Closes[1][0];
                    }
                }
                else
                {
                    currentDailyHigh    = Math.Max(currentDailyHigh, Highs[1][0]);
                    currentDailyLow         = Math.Min(currentDailyLow, Lows[1][0]);
                    currentDailyClose    = Closes[1][0];
                }
            }
        }
     
        #region Properties
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> PP
        {
            get { return Values[0]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> CP
        {
            get { return Values[1]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> DP
        {
            get { return Values[2]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> R1
        {
            get { return Values[3]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> S1
        {
            get { return Values[4]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> R2
        {
            get { return Values[5]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> S2
        {
            get { return Values[6]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> R3
        {
            get { return Values[7]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> S3
        {
            get { return Values[8]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> R4
        {
            get { return Values[9]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> S4
        {
            get { return Values[10]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> PriorHigh
        {
            get { return Values[11]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> PriorLow
        {
            get { return Values[12]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> PriorClose
        {
            get { return Values[13]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> RMid
        {
            get { return Values[14]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> SMid
        {
            get { return Values[15]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> R12Mid
        {
            get { return Values[16]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> S12Mid
        {
            get { return Values[17]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> R23Mid
        {
            get { return Values[18]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> S23Mid
        {
            get { return Values[19]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> R34Mid
        {
            get { return Values[20]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> S34Mid
        {
            get { return Values[21]; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public int CacheLastBarPainted
        {
            get { return cacheLastBarPainted; }
            set { cacheLastBarPainted = value; }
        }
     
        [Browsable(false)]
        [XmlIgnore()]
        public bool LastBarStartsNewPeriod
        {
            get { return lastBarStartsNewPeriod; }
            set { lastBarStartsNewPeriod = value; }
        }

        [NinjaScriptProperty]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Pivot formula", Description = "Select formula for calculating the pivots", GroupName = "Algorithmic Options", Order = 0)]
         [RefreshProperties(RefreshProperties.All)]
        public amaPivotFormulaPD PivotFormula
        {
            get { return pivotFormula; }
            set { pivotFormula = value; }
        }
         
        [NinjaScriptProperty]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Input data", Description = "Select between taking high, low and close from intraday data or from daily data", GroupName = "Algorithmic Options", Order = 1)]
         [RefreshProperties(RefreshProperties.All)]
        public amaSessionTypePD SessionType
        {
            get { return sessionType; }
            set { sessionType = value; }
        }
         
        [NinjaScriptProperty]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Input data for close", Description = "Select between taking close from intraday data or from daily data", GroupName = "Algorithmic Options", Order = 2)]
        public amaCalcModePD CalcMode
        {
            get { return calcMode; }
            set { calcMode = value; }
        }
         
        [Display(ResourceType = typeof(Custom.Resource), Name = "Show main pivot PP", Description = "Shows main pivot PP", GroupName = "Display Options", Order = 0)]
        [RefreshProperties(RefreshProperties.All)]
           public bool ShowPP
        {
            get { return showPP; }
            set { showPP = value; }
        }
     
        [Display(ResourceType = typeof(Custom.Resource), Name = "Show central pivot CP", Description = "Shows central pivot CP", GroupName = "Display Options", Order = 1)]
         [RefreshProperties(RefreshProperties.All)]
           public bool ShowCP
        {
            get { return showCP; }
            set { showCP = value; }
        }
     
        [Display(ResourceType = typeof(Custom.Resource), Name = "Show directional pivot DP", Description = "Shows directional pivot DP", GroupName = "Display Options", Order = 2)]
         [RefreshProperties(RefreshProperties.All)]
           public bool ShowDP
        {
            get { return showDP; }
            set { showDP = value; }
        }
     
        [Display(ResourceType = typeof(Custom.Resource), Name = "Show pivot range", Description = "Shows central and directional pivot", GroupName = "Display Options", Order = 3)]
          [RefreshProperties(RefreshProperties.All)]
           public bool ShowPivotRange
        {
            get { return showPivotRange; }
            set { showPivotRange = value; }
        }
     
        [Display(ResourceType = typeof(Custom.Resource), Name = "Show prior HLC", Description = "Shows prior day high, low and close (settlement)", GroupName = "Display Options", Order = 4)]
         [RefreshProperties(RefreshProperties.All)]
           public bool ShowPriorHLC
        {
            get { return showPriorHLC; }
            set { showPriorHLC = value; }
        }
     
        [Display(ResourceType = typeof(Custom.Resource), Name = "Show S/R pivots", Description = "Shows all support and resistance pivots", GroupName = "Display Options", Order = 5)]
        [RefreshProperties(RefreshProperties.All)]
        public bool ShowPivots
        {
            get { return showPivots; }
            set { showPivots = value; }
        }
     
        [Display(ResourceType = typeof(Custom.Resource), Name = "Show Jackson Zones", Description = "Shows Jackson Zones", GroupName = "Display Options", Order = 6)]
          [RefreshProperties(RefreshProperties.All)]
           public bool ShowJacksonZones
        {
            get { return showJacksonZones; }
            set { showJacksonZones = value; }
        }
     
        [Display(ResourceType = typeof(Custom.Resource), Name = "Show midpivots", Description = "Shows midpivot levels", GroupName = "Display Options", Order = 7)]
         [RefreshProperties(RefreshProperties.All)]
           public bool ShowMidpivots
        {
            get { return showMidpivots; }
            set { showMidpivots = value; }
        }
     
        [Display(ResourceType = typeof(Custom.Resource), Name = "Show labels", Description = "Shows labels for all pivot lines", GroupName = "Display Options", Order = 8)]
          [RefreshProperties(RefreshProperties.All)]
           public bool ShowLabels
        {
            get { return showLabels; }
            set { showLabels = value; }
        }
     
        [XmlIgnore]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Main pivot", Description = "Sets the color for the main pivot PP", GroupName = "Plot Colors", Order = 0)]
        public System.Windows.Media.Brush PivotBrush
        {
            get {return pivotBrush;}
            set {pivotBrush = value;}
        }

        [Browsable(false)]
        public string PivotBrushSerializable
        {
            get { return Serialize.BrushToString(pivotBrush); }
            set { pivotBrush = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Central pivot", Description = "Sets the color for the central pivot CP", GroupName = "Plot Colors", Order = 1)]
        public System.Windows.Media.Brush CentralPivotBrush
        {
            get {return centralPivotBrush;}
            set {centralPivotBrush = value;}
        }

        [Browsable(false)]
        public string CentralPivotBrushSerializable
        {
            get { return Serialize.BrushToString(centralPivotBrush); }
            set { centralPivotBrush = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Directional pivot", Description = "Sets the color for the directional pivot DP", GroupName = "Plot Colors", Order = 2)]
        public System.Windows.Media.Brush DirectionalPivotBrush
        {
            get {return directionalPivotBrush;}
            set {directionalPivotBrush = value;}
        }

        [Browsable(false)]
        public string DirectionalPivotBrushSerializable
        {
            get { return Serialize.BrushToString(directionalPivotBrush); }
            set { directionalPivotBrush = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Prior day high", Description = "Sets the color for the prior day high", GroupName = "Plot Colors", Order = 3)]
        public System.Windows.Media.Brush PriorHighBrush
        {
            get {return priorHighBrush;}
            set {priorHighBrush = value;}
        }

        [Browsable(false)]
        public string PriorHighBrushSerializable
        {
            get { return Serialize.BrushToString(priorHighBrush); }
            set { priorHighBrush = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Prior day low", Description = "Sets the color for the prior day low", GroupName = "Plot Colors", Order = 4)]
        public System.Windows.Media.Brush PriorLowBrush
        {
            get {return priorLowBrush;}
            set {priorLowBrush = value;}
        }

        [Browsable(false)]
        public string PriorLowBrushSerializable
        {
            get { return Serialize.BrushToString(priorLowBrush); }
            set { priorLowBrush = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Prior day close", Description = "Sets the color for the prior day close", GroupName = "Plot Colors", Order = 5)]
        public System.Windows.Media.Brush PriorCloseBrush
        {
            get {return priorCloseBrush;}
            set {priorCloseBrush = value;}
        }

        [Browsable(false)]
        public string PriorCloseBrushSerializable
        {
            get { return Serialize.BrushToString(priorCloseBrush); }
            set { priorCloseBrush = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Resistance pivots", Description = "Sets the color for the resistance levels R1, R2, R3 and R4", GroupName = "Plot Colors", Order = 6)]
        public System.Windows.Media.Brush ResistanceBrush
        {
            get {return resistanceBrush;}
            set {resistanceBrush = value;}
        }

        [Browsable(false)]
        public string ResistanceBrushSerializable
        {
            get { return Serialize.BrushToString(resistanceBrush); }
            set { resistanceBrush = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Support pivots", Description = "Sets the color for the support levels S1, S2, S3 and S4", GroupName = "Plot Colors", Order = 7)]
        public System.Windows.Media.Brush SupportBrush
        {
            get {return supportBrush;}
            set {supportBrush = value;}
        }

        [Browsable(false)]
        public string SupportBrushSerializable
        {
            get { return Serialize.BrushToString(supportBrush); }
            set { supportBrush = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Resistance midpivots", Description = "Sets the color for the resistance midpivots", GroupName = "Plot Colors", Order = 8)]
        public System.Windows.Media.Brush ResistanceMidBrush
        {
            get {return resistanceMidBrush;}
            set {resistanceMidBrush = value;}
        }

        [Browsable(false)]
        public string ResistanceMidBrushSerializable
        {
            get { return Serialize.BrushToString(resistanceMidBrush); }
            set { resistanceMidBrush = Serialize.StringToBrush(value); }
        }
     
        [XmlIgnore]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Support midpivots", Description = "Sets the color for the support midpivots", GroupName = "Plot Colors", Order = 9)]
        public System.Windows.Media.Brush SupportMidBrush
        {
            get {return supportMidBrush;}
            set {supportMidBrush = value;}
        }

        [Browsable(false)]
        public string SupportMidBrushSerializable
        {
            get { return Serialize.BrushToString(supportMidBrush); }
            set { supportMidBrush = Serialize.StringToBrush(value); }
        }
     
        [Display(ResourceType = typeof(Custom.Resource), Name = "Dash style pivots", Description = "Sets the dash style for all pivot lines", GroupName = "Plot Parameters", Order = 0)]
        public DashStyleHelper Dash0Style
        {
            get { return dash0Style; }
            set { dash0Style = value; }
        }
     
        [Range(1, int.MaxValue)]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Plot width pivots", Description = "Sets the plot width for all pivots", GroupName = "Plot Parameters", Order = 1)]
        public int Plot0Width
        {
            get { return plot0Width; }
            set { plot0Width = value; }
        }
         
        [Display(ResourceType = typeof(Custom.Resource), Name = "Dash style prior HLC", Description = "Sets the dash style for the prior day high, low and close", GroupName = "Plot Parameters", Order = 2)]
        public DashStyleHelper Dash1Style
        {
            get { return dash1Style; }
            set { dash1Style = value; }
        }
     
        [Range(1, int.MaxValue)]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Plot width prior HLC", Description = "Sets the plot width for the prior day high, low and close", GroupName = "Plot Parameters", Order = 3)]
        public int Plot1Width
        {
            get { return plot1Width; }
            set { plot1Width = value; }
        }
     
        [Display(ResourceType = typeof(Custom.Resource), Name = "Dash style midpivots", Description = "Sets the dash style for the midpivots", GroupName = "Plot Parameters", Order = 4)]
        public DashStyleHelper Dash2Style
        {
            get { return dash2Style; }
            set { dash2Style = value; }
        }
     
        [Range(1, int.MaxValue)]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Plot width midpivots", Description = "Sets the plot width for the midpivots", GroupName = "Plot Parameters", Order = 5)]
        public int Plot2Width
        {
            get { return plot2Width; }
            set { plot2Width = value; }
        }
     
        [Range(10, 40)]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Label font size", Description = "Sets the size for all pivot labels", GroupName = "Plot Parameters", Order = 6)]
        public int TextFontSize
        {
            get { return textFontSize; }
            set { textFontSize = value; }
        }
     
        [Range(0, int.MaxValue)]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Label offset", Description = "Allows for shifting the labels further to the right", GroupName = "Plot Parameters", Order = 7)]
        public int ShiftLabelOffset
        {
            get { return shiftLabelOffset; }
            set { shiftLabelOffset = value; }
        }
     
        [XmlIgnore]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Pivot range", Description = "Sets the color for the pivot range", GroupName = "Shaded Areas", Order = 0)]
        public System.Windows.Media.Brush PivotRangeBrushS
        {
            get {return pivotRangeBrushS;}
            set {pivotRangeBrushS = value;}
        }

        [Browsable(false)]
        public string PivotRangeBrushSSerializable
        {
            get { return Serialize.BrushToString(pivotRangeBrushS); }
            set { pivotRangeBrushS = Serialize.StringToBrush(value); }
        }
     
        [Range(0, 100)]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Pivot range opacity", Description = "Sets the opacity for the pivot range", GroupName = "Shaded Areas", Order = 1)]
        public int PivotRangeOpacity
        {
            get { return pivotRangeOpacity; }
            set { pivotRangeOpacity = value; }
        }
     
        [XmlIgnore]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Central range", Description = "Sets the color for the central range", GroupName = "Shaded Areas", Order = 2)]
        public System.Windows.Media.Brush CentralRangeBrushS
        {
            get {return centralRangeBrushS;}
            set {centralRangeBrushS = value;}
        }

        [Browsable(false)]
        public string CentralRangeBrushSSerializable
        {
            get { return Serialize.BrushToString(centralRangeBrushS); }
            set { centralRangeBrushS = Serialize.StringToBrush(value); }
        }
     
        [Range(0, 100)]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Central range opacity", Description = "Sets the opacity for the central range", GroupName = "Shaded Areas", Order = 3)]
        public int CentralRangeOpacity
        {
            get { return centralRangeOpacity; }
            set { centralRangeOpacity = value; }
        }
     
        [XmlIgnore]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Jackson Zones", Description = "Sets the color for the Jackson Zones", GroupName = "Shaded Areas", Order = 4)]
        public System.Windows.Media.Brush JacksonZonesBrushS
        {
            get {return jacksonZonesBrushS;}
            set {jacksonZonesBrushS = value;}
        }

        [Browsable(false)]
        public string JacksonZonesBrushSSerializable
        {
            get { return Serialize.BrushToString(jacksonZonesBrushS); }
            set { jacksonZonesBrushS = Serialize.StringToBrush(value); }
        }
     
        [Range(0, 100)]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Jackson Zones opacity", Description = "Sets the opacity for the Jackson Zones", GroupName = "Shaded Areas", Order = 5)]
        public int JacksonZonesOpacity
        {
            get { return jacksonZonesOpacity; }
            set { jacksonZonesOpacity = value; }
        }
     
        [XmlIgnore]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Release and date", Description = "Release and date", GroupName = "Version", Order = 0)]
        public string VersionString
        {
            get { return versionString; }
            set { ; }
        }
        #endregion
     
        #region Miscellaneous
     
        public override string FormatPriceMarker(double price)
        {
            return Instrument.MasterInstrument.FormatPrice(Instrument.MasterInstrument.RoundToTickSize(price));
        }        

        private bool IsConnected()
        {
            try
            {
                if (BarsArray[0] != null && BarsArray[0].Instrument.GetMarketDataConnection().PriceStatus == NinjaTrader.Cbi.ConnectionStatus.Connected)
                    return true;
                else
                    return false;
            }
            catch
            {
                return false;
            }
        }
     
        private DateTime GetLastBarSessionDate0(DateTime time)
        {
            sessionIterator0.CalculateTradingDay(time, timeBased0);
            sessionDateTmp0 = sessionIterator0.ActualTradingDayExchange;
            if(cacheSessionDate0 != sessionDateTmp0)
            {
                cacheSessionDate0 = sessionDateTmp0;
                if (newSessionBarIdxArr.Count == 0 || (newSessionBarIdxArr.Count > 0 && CurrentBars[0] > (int) newSessionBarIdxArr[newSessionBarIdxArr.Count - 1]))
                        newSessionBarIdxArr.Add(CurrentBars[0]);
            }
            return sessionDateTmp0;        
        }
     
        private DateTime GetLastBarSessionDate1(DateTime time)
        {
            sessionIterator0.CalculateTradingDay(time, true);
            sessionDateTmp1 = sessionIterator0.ActualTradingDayExchange;
            return sessionDateTmp1;        
        }
     
        public override void OnRenderTargetChanged()
        {
            if (pivotRangeBrushDX != null)
                pivotRangeBrushDX.Dispose();
            if (centralRangeBrushDX != null)
                centralRangeBrushDX.Dispose();
            if (jacksonZonesBrushDX != null)
                jacksonZonesBrushDX.Dispose();
            if (transparentBrushDX != null)
                transparentBrushDX.Dispose();
            for (int seriesCount = 0; seriesCount < Values.Length; seriesCount++)
                if(brushesDX[seriesCount] != null)
                    brushesDX[seriesCount].Dispose();

            if (RenderTarget != null)
            {
                try
                {
                    pivotRangeBrushDX     = pivotRangeBrush.ToDxBrush(RenderTarget);
                    centralRangeBrushDX = centralRangeBrush.ToDxBrush(RenderTarget);
                    jacksonZonesBrushDX = jacksonZonesBrush.ToDxBrush(RenderTarget);
                    transparentBrushDX = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Transparent);
                    for (int seriesCount = 0; seriesCount < Values.Length; seriesCount++)
                        brushesDX[seriesCount]     = Plots[seriesCount].BrushDX;
                }
                catch (Exception e) { }
            }
        }
     
        protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            if (ChartBars == null || errorMessage || !IsVisible) return;
            int    lastBarPainted = ChartBars.ToIndex;
            if(lastBarPainted  < 0 || BarsArray[0].Count < lastBarPainted) return;

            SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode;
            RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.Aliased;
            TextFormat textFormat1 = new TextFormat(Globals.DirectWriteFactory, "Arial", (float)this.TextFontSize);    
         
            int lastBarCounted                = Inputs[0].Count - 1;
            int    lastBarOnUpdate                = lastBarCounted - (Calculate == Calculate.OnBarClose ? 1 : 0);
            int    lastBarIndex                = Math.Min(lastBarPainted, lastBarOnUpdate);
            int firstBarPainted                 = ChartBars.FromIndex;
            int firstBarIndex                   = Math.Max(BarsRequiredToPlot, firstBarPainted);
            int firstBarIdxToPaint          = 0;
            int lastPlotIndex                = lastBarPainted;
            int lastPlotCalcIndex            = lastBarIndex;
            int firstPlotIndex                = 0;
            int    resolution                    = 1 + this.TextFontSize/2;
            double barWidth                    = chartControl.GetBarPaintWidth(ChartBars);
            double smallGap                    = 2.0;
            double labelOffset                = (this.TextFontSize + barWidth)/2.0 + shiftLabelOffset;
            double firstX                    = 0.0;
            double lastX                    = 0.0;
            double val                        = 0.0;
            double valC                        = 0.0;
            double valD                        = 0.0;
            double valH                        = 0.0;
            double valL                        = 0.0;
            double y                        = 0.0;
            double yC                        = 0.0;
            double yD                        = 0.0;
            double yH                        = 0.0;
            double yL                        = 0.0;
            double[] yArr                    = new double[Values.Length];
            float width                        = 0.0f;
            float height                    = 0.0f;
            float textFontSize                = textFormat1.FontSize;
            string[] plotLabels                = new string[Values.Length];
            bool firstLoop                    = true;
            DateTime lastBarPaintedTime        = ChartBars.Bars.GetTime(lastBarPainted);
            DateTime lastBarIndexTime        = ChartBars.Bars.GetTime(lastBarIndex);
            DateTime tradingDayEndPainted;
            DateTime tradingDayEndByIndex;
            SharpDX.Vector2 startPointDX;
            SharpDX.Vector2 endPointDX;
            SharpDX.Vector2 textPointDX;
            SharpDX.RectangleF rect;
         
            if(lastBarPainted != CacheLastBarPainted)
            {
                sessionIterator0.GetNextSession(lastBarPaintedTime, timeBased0);
                tradingDayEndPainted = sessionIterator0.ActualTradingDayEndLocal;
                sessionIterator0.GetNextSession(lastBarIndexTime, timeBased0);
                tradingDayEndByIndex = sessionIterator0.ActualTradingDayEndLocal;
                CacheLastBarPainted = lastBarPainted;
                if(tradingDayEndByIndex < tradingDayEndPainted)
                    LastBarStartsNewPeriod = true;
                else
                    LastBarStartsNewPeriod = false;
            }
            if(LastBarStartsNewPeriod)
                lastPlotIndex = lastBarIndex;
         
            if(!Values[0].IsValidDataPointAt(lastPlotCalcIndex))
            {
                if(!errorMessage)
                {
                    SharpDX.Direct2D1.Brush errorBrushDX = errorBrush.ToDxBrush(RenderTarget);
                    TextFormat textFormat2 = new TextFormat(Globals.DirectWriteFactory, "Arial", 20.0f);    
                    SharpDX.DirectWrite.TextLayout textLayout = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Globals.DirectWriteFactory, errorText8, textFormat2, 1000, 20.0f);
                    SharpDX.Vector2 lowerTextPoint = new SharpDX.Vector2(ChartPanel.W - textLayout.Metrics.Width - 5, ChartPanel.Y + (ChartPanel.H - textLayout.Metrics.Height));
                    RenderTarget.DrawTextLayout(lowerTextPoint, textLayout, errorBrushDX, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
                    errorBrushDX.Dispose();
                    textFormat2.Dispose();
                    textLayout.Dispose();
                }
                RenderTarget.AntialiasMode = oldAntialiasMode;
                textFormat1.Dispose();
                return;
            }
         
            do
            {
                //check whether lastBarIndex contains a pivot value
                for (int i = newSessionBarIdxArr.Count - 1; i >= 0; i--)
                {
                    int prevSessionBreakIdx = newSessionBarIdxArr[i];
                    if (prevSessionBreakIdx <= lastPlotIndex)
                    {
                        firstBarIdxToPaint = prevSessionBreakIdx;
                        break;
                    }
                }
                firstPlotIndex = Math.Max(firstBarIndex, firstBarIdxToPaint);
                if(!Values[0].IsValidDataPointAt(lastPlotCalcIndex))
                    break;
                if(firstPlotIndex > firstBarPainted)
                    firstX    = chartControl.GetXByBarIndex(ChartBars, firstPlotIndex - 1) + smallGap;
                else
                    firstX    = smallGap;
                lastX    = chartControl.GetXByBarIndex(ChartBars, lastPlotIndex);
             
                for (int seriesCount = 0; seriesCount < Values.Length; seriesCount++)
                {
                    val                        = Values[seriesCount].GetValueAt(lastPlotCalcIndex);
                    yArr[seriesCount]         = chartScale.GetYByValue(val);
                    plotLabels[seriesCount] = Plots[seriesCount].Name;
                    brushesDX[seriesCount]     = Plots[seriesCount].BrushDX;
                }
             
                // adjust labels in case that two pivots have near-identical prices
                if(ShowMidpivots && pivotFormula != amaPivotFormulaPD.Jackson_Zones && pivotFormula != amaPivotFormulaPD.Fibonacci_Pivots)
                {
                    for (int i = 7; i < 9; i++)
                    {
                        if(ShowPriorHLC && Math.Abs(yArr[2*i] - yArr[13]) < resolution)
                        {
                            plotLabels[13] = plotLabels[13] + "/" + plotLabels[2*i];
                            plotLabels[2*i] = "";
                            brushesDX[2*i] = transparentBrushDX;
                        }
                        else if(ShowPriorHLC && Math.Abs(yArr[2*i] - yArr[11]) < resolution)
                        {
                            plotLabels[11] = plotLabels[11] + "/" + plotLabels[2*i];
                            plotLabels[2*i] = "";
                            brushesDX[2*i] = transparentBrushDX;
                        }
                        else if (ShowDP && Math.Abs(yArr[2*i] - yArr[2]) < resolution)
                        {
                            plotLabels[2] = plotLabels[2] + "/" + plotLabels[2*i];
                            plotLabels[2*i] = "";
                            brushesDX[2*i] = transparentBrushDX;
                        }
                        else if (ShowCP && Math.Abs(yArr[2*i] - yArr[1]) < resolution)
                        {
                            plotLabels[1] = plotLabels[1] + "/" + plotLabels[2*i];
                            plotLabels[2*i] = "";
                            brushesDX[2*i] = transparentBrushDX;
                        }
                    }
                    for (int i = 7; i < 9; i++)
                    {
                        if(ShowPriorHLC && Math.Abs(yArr[2*i+1] - yArr[13]) < resolution)
                        {
                            plotLabels[13] = plotLabels[13] + "/" + plotLabels[2*i+1];
                            plotLabels[2*i+1] = "";
                            brushesDX[2*i+1] = transparentBrushDX;
                        }
                        else if(ShowPriorHLC && Math.Abs(yArr[2*i+1] - yArr[12]) < resolution)
                        {
                            plotLabels[12] = plotLabels[12] + "/" + plotLabels[2*i+1];
                            plotLabels[2*i+1] = "";
                            brushesDX[2*i+1] = transparentBrushDX;
                        }
                        else if (ShowDP && Math.Abs(yArr[2*i+1] - yArr[2]) < resolution)
                        {
                            plotLabels[2] = plotLabels[2] + "/" + plotLabels[2*i+1];
                            plotLabels[2*i+1] = "";
                            brushesDX[2*i+1] = transparentBrushDX;
                        }
                        else if (ShowCP && Math.Abs(yArr[2*i+1] - yArr[1]) < resolution)
                        {
                            plotLabels[1] = plotLabels[1] + "/" + plotLabels[2*i+1];
                            plotLabels[2*i+1] = "";
                            brushesDX[2*i+1] = transparentBrushDX;
                        }
                    }
                }
             
                if(ShowPriorHLC)
                {
                    if (Math.Abs(yArr[13] - yArr[11]) < resolution)
                    {
                        plotLabels[11] = plotLabels[11] + "/" + plotLabels[13];
                        plotLabels[13] = "";
                        brushesDX[13] = transparentBrushDX;
                    }
                    else if (Math.Abs(yArr[13] - yArr[12]) < resolution)
                    {
                        plotLabels[12] = plotLabels[12] + "/" + plotLabels[13];
                        plotLabels[13] = "";
                        brushesDX[13] = transparentBrushDX;
                    }
                    else if (ShowDP && Math.Abs(yArr[13] - yArr[2]) < resolution)
                    {
                        plotLabels[2] = plotLabels[2] + "/" + plotLabels[13];
                        brushesDX[2] = brushesDX[13];
                        plotLabels[13] = "";
                        brushesDX[13] = transparentBrushDX;
                    }
                    else if (ShowCP && Math.Abs(yArr[13] - yArr[1]) < resolution)
                    {
                        plotLabels[1] = plotLabels[1] + "/" + plotLabels[13];
                        brushesDX[1] = brushesDX[13];
                        plotLabels[13] = "";
                        brushesDX[13] = transparentBrushDX;
                    }
                    else if (ShowPP && Math.Abs(yArr[13] - yArr[0]) < resolution)
                    {
                        plotLabels[0] = plotLabels[0] + "/" + plotLabels[13];
                        brushesDX[0] = brushesDX[13];
                        plotLabels[13] = "";
                        brushesDX[13] = transparentBrushDX;
                    }
                    if(ShowPivots)
                    {
                        if (Math.Abs(yArr[11] - yArr[3]) < resolution)
                        {
                            plotLabels[3] = plotLabels[3] + "/" + plotLabels[11];
                            brushesDX[3] = brushesDX[11];
                            plotLabels[11] = "";
                            brushesDX[11] = transparentBrushDX;
                        }
                        if (Math.Abs(yArr[12] - yArr[4]) < resolution)
                        {
                            plotLabels[4] = plotLabels[4] + "/" + plotLabels[12];
                            brushesDX[4] = brushesDX[12];
                            plotLabels[12] = "";
                            brushesDX[12] = transparentBrushDX;
                        }
                    }
                }
             
                if (ShowPP && ShowCP && ShowDP && Math.Min(Math.Abs(yArr[1] - yArr[0]), Math.Abs(yArr[2] - yArr[0])) < resolution)
                {
                    plotLabels[0] = plotLabels[0] + "/" + plotLabels[1] + "/" + plotLabels[2];
                    brushesDX[0] = brushesDX[2];
                    plotLabels[1] = "";
                    plotLabels[2] = "";
                    brushesDX[1] = transparentBrushDX;
                    brushesDX[2] = transparentBrushDX;
                }
                else if (ShowPP)
                {
                    if (ShowCP && Math.Abs(yArr[1] - yArr[0]) < resolution)
                    {
                        plotLabels[0] = plotLabels[0] + "/" + plotLabels[1];
                        brushesDX[0] = brushesDX[1];
                        plotLabels[1] = "";
                        brushesDX[1] = transparentBrushDX;
                    }
                    else if (ShowDP && Math.Abs(yArr[2] - yArr[0]) < resolution)
                    {
                        plotLabels[0] = plotLabels[0] + "/" + plotLabels[2];
                        brushesDX[0] = brushesDX[2];
                        plotLabels[2] = "";
                        brushesDX[2] = transparentBrushDX;
                    }
                }
                else if (ShowCP && ShowDP && Math.Abs(yArr[2] - yArr[1]) < resolution)
                {
                    plotLabels[1] = plotLabels[1] + "/" + plotLabels[2];
                    brushesDX[1] = brushesDX[2];
                    plotLabels[2] = "";
                    brushesDX[2] = transparentBrushDX;
                }
             
                //Draw pivot range
                if(ShowPivotRange)
                {
                    val = Values[0].GetValueAt(lastPlotCalcIndex);
                    valC = Values[1].GetValueAt(lastPlotCalcIndex);
                    valD = Values[2].GetValueAt(lastPlotCalcIndex);
                    y = chartScale.GetYByValue(val);
                    yC = chartScale.GetYByValue(valC);
                    yD = chartScale.GetYByValue(valD);
                 
                    if(y < yC)
                    {
                        width = (float)(lastX - firstX);
                        height = (float)(yC - y);
                        startPointDX = new SharpDX.Vector2((float)firstX, (float)y);
                        rect = new SharpDX.RectangleF(startPointDX.X, startPointDX.Y, width, height);
                        RenderTarget.FillRectangle(rect, centralRangeBrushDX);
                    }
                    else if (y > yC)
                    {
                        width = (float)(lastX - firstX);
                        height = (float)(y - yC);
                        startPointDX = new SharpDX.Vector2((float)firstX, (float)yC);
                        rect = new SharpDX.RectangleF(startPointDX.X, startPointDX.Y, width, height);
                        RenderTarget.FillRectangle(rect, centralRangeBrushDX);
                    }
                    else
                    {
                        width = (float)(lastX - firstX);
                        height = 10.0f;
                        startPointDX = new SharpDX.Vector2((float)firstX, (float)y);
                        rect = new SharpDX.RectangleF(startPointDX.X, startPointDX.Y -5.0f, width, height);
                        RenderTarget.FillRectangle(rect, centralRangeBrushDX);
                    }
                 
                    if(y < yD)
                    {
                        width = (float)(lastX - firstX);
                        height = (float)(yD - y);
                        startPointDX = new SharpDX.Vector2((float)firstX, (float)y);
                        rect = new SharpDX.RectangleF(startPointDX.X, startPointDX.Y, width, height);
                        RenderTarget.FillRectangle(rect, pivotRangeBrushDX);
                    }
                    else if (y > yD)
                    {
                        width = (float)(lastX - firstX);
                        height = (float)(y - yD);
                        startPointDX = new SharpDX.Vector2((float)firstX, (float)yD);
                        rect = new SharpDX.RectangleF(startPointDX.X, startPointDX.Y, width, height);
                        RenderTarget.FillRectangle(rect, pivotRangeBrushDX);
                    }
                }
             
                //Draw Jackson Zones
                if(ShowJacksonZones && pivotFormula == amaPivotFormulaPD.Jackson_Zones)
                {
                    valH = Values[3].GetValueAt(lastPlotCalcIndex);
                    valL = Values[5].GetValueAt(lastPlotCalcIndex);
                    yH = chartScale.GetYByValue(valH);
                    yL = chartScale.GetYByValue(valL);
                 
                    if(yL < yH)
                    {
                        width = (float)(lastX - firstX);
                        height = (float)(yH - yL);
                        startPointDX = new SharpDX.Vector2((float)firstX, (float)yL);
                        rect = new SharpDX.RectangleF(startPointDX.X, startPointDX.Y, width, height);
                        RenderTarget.FillRectangle(rect, jacksonZonesBrushDX);
                    }
                    else
                    {
                        width = (float)(lastX - firstX);
                        height = 10.0f;
                        startPointDX = new SharpDX.Vector2((float)firstX, (float)yL);
                        rect = new SharpDX.RectangleF(startPointDX.X, startPointDX.Y -5.0f, width, height);
                        RenderTarget.FillRectangle(rect, jacksonZonesBrushDX);
                    }
                 
                    valH = Values[6].GetValueAt(lastPlotCalcIndex);
                    valL = Values[4].GetValueAt(lastPlotCalcIndex);
                    yH = chartScale.GetYByValue(valH);
                    yL = chartScale.GetYByValue(valL);
                 
                    if(yL < yH)
                    {
                        width = (float)(lastX - firstX);
                        height = (float)(yH - yL);
                        startPointDX = new SharpDX.Vector2((float)firstX, (float)yL);
                        rect = new SharpDX.RectangleF(startPointDX.X, startPointDX.Y, width, height);
                        RenderTarget.FillRectangle(rect, jacksonZonesBrushDX);
                    }
                    else
                    {
                        width = (float)(lastX - firstX);
                        height = 10.0f;
                        startPointDX = new SharpDX.Vector2((float)firstX, (float)yL);
                        rect = new SharpDX.RectangleF(startPointDX.X, startPointDX.Y -5.0f, width, height);
                        RenderTarget.FillRectangle(rect, jacksonZonesBrushDX);
                    }
                 
                    valH = Values[7].GetValueAt(lastPlotCalcIndex);
                    valL = Values[9].GetValueAt(lastPlotCalcIndex);
                    yH = chartScale.GetYByValue(valH);
                    yL = chartScale.GetYByValue(valL);
                 
                    if(yL < yH)
                    {
                        width = (float)(lastX - firstX);
                        height = (float)(yH - yL);
                        startPointDX = new SharpDX.Vector2((float)firstX, (float)yL);
                        rect = new SharpDX.RectangleF(startPointDX.X, startPointDX.Y, width, height);
                        RenderTarget.FillRectangle(rect, jacksonZonesBrushDX);
                    }
                    else
                    {
                        width = (float)(lastX - firstX);
                        height = 10.0f;
                        startPointDX = new SharpDX.Vector2((float)firstX, (float)yL);
                        rect = new SharpDX.RectangleF(startPointDX.X, startPointDX.Y -5.0f, width, height);
                        RenderTarget.FillRectangle(rect, jacksonZonesBrushDX);
                    }
                 
                    valH = Values[10].GetValueAt(lastPlotCalcIndex);
                    valL = Values[8].GetValueAt(lastPlotCalcIndex);
                    yH = chartScale.GetYByValue(valH);
                    yL = chartScale.GetYByValue(valL);
                 
                    if(yL < yH)
                    {
                        width = (float)(lastX - firstX);
                        height = (float)(yH - yL);
                        startPointDX = new SharpDX.Vector2((float)firstX, (float)yL);
                        rect = new SharpDX.RectangleF(startPointDX.X, startPointDX.Y, width, height);
                        RenderTarget.FillRectangle(rect, jacksonZonesBrushDX);
                    }
                    else
                    {
                        width = (float)(lastX - firstX);
                        height = 10.0f;
                        startPointDX = new SharpDX.Vector2((float)firstX, (float)yL);
                        rect = new SharpDX.RectangleF(startPointDX.X, startPointDX.Y -5.0f, width, height);
                        RenderTarget.FillRectangle(rect, jacksonZonesBrushDX);
                    }
                }
             
                // Loop through all plot values on the chart
                for (int seriesCount = 0; seriesCount < Values.Length; seriesCount++)
                {
                    Plot    plot = Plots[seriesCount];
                    y = yArr[seriesCount];
                 
                    // Draw pivot lines
                    startPointDX = new SharpDX.Vector2((float)firstX, (float)y);
                    endPointDX = new SharpDX.Vector2((float)lastX, (float)y);
                    RenderTarget.DrawLine(startPointDX, endPointDX, plot.BrushDX, plot.Width, plot.StrokeStyle);
                 
                    // Draw pivot text
                    if(ShowLabels && firstLoop)
                    {
                            textPointDX = new SharpDX.Vector2((float)(lastX + labelOffset), (float)(y - textFontSize/2));
                            TextLayout textLayout = new TextLayout(Globals.DirectWriteFactory, plotLabels[seriesCount], textFormat1, Math.Max(150, ChartControl.Properties.BarMarginRight - (float)labelOffset - 20), textFontSize);
                            RenderTarget.DrawTextLayout(textPointDX, textLayout, brushesDX[seriesCount]);
                            textLayout.Dispose();
                    }
                }
             
                if(lastPlotIndex < firstPlotIndex)
                    lastPlotIndex = 0;
                else
                    lastPlotIndex = firstPlotIndex - 1;
                lastPlotCalcIndex = lastPlotIndex;
                firstLoop = false;
            }
            while (lastPlotIndex >= firstBarIndex);
             
            RenderTarget.AntialiasMode = oldAntialiasMode;
            textFormat1.Dispose();
            base.OnRender(chartControl, chartScale);
        }
        #endregion
    }
}

namespace NinjaTrader.NinjaScript.Indicators
{
    public class amaPivotsDailyTypeConverter : NinjaTrader.NinjaScript.IndicatorBaseConverter
    {
        public override bool GetPropertiesSupported(ITypeDescriptorContext context) { return true; }

        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            PropertyDescriptorCollection propertyDescriptorCollection = base.GetPropertiesSupported(context) ? base.GetProperties(context, value, attributes) : TypeDescriptor.GetProperties(value, attributes);

            amaPivotsDaily        thisPivotsInstance                    = (amaPivotsDaily) value;
            amaPivotFormulaPD    pivotFormulaFromInstance            = thisPivotsInstance.PivotFormula;
            amaSessionTypePD    sessionTypeFromInstance                = thisPivotsInstance.SessionType;
            bool                showPPFromInstance                    = thisPivotsInstance.ShowPP;
            bool                showCPFromInstance                    = thisPivotsInstance.ShowCP;
            bool                showDPFromInstance                    = thisPivotsInstance.ShowDP;
            bool                showPriorHLCFromInstance            = thisPivotsInstance.ShowPriorHLC;
            bool                showPivotsFromInstance                = thisPivotsInstance.ShowPivots;
            bool                showMidpivotsFromInstance            = thisPivotsInstance.ShowMidpivots;
            bool                showPivotRangeFromInstance            = thisPivotsInstance.ShowPivotRange;
            bool                showJacksonZonesFromInstance        = thisPivotsInstance.ShowJacksonZones;
            bool                showLabelsFromInstance                = thisPivotsInstance.ShowLabels;
         
            PropertyDescriptorCollection adjusted = new PropertyDescriptorCollection(null);
         
            foreach (PropertyDescriptor thisDescriptor in propertyDescriptorCollection)
            {
                if ((pivotFormulaFromInstance == amaPivotFormulaPD.Jackson_Zones || pivotFormulaFromInstance == amaPivotFormulaPD.Fibonacci_Pivots) &&
                    (thisDescriptor.Name == "ShowMidpivots" || thisDescriptor.Name == "ResistanceMidBrush" || thisDescriptor.Name == "SupportMidBrush"
                    || thisDescriptor.Name == "Dash2Style" || thisDescriptor.Name == "Plot2Width"))
                    adjusted.Add(new PropertyDescriptorExtended(thisDescriptor, o => value, null, new Attribute[] {new BrowsableAttribute(false), }));
                else if (pivotFormulaFromInstance != amaPivotFormulaPD.Jackson_Zones && (thisDescriptor.Name == "ShowJacksonZones" ||
                    thisDescriptor.Name == "JacksonZonesBrushS" || thisDescriptor.Name == "JacksonZonesOpacity"))
                    adjusted.Add(new PropertyDescriptorExtended(thisDescriptor, o => value, null, new Attribute[] {new BrowsableAttribute(false), }));
                else if (sessionTypeFromInstance == amaSessionTypePD.Daily_Bars && thisDescriptor.Name == "CalcMode")
                    adjusted.Add(new PropertyDescriptorExtended(thisDescriptor, o => value, null, new Attribute[] {new BrowsableAttribute(false), }));
                else if (!showPPFromInstance && thisDescriptor.Name == "PivotBrush")
                    adjusted.Add(new PropertyDescriptorExtended(thisDescriptor, o => value, null, new Attribute[] {new BrowsableAttribute(false), }));
                else if (!showCPFromInstance && thisDescriptor.Name == "CentralPivotBrush")
                    adjusted.Add(new PropertyDescriptorExtended(thisDescriptor, o => value, null, new Attribute[] {new BrowsableAttribute(false), }));
                else if (!showDPFromInstance && thisDescriptor.Name == "DirectionalPivotBrush")
                    adjusted.Add(new PropertyDescriptorExtended(thisDescriptor, o => value, null, new Attribute[] {new BrowsableAttribute(false), }));
                else if (!showPriorHLCFromInstance && (thisDescriptor.Name == "PriorHighBrush" || thisDescriptor.Name == "PriorLowBrush"
                    || thisDescriptor.Name == "PriorCloseBrush" || thisDescriptor.Name == "Dash1Style" || thisDescriptor.Name == "Plot1Width"))
                    adjusted.Add(new PropertyDescriptorExtended(thisDescriptor, o => value, null, new Attribute[] {new BrowsableAttribute(false), }));
                else if (!showPivotsFromInstance && (thisDescriptor.Name == "ResistanceBrush" || thisDescriptor.Name == "SupportBrush"))
                    adjusted.Add(new PropertyDescriptorExtended(thisDescriptor, o => value, null, new Attribute[] {new BrowsableAttribute(false), }));
                else if (!showMidpivotsFromInstance && (thisDescriptor.Name == "ResistanceMidBrush" || thisDescriptor.Name == "SupportMidBrush"
                    || thisDescriptor.Name == "Dash2Style" || thisDescriptor.Name == "Plot2Width"))
                    adjusted.Add(new PropertyDescriptorExtended(thisDescriptor, o => value, null, new Attribute[] {new BrowsableAttribute(false), }));
                else if (!showPPFromInstance && !showCPFromInstance && !showDPFromInstance && !showPivotsFromInstance && (thisDescriptor.Name == "Dash0Style" || thisDescriptor.Name == "Plot0Width"))
                    adjusted.Add(new PropertyDescriptorExtended(thisDescriptor, o => value, null, new Attribute[] {new BrowsableAttribute(false), }));
                else if (!showPivotRangeFromInstance && (thisDescriptor.Name == "PivotRangeBrushS" || thisDescriptor.Name == "PivotRangeOpacity"
                    || thisDescriptor.Name == "CentralRangeBrushS" || thisDescriptor.Name == "CentralRangeOpacity" ))
                    adjusted.Add(new PropertyDescriptorExtended(thisDescriptor, o => value, null, new Attribute[] {new BrowsableAttribute(false), }));
                else if (!showJacksonZonesFromInstance && (thisDescriptor.Name == "JacksonZonesBrushS" || thisDescriptor.Name == "JacksonZonesOpacity"))
                    adjusted.Add(new PropertyDescriptorExtended(thisDescriptor, o => value, null, new Attribute[] {new BrowsableAttribute(false), }));
                else if (!showLabelsFromInstance && (thisDescriptor.Name == "TextFontSize" || thisDescriptor.Name == "ShiftLabelOffset"))
                    adjusted.Add(new PropertyDescriptorExtended(thisDescriptor, o => value, null, new Attribute[] {new BrowsableAttribute(false), }));
                else
                    adjusted.Add(thisDescriptor);
            }
            return adjusted;    
        }
    }
}

#region Public Enums
public enum amaPivotFormulaPD
{
    Floor_Trader_Pivots,
    Wide_Pivots,
    Jackson_Zones,
    Fibonacci_Pivots
}

public enum amaSessionTypePD
{
    Trading_Hours,
    Daily_Bars
}

public enum amaCalcModePD
{
    Intraday_Data,
    Daily_Data
}
#endregion

#region NinjaScript generated code. Neither change nor remove.

namespace NinjaTrader.NinjaScript.Indicators
{
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
        private LizardIndicators.amaPivotsDaily[] cacheamaPivotsDaily;
        public LizardIndicators.amaPivotsDaily amaPivotsDaily(amaPivotFormulaPD pivotFormula, amaSessionTypePD sessionType, amaCalcModePD calcMode)
        {
            return amaPivotsDaily(Input, pivotFormula, sessionType, calcMode);
        }

        public LizardIndicators.amaPivotsDaily amaPivotsDaily(ISeries<double> input, amaPivotFormulaPD pivotFormula, amaSessionTypePD sessionType, amaCalcModePD calcMode)
        {
            if (cacheamaPivotsDaily != null)
                for (int idx = 0; idx < cacheamaPivotsDaily.Length; idx++)
                    if (cacheamaPivotsDaily[idx] != null && cacheamaPivotsDaily[idx].PivotFormula == pivotFormula && cacheamaPivotsDaily[idx].SessionType == sessionType && cacheamaPivotsDaily[idx].CalcMode == calcMode && cacheamaPivotsDaily[idx].EqualsInput(input))
                        return cacheamaPivotsDaily[idx];
            return CacheIndicator<LizardIndicators.amaPivotsDaily>(new LizardIndicators.amaPivotsDaily(){ PivotFormula = pivotFormula, SessionType = sessionType, CalcMode = calcMode }, input, ref cacheamaPivotsDaily);
        }
    }
}

namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
        public Indicators.LizardIndicators.amaPivotsDaily amaPivotsDaily(amaPivotFormulaPD pivotFormula, amaSessionTypePD sessionType, amaCalcModePD calcMode)
        {
            return indicator.amaPivotsDaily(Input, pivotFormula, sessionType, calcMode);
        }

        public Indicators.LizardIndicators.amaPivotsDaily amaPivotsDaily(ISeries<double> input , amaPivotFormulaPD pivotFormula, amaSessionTypePD sessionType, amaCalcModePD calcMode)
        {
            return indicator.amaPivotsDaily(input, pivotFormula, sessionType, calcMode);
        }
    }
}

namespace NinjaTrader.NinjaScript.Strategies
{
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
        public Indicators.LizardIndicators.amaPivotsDaily amaPivotsDaily(amaPivotFormulaPD pivotFormula, amaSessionTypePD sessionType, amaCalcModePD calcMode)
        {
            return indicator.amaPivotsDaily(Input, pivotFormula, sessionType, calcMode);
        }

        public Indicators.LizardIndicators.amaPivotsDaily amaPivotsDaily(ISeries<double> input , amaPivotFormulaPD pivotFormula, amaSessionTypePD sessionType, amaCalcModePD calcMode)
        {
            return indicator.amaPivotsDaily(input, pivotFormula, sessionType, calcMode);
        }
    }
}

#endregion
 
Last edited by a moderator:

Similar threads

Top