The Cemetery: Questions Edition

Status
Not open for further replies.
Y

Yawar ali

New member
Hello,

I have a screenshot of an indicator, Can anyone please help me get the script for.. please please help me ... script for trading view ... this is very different than trend magic and super trend...
.
 
Dezdewdad

Dezdewdad

New member
Hello group - i'm looking for a scriptwriter to build a custom indicator for think or swim catered to 15 min price bars with signals. If interested can you please inbox me for details of my style.
 
Y

yusef

New member
Hello good morning, greetings to all, I have a ratioscript volume created by me, but I would like to know how I can put it in a candle chart, since this is a lower indicator, I can only see it with a line, and I would like to rename it as a ticker and be able to put it on a candle chart.
 
H

Heloyguerra

New member
I have a video with paramaters that I would like to trade and would like to put it in a thinkorswwim script any help would be greatly appricated
 
H

hoojsn

New member
Hi, Anyone could help me to write a script for the above for MTF for CandleStick with Arrow or Colour as Signal. I use it in my studies. Thanks.
 
S

Shirke

New member
Where can I find the ThinkorSwim ThinkScript Coder who can help me.

Thanks,
 
M

mennen12

New member
Hello team, I got this code and I would like to color my bar when the condition is true, right now plot only an arrow but I would like to see a black candle in my chart when the condition is made. Thanks
 
H

Heloyguerra

New member
set{var1,high 30 day high - low 10 day low}
set{var2,var1 / close}

var2 < 0.15
market is ETF
average volume is above 300000 for last 50 days
 
S

snow22

New member
2019 Donor
I had a study on TOS that painted the upper chart green/red depending on the trend/price action. It must have used assignbackgroundcolor(). Help appreciated!
 
Y

yman

Member
Recently saw an indicator that overlaps the 5 min over the 1 min cant find it need help
Thanks
 
B

birdie123

New member
I have two prices A and B and want to plot a line from A to B. Is it possible using thinkorswim script? Thanks!
 
R

rogtrader

New member


This is an amazing strategy for day traders..

Anyone knows how to code this in Thinkorswim? This one is from TradingView. Thanks!!!
 
M

MindPortal

New member
I have a very intricate indicator referencing many different stocks. I’m now getting an “script too long”error message. Is there away around this? Thank you
 
NahuelPatricioRodriguez

NahuelPatricioRodriguez

New member
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

The first is "DValueArea", the second code is PriceAction Swing

Code:
// #############################################################
// #                                                           #
// #                     PriceActionSwing                      #
// #                                                           #
// #     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>
    /// PriceActionSwing calculates swings and visualizes them in different ways
    /// and displays several information about the swings.
    /// </summary>
    public class PriceActionSwing : 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;
        //=========================================================================================
        #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                            = @"PriceActionSwing calculates swings and visualize them in different ways and display several information about them.";
                Name                                = "PriceActionSwing";
                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);
            }
        }
        //=========================================================================================
        #endregion

        protected override void OnBarUpdate()
        {
            Print("Size: " + Convert.ToInt32(textFont.Size));
            
            // Checks to ensure there are enough bars before beginning
            if (CurrentBars[BarsInProgress] <= 1
                || CurrentBars[BarsInProgress] < SwingSize)
                return;

            #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 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 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); }
        }
        //=========================================================================================
        #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
        #endregion
        
        #region CalculateShortRisk
        //#########################################################################################
        public override string DisplayName
        {
            get { return (displayName != null ? displayName : Name); }
        }       
        //#########################################################################################
        #endregion
    }
}

namespace PriceActionSwing.Base
{
        #region public class SwingValues
        //=============================================================================================
        public class Swings
        {
            #region Current values
            //-----------------------------------------------------------------------------------------
            /// <summary>
            /// Represents the price of the current swing.
            /// </summary>
            public double CurPrice { get; set; }
            /// <summary>
            /// Represents the bar number of the highest/lowest bar of the current swing.
            /// </summary>
            public int CurBar { get; set; }
            /// <summary>
            /// Represents the duration as time values of the current swing.
            /// </summary>
            public DateTime CurDateTime { get; set; }
            /// <summary>
            /// Represents the duration in bars of the current swing.
            /// </summary>
            public int CurDuration { get; set; }
            /// <summary>
            /// Represents the swing length in ticks of the current swing.
            /// </summary>
            public int CurLength { get; set; }
            /// <summary>
            /// Represents the percentage in relation between the last swing and the current swing.
            /// E. g. 61.8% fib retracement.
            /// </summary>
            public double CurPercent { get; set; }
            /// <summary>
            /// Represents the duration as integer in HHMMSS of the current swing.
            /// </summary>
            public int CurTime { get; set; }
            /// <summary>
            /// Represents the entire volume of the current swing.
            /// </summary>
            public long CurVolume { get; set; }
            /// <summary>
            /// Represents the relation to the previous swing.
            /// -1 = Lower High | 0 = Double Top | 1 = Higher High
            /// </summary>
            public int CurRelation { get; set; }
            //-----------------------------------------------------------------------------------------
            #endregion

            #region Last values
            //-----------------------------------------------------------------------------------------
            /// <summary>
            /// Represents the price of the last swing.
            /// </summary>
            public double LastPrice { get; set; }
            /// <summary>
            /// Represents the bar number of the highest/lowest bar of the last swing.
            /// </summary>
            public int LastBar { get; set; }
            /// <summary>
            /// Represents the duration as time values of the last swing.
            /// </summary>
            public DateTime LastDateTime { get; set; }
            /// <summary>
            /// Represents the duration in bars of the last swing.
            /// </summary>
            public int LastDuration { get; set; }
            /// <summary>
            /// Represents the swing length in ticks of the last swing.
            /// </summary>
            public int LastLength { get; set; }
            /// <summary>
            /// Represents the percentage in relation between the previous swing and the last swing.
            /// E. g. 61.8% fib retracement.
            /// </summary>
            public double LastPercent { get; set; }
            /// <summary>
            /// Represents the duration as integer in HHMMSS of the last swing.
            /// </summary>
            public int LastTime { get; set; }
            /// <summary>
            /// Represents the entire volume of the last swing.
            /// </summary>
            public long LastVolume { get; set; }
            /// <summary>
            /// Represents the relation to the previous swing.
            /// -1 = Lower High | 0 = Double Top | 1 = Higher High
            /// </summary>
            public int LastRelation { get; set; }
            //-----------------------------------------------------------------------------------------
            #endregion

            #region Other values
            //-----------------------------------------------------------------------------------------
            /// <summary>
            /// Represents the number of swings.
            /// </summary>
            public int Counter { get; set; }
            /// <summary>
            /// Indicates if a new swing is found.
            /// </summary>
            public bool New { get; set; }
            /// <summary>
            /// Indicates if a the current swing is updated.
            /// </summary>
            public bool Update { get; set; }
            /// <summary>
            /// Represents the volume of the signal bar for the swing.
            /// </summary>
            public double SignalBarVolume { get; set; }
            /// <summary>
            /// Represents the number of the last swing in the swing list.
            /// </summary>
            public int ListCount { get; set; }
            //-----------------------------------------------------------------------------------------
            #endregion
        }
        //=============================================================================================
        #endregion

        #region public class CurrentSwing
        //=============================================================================================
        public class SwingCurrent
        {
            /// <summary>
            /// Represents the swing slope direction. -1 = down | 0 = init | 1 = up.
            /// </summary>
            public int SwingSlope { get; set; }
            /// <summary>
            /// Represents the bar number of the swing slope change bar.
            /// </summary>
            public int SwingSlopeChangeBar { get; set; }
            /// <summary>
            /// Indicates if a new swing is found. And whether it is a swing high or a swing low.
            /// Used to control, that either a swing high or a swing low is set for each bar.
            /// 0 = no swing | -1 = down swing | 1 = up swing
            /// </summary>
            public int NewSwing { get; set; }
            /// <summary>
            /// Represents the number of consecutives up/down bars.
            /// </summary>
            public int ConsecutiveBars { get; set; }
            /// <summary>
            /// Represents the bar number of the last bar which was counted to the
            /// consecutives up/down bars.
            /// </summary>
            public int ConsecutiveBarNumber { get; set; }
            /// <summary>
            /// Represents the high/low of the last consecutive bar.
            /// </summary>
            public double ConsecutiveBarValue { get; set; }
            /// <summary>
            /// Indicates if the outside bar calculation is stopped. Used to avoid an up swing and
            /// a down swing in one bar.
            /// </summary>
            public bool StopOutsideBarCalc { get; set; }
        }
        //=============================================================================================
        #endregion

        #region public class SwingProperties
        //=============================================================================================
        public class SwingProperties
        {
            public SwingProperties(double swingSize, int dtbStrength)
            {
                SwingSize = swingSize;
                DtbStrength = dtbStrength;
            }

            public SwingProperties(SwingStyle swingType, double swingSize, int dtbStrength,
                SwingLengthStyle swingLengthType, SwingDurationStyle swingDurationType,
                bool showSwingPrice, bool showSwingLabel, bool showSwingPercent,
                SwingTimeStyle swingTimeType, SwingVolumeStyle swingVolumeType,
                VisualizationStyle visualizationType, bool useBreakouts, bool ignoreInsideBars,
                bool useAutoScale, Brush zigZagColorUp, Brush zigZagColorDn,
                DashStyleHelper zigZagStyle, int zigZagWidth, Brush textColorHigherHigh,
                Brush textColorLowerHigh, Brush textColorDoubleTop, Brush textColorHigherLow,
                Brush textColorLowerLow, Brush textColorDoubleBottom, SimpleFont textFont,
                int textOffsetLength, int textOffsetPercent, int textOffsetPrice, int textOffsetLabel,
                int textOffsetTime, int textOffsetVolume, bool useCloseValues,
                bool drawSwingsOnPricePanel)
            {
                SwingType = swingType;
                SwingSize = swingSize;
                DtbStrength = dtbStrength;
                SwingLengthType = swingLengthType;
                SwingDurationType = swingDurationType;
                ShowSwingPrice = showSwingPrice;
                ShowSwingLabel = showSwingLabel;
                ShowSwingPercent = showSwingPercent;
                SwingTimeType = swingTimeType;
                SwingVolumeType = swingVolumeType;
                VisualizationType = visualizationType;
                UseBreakouts = useBreakouts;
                IgnoreInsideBars = ignoreInsideBars;
                UseAutoScale = useAutoScale;
                ZigZagColorUp = zigZagColorUp;
                ZigZagColorDn = zigZagColorDn;
                ZigZagStyle = zigZagStyle;
                ZigZagWidth = zigZagWidth;
                TextColorHigherHigh = textColorHigherHigh;
                TextColorLowerHigh = textColorLowerHigh;
                TextColorDoubleTop = textColorDoubleTop;
                TextColorHigherLow = textColorHigherLow;
                TextColorLowerLow = textColorLowerLow;
                TextColorDoubleBottom = textColorDoubleBottom;
                TextFont = textFont;
                TextOffsetLength = textOffsetLength;
                TextOffsetPercent = textOffsetPercent;
                TextOffsetPrice = textOffsetPrice;
                TextOffsetLabel = textOffsetLabel;
                TextOffsetTime = textOffsetTime;
                TextOffsetVolume = textOffsetVolume;
                UseCloseValues = useCloseValues;
                DrawSwingsOnPricePanel = drawSwingsOnPricePanel;
            }

            /// <summary>
            /// Represents the swing type.
            /// </summary>
            public SwingStyle SwingType { get; set; }
            /// <summary>
            /// Represents the swing size. e.g. 1 = small swings and 5 = bigger swings.
            /// </summary>
            public double SwingSize { get; set; }
            /// <summary>
            /// Represents the double top and double bottom strength.
            /// </summary>
            public int DtbStrength { get; set; }
            /// <summary>
            /// Represents the swing length visualization type.
            /// </summary>
            public SwingLengthStyle SwingLengthType { get; set; }
            /// <summary>
            /// Represents the swing duration visualization type.
            /// </summary>
            public SwingDurationStyle SwingDurationType { get; set; }
            /// <summary>
            /// Indicates if the swing price is shown.
            /// </summary>
            public bool ShowSwingPrice { get; set; }
            /// <summary>
            /// Indicates if the swing label is shown.
            /// </summary>
            public bool ShowSwingLabel { get; set; }
            /// <summary>
            /// Indicates if the swing percentage in relation to the last swing is shown.
            /// </summary>
            public bool ShowSwingPercent { get; set; }
            /// <summary>
            /// Represents the swing time visualization type.
            /// </summary>
            public SwingTimeStyle SwingTimeType { get; set; }
            /// <summary>
            /// Represents the swing volume visualization type.
            /// </summary>
            public SwingVolumeStyle SwingVolumeType { get; set; }
            /// <summary>
            /// Represents the swing visualization type.
            /// </summary>
            public VisualizationStyle VisualizationType { get; set; }
            /// <summary>
            /// Indicates if the Gann swings are updated if the last swing high/low is broken.
            /// </summary>
            public bool UseBreakouts { get; set; }
            /// <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>
            public bool IgnoreInsideBars { get; set; }
            /// <summary>
            /// Indicates if AutoScale is used.
            /// </summary>
            public bool UseAutoScale { get; set; }
            /// <summary>
            /// Represents the colour of the zig-zag up lines.
            /// </summary>
            public Brush ZigZagColorUp { get; set; }
            /// <summary>
            /// Represents the colour of the zig-zag down lines.
            /// </summary>
            public Brush ZigZagColorDn { get; set; }
            /// <summary>
            /// Represents the line style of the zig-zag lines.
            /// </summary>
            public DashStyleHelper ZigZagStyle { get; set; }
            /// <summary>
            /// Represents the line width of the zig-zag lines.
            /// </summary>
            public int ZigZagWidth { get; set; }
            /// <summary>
            /// Represents the colour of the swing value output for higher highs.
            /// </summary>
            public Brush TextColorHigherHigh { get; set; }
            /// <summary>
            /// Represents the colour of the swing value output for lower highs.
            /// </summary>
            public Brush TextColorLowerHigh { get; set; }
            /// <summary>
            /// Represents the colour of the swing value output for double tops.
            /// </summary>
            public Brush TextColorDoubleTop { get; set; }
            /// <summary>
            /// Represents the colour of the swing value output for higher lows.
            /// </summary>
            public Brush TextColorHigherLow { get; set; }
            /// <summary>
            /// Represents the colour of the swing value output for lower lows.
            /// </summary>
            public Brush TextColorLowerLow { get; set; }
            /// <summary>
            /// Represents the colour of the swing value output for double bottems.
            /// </summary>
            public Brush TextColorDoubleBottom { get; set; }
            /// <summary>
            /// Represents the text font for the swing value output.
            /// </summary>
            public SimpleFont TextFont { get; set; }
            /// <summary>
            /// Represents the text offset in pixel for the swing length.
            /// </summary>
            public int TextOffsetLength { get; set; }
            /// <summary>
            /// Represents the text offset in pixel for the retracement value.
            /// </summary>
            public int TextOffsetPercent { get; set; }
            /// <summary>
            /// Represents the text offset in pixel for the swing price.
            /// </summary>
            public int TextOffsetPrice { get; set; }
            /// <summary>
            /// Represents the text offset in pixel for the swing labels.
            /// </summary>
            public int TextOffsetLabel { get; set; }
            /// <summary>
            /// Represents the text offset in pixel for the swing time.
            /// </summary>
            public int TextOffsetTime { get; set; }
            /// <summary>
            /// Represents the text offset in pixel for the swing volume.
            /// </summary>
            public int TextOffsetVolume { get; set; }
            /// <summary>
            /// Indicates if high and low prices are used for the swing calculations or close values.
            /// </summary>
            public bool UseCloseValues { get; set; }
            /// <summary>
            /// Indicates if the swings are drawn on the price panel.
            /// </summary>
            public bool DrawSwingsOnPricePanel { get; set; }
        }
        //=============================================================================================
        #endregion

        #region public struct SwingStruct
        //=============================================================================================
        public struct SwingStruct
        {
            /// <summary>
            /// Swing price.
            /// </summary>
            public double price;
            /// <summary>
            /// Swing bar number.
            /// </summary>
            public int barNumber;
            /// <summary>
            /// Swing time.
            /// </summary>
            public DateTime time;
            /// <summary>
            /// Swing duration in bars.
            /// </summary>
            public int duration;
            /// <summary>
            /// Swing length in ticks.
            /// </summary>
            public int length;
            /// <summary>
            /// Swing relation.
            /// -1 = Lower | 0 = Double | 1 = Higher
            /// </summary>
            public int relation;
            /// <summary>
            /// Swing volume.
            /// </summary>
            public long volume;

            public SwingStruct(double swingPrice, int swingBarNumber, DateTime swingTime,
                    int swingDuration, int swingLength, int swingRelation, long swingVolume)
            {
                price = swingPrice;
                barNumber = swingBarNumber;
                time = swingTime;
                duration = swingDuration;
                length = swingLength;
                relation = swingRelation;
                volume = swingVolume;
            }
        }
        //=============================================================================================
        #endregion

        #region Enums
        //=============================================================================================
        public enum VisualizationStyle
        {
            False,
            Dots,
            Dots_ZigZag,
            ZigZag,
            ZigZagVolume,
            GannStyle,
        }

        public enum SwingStyle
        {
            Standard,
            Gann,
            Ticks,
            Percent,
        }

        public enum SwingLengthStyle
        {
            False,
            Ticks,
            Ticks_Price,
            Price_Ticks,
            Points,
            Points_Price,
            Price_Points,
            Price,
            Percent,
        }

        public enum SwingDurationStyle
        {
            False,
            Bars,
            MMSS,
            HHMM,
            SecondsTotal,
            MinutesTotal,
            HoursTotal,
            Days,
        }

        public enum SwingTimeStyle
        {
            False,
            Integer,
            HHMM,
            HHMMSS,
            DDMM,
        }
        
        public enum SwingVolumeStyle
        {
            False,
            Absolute,
            Relative,
        }

        public enum AbcPatternMode
        {
            False,
            Long_Short,
            Long,
            Short,
        }

        public enum StatisticPositionStyle
        {
            False,
            Bottom,
            Top,
        }

        public enum RiskManagementStyle
        {
            False,
            ToolStrip,
            Tab,
        }

        public enum DivergenceMode
        {
            Custom,
            False,
            GomCD,
            MACD,
            Stochastics,
        }
        public enum DivergenceDirection
        {
            Long,
            Long_Short,
            Short
        }
        public enum Show
        {
            Trend,
            Relation,
            Volume,
        }
        //=============================================================================================
        #endregion
}


#region NinjaScript generated code. Neither change nor remove.

namespace NinjaTrader.NinjaScript.Indicators
{
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
        private PriceActionSwing.PriceActionSwing[] cachePriceActionSwing;
        public PriceActionSwing.PriceActionSwing PriceActionSwing(SwingStyle swingType, double swingSize, int dtbStrength, bool useCloseValues, 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 ignoreInsideBars, bool useBreakouts)
        {
            return PriceActionSwing(Input, swingType, swingSize, dtbStrength, useCloseValues, swingLengthType, swingDurationType, showSwingPrice, showSwingLabel, showSwingPercent, swingTimeType, swingVolumeType, visualizationType, textFont, textOffsetLength, textOffsetVolume, textOffsetPrice, textOffsetLabel, textOffsetTime, textOffsetPercent, zigZagStyle, zigZagWidth, ignoreInsideBars, useBreakouts);
        }

        public PriceActionSwing.PriceActionSwing PriceActionSwing(ISeries<double> input, SwingStyle swingType, double swingSize, int dtbStrength, bool useCloseValues, 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 ignoreInsideBars, bool useBreakouts)
        {
            if (cachePriceActionSwing != null)
                for (int idx = 0; idx < cachePriceActionSwing.Length; idx++)
                    if (cachePriceActionSwing[idx] != null && cachePriceActionSwing[idx].SwingType == swingType && cachePriceActionSwing[idx].SwingSize == swingSize && cachePriceActionSwing[idx].DtbStrength == dtbStrength && cachePriceActionSwing[idx].UseCloseValues == useCloseValues && cachePriceActionSwing[idx].SwingLengthType == swingLengthType && cachePriceActionSwing[idx].SwingDurationType == swingDurationType && cachePriceActionSwing[idx].ShowSwingPrice == showSwingPrice && cachePriceActionSwing[idx].ShowSwingLabel == showSwingLabel && cachePriceActionSwing[idx].ShowSwingPercent == showSwingPercent && cachePriceActionSwing[idx].SwingTimeType == swingTimeType && cachePriceActionSwing[idx].SwingVolumeType == swingVolumeType && cachePriceActionSwing[idx].VisualizationType == visualizationType && cachePriceActionSwing[idx].TextFont == textFont && cachePriceActionSwing[idx].TextOffsetLength == textOffsetLength && cachePriceActionSwing[idx].TextOffsetVolume == textOffsetVolume && cachePriceActionSwing[idx].TextOffsetPrice == textOffsetPrice && cachePriceActionSwing[idx].TextOffsetLabel == textOffsetLabel && cachePriceActionSwing[idx].TextOffsetTime == textOffsetTime && cachePriceActionSwing[idx].TextOffsetPercent == textOffsetPercent && cachePriceActionSwing[idx].ZigZagStyle == zigZagStyle && cachePriceActionSwing[idx].ZigZagWidth == zigZagWidth && cachePriceActionSwing[idx].IgnoreInsideBars == ignoreInsideBars && cachePriceActionSwing[idx].UseBreakouts == useBreakouts && cachePriceActionSwing[idx].EqualsInput(input))
                        return cachePriceActionSwing[idx];
            return CacheIndicator<PriceActionSwing.PriceActionSwing>(new PriceActionSwing.PriceActionSwing(){ SwingType = swingType, SwingSize = swingSize, DtbStrength = dtbStrength, UseCloseValues = useCloseValues, 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, IgnoreInsideBars = ignoreInsideBars, UseBreakouts = useBreakouts }, input, ref cachePriceActionSwing);
        }
    }
}

namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
        public Indicators.PriceActionSwing.PriceActionSwing PriceActionSwing(SwingStyle swingType, double swingSize, int dtbStrength, bool useCloseValues, 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 ignoreInsideBars, bool useBreakouts)
        {
            return indicator.PriceActionSwing(Input, swingType, swingSize, dtbStrength, useCloseValues, swingLengthType, swingDurationType, showSwingPrice, showSwingLabel, showSwingPercent, swingTimeType, swingVolumeType, visualizationType, textFont, textOffsetLength, textOffsetVolume, textOffsetPrice, textOffsetLabel, textOffsetTime, textOffsetPercent, zigZagStyle, zigZagWidth, ignoreInsideBars, useBreakouts);
        }

        public Indicators.PriceActionSwing.PriceActionSwing PriceActionSwing(ISeries<double> input , SwingStyle swingType, double swingSize, int dtbStrength, bool useCloseValues, 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 ignoreInsideBars, bool useBreakouts)
        {
            return indicator.PriceActionSwing(input, swingType, swingSize, dtbStrength, useCloseValues, swingLengthType, swingDurationType, showSwingPrice, showSwingLabel, showSwingPercent, swingTimeType, swingVolumeType, visualizationType, textFont, textOffsetLength, textOffsetVolume, textOffsetPrice, textOffsetLabel, textOffsetTime, textOffsetPercent, zigZagStyle, zigZagWidth, ignoreInsideBars, useBreakouts);
        }
    }
}

namespace NinjaTrader.NinjaScript.Strategies
{
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
        public Indicators.PriceActionSwing.PriceActionSwing PriceActionSwing(SwingStyle swingType, double swingSize, int dtbStrength, bool useCloseValues, 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 ignoreInsideBars, bool useBreakouts)
        {
            return indicator.PriceActionSwing(Input, swingType, swingSize, dtbStrength, useCloseValues, swingLengthType, swingDurationType, showSwingPrice, showSwingLabel, showSwingPercent, swingTimeType, swingVolumeType, visualizationType, textFont, textOffsetLength, textOffsetVolume, textOffsetPrice, textOffsetLabel, textOffsetTime, textOffsetPercent, zigZagStyle, zigZagWidth, ignoreInsideBars, useBreakouts);
        }

        public Indicators.PriceActionSwing.PriceActionSwing PriceActionSwing(ISeries<double> input , SwingStyle swingType, double swingSize, int dtbStrength, bool useCloseValues, 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 ignoreInsideBars, bool useBreakouts)
        {
            return indicator.PriceActionSwing(input, swingType, swingSize, dtbStrength, useCloseValues, swingLengthType, swingDurationType, showSwingPrice, showSwingLabel, showSwingPercent, swingTimeType, swingVolumeType, visualizationType, textFont, textOffsetLength, textOffsetVolume, textOffsetPrice, textOffsetLabel, textOffsetTime, textOffsetPercent, zigZagStyle, zigZagWidth, ignoreInsideBars, useBreakouts);
        }
    }
}

#endregion
 
Status
Not open for further replies.

Similar threads

Top