Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ReversalBar_V2 convert/port to NT8

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    ReversalBar_V2 convert/port to NT8

    Would a good soul help convert this to NT8?

    Thanks in advance!

    Original credits are in the code

    Code:
    /*
    Reversal Bar by cunparis
    
    This indicator will color a reversal bar grey.
    It is designed to be used on range charts.
    If you see a lot of grey bars then it could be consolidation.
    If you see a lot of colored bars then price is moving nicely.
    
    20100101 v1.0
    First version.  No alerts yet, I will add them later.
    
    20100106 v1.1
    Fixed problem with saving color parameters.
    Added purple bars for consolidation
    
    */
    
    #region Using declarations
    using System;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.ComponentModel;
    using System.Xml.Serialization;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    #endregion
    
    namespace NinjaTrader.Indicator
    {
        [Description("ReversalBar_V2")]  // Jan. 28, 2010, TheWizard added serialization to the colors so they will be saved if you change them & then save your template & re-load it
        [Gui.Design.DisplayName("ReversalBar_V2")]
        public class ReversalBar_V2 : Indicator  // Changed the name to _V2 so as not to conflict with the original indicator posted by Cunparis.
        {
            private bool useAlerts             = false;
            private bool paintbar            = true;        
    
            private Color colorUp             = Color.Blue;
            private Color colorDown         = Color.Red;
            private Color colorReversal        = Color.Gray;
            private Color colorCongestion    = Color.Purple;
    
            private int  lastSoundBar    = 0;
            private DataSeries BarColorData;
    
            protected override void Initialize()
            {
                Overlay                = true;
                PriceTypeSupported    = false;
                Panel = 1;
    
                BarColorData = new DataSeries(this);
            }
    
            protected void doSetBarColor() {
                if(Instrument.MasterInstrument.Compare(Close[1],Open[1]) == 1) {
                    if(Instrument.MasterInstrument.Compare(Close[0], Open[0]) == 1) {
                        BarColorData.Set(1);
                    } else {
                        BarColorData.Set(0);
                    }
                } else if(Instrument.MasterInstrument.Compare(Close[1],Open[1]) == -1) {
                    if(Instrument.MasterInstrument.Compare(Close[0], Open[0]) == -1) {
                        BarColorData.Set(-1);
                    } else {
                        BarColorData.Set(0);
                    }
                }
    
                bool overlap = false;
                if(MAX(High, 5)[0] - MIN(Low,5)[0] < 2 * Bars.Period.Value * TickSize) {
                    //Print(Time[0] + " H=" + MAX(High, 5)[0] + " L=" + MIN(Low,5)[0]);
                    overlap = true;
                }
                if(MAX(High, 4)[0] - MIN(Low,4)[0] < 1.5 * Bars.Period.Value * TickSize) {
                    overlap = true;
                }
    
                if(BarColorData[0] == 1) {
                    BarColor = colorUp;
                } else if(BarColorData[0] == -1) {
                    BarColor = colorDown;
                } else if(BarColorData[0] == 0) {
                    if(overlap) {
                        BarColor = colorCongestion;
                    } else {
                        BarColor = colorReversal;
                    }
                }
            }
    
            protected bool barOverlap(int i) {
                if(Math.Abs(High[i] - High[i-1]) <= 2*TickSize && Math.Abs(Low[0] - Low[i-1]) <= 2*TickSize) {
                    return true;
                } else {
                    return false;
                }
            }
    
            protected override void OnBarUpdate()
            {
                if(CurrentBar < 4) {
                    return;
                }
    
                if(paintbar) {
                    doSetBarColor();
                }
    
            }
    
    
    //        [Description("Use Audio Alerts?")]
    //        [Category("Parameters")]
    //        public bool UseAlerts
    //        {
    //            get { return useAlerts; }
    //            set { useAlerts = value; }
    //        }
    
            [Description("Paint Bars?")]
            [Category("Visual")]
            [Gui.Design.DisplayName ("1. Paint Bars?")]
            public bool Paintbar
            {
                get { return paintbar; }
                set { paintbar = value; }
            }
    
            [XmlIgnore()]
            [Description("Color Up")]
            [Category("Visual")]
            [Gui.Design.DisplayName ("2. Color Up")]
            public Color ColorUp
            {
                get { return colorUp; }
                set { colorUp = value; }
            }
    // Serialization of the colors added by TheWizard January 28, 2010
            [Browsable(false)]
            public string colorUpSerialize
            {
                get { return NinjaTrader.Gui.Design.SerializableColor.ToString(colorUp); }
                set { colorUp = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
            }
            [XmlIgnore()]
            [Description("Color Down")]
            [Category("Visual")]
            [Gui.Design.DisplayName ("3. Color Down")]
            public Color ColorDown
            {
                get { return colorDown; }
                set { colorDown = value; }
            }
    // Serialization of the colors added by TheWizard January 28, 2010
            [Browsable(false)]
            public string colorDownSerialize
            {
                get { return NinjaTrader.Gui.Design.SerializableColor.ToString(colorDown); }
                set { colorDown = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
            }
            [XmlIgnore()]
            [Description("Color Reversal")]
            [Category("Visual")]
            [Gui.Design.DisplayName ("4. Color Reversal")]
            public Color ColorReversal
            {
                get { return colorReversal; }
                set { colorReversal = value; }
            }
    // Serialization of the colors added by TheWizard January 28, 2010
            [Browsable(false)]
            public string colorReversalSerialize
            {
                get { return NinjaTrader.Gui.Design.SerializableColor.ToString(colorReversal); }
                set { colorReversal = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
            }
            [XmlIgnore()]
            [Description("Color Congestion")]
            [Category("Visual")]
            [Gui.Design.DisplayName ("5. Color Congestion")]
            public Color ColorCongestion
            {
                get { return colorCongestion; }
                set { colorCongestion = value; }
            }
    // Serialization of the colors added by TheWizard January 28, 2010
            [Browsable(false)]
            public string colorCongestionSerialize
            {
                get { return NinjaTrader.Gui.Design.SerializableColor.ToString(colorCongestion); }
                set { colorCongestion = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
            }
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
        public partial class Indicator : IndicatorBase
        {
            private ReversalBar_V2[] cacheReversalBar_V2 = null;
    
            private static ReversalBar_V2 checkReversalBar_V2 = new ReversalBar_V2();
    
            /// <summary>
            /// ReversalBar_V2
            /// </summary>
            /// <returns></returns>
            public ReversalBar_V2 ReversalBar_V2()
            {
                return ReversalBar_V2(Input);
            }
    
            /// <summary>
            /// ReversalBar_V2
            /// </summary>
            /// <returns></returns>
            public ReversalBar_V2 ReversalBar_V2(Data.IDataSeries input)
            {
    
                if (cacheReversalBar_V2 != null)
                    for (int idx = 0; idx < cacheReversalBar_V2.Length; idx++)
                        if (cacheReversalBar_V2[idx].EqualsInput(input))
                            return cacheReversalBar_V2[idx];
    
                ReversalBar_V2 indicator = new ReversalBar_V2();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
                indicator.Input = input;
                indicator.SetUp();
    
                ReversalBar_V2[] tmp = new ReversalBar_V2[cacheReversalBar_V2 == null ? 1 : cacheReversalBar_V2.Length + 1];
                if (cacheReversalBar_V2 != null)
                    cacheReversalBar_V2.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheReversalBar_V2 = tmp;
                Indicators.Add(indicator);
    
                return indicator;
            }
    
        }
    }
    
    // This namespace holds all market analyzer column definitions and is required. Do not change it.
    namespace NinjaTrader.MarketAnalyzer
    {
        public partial class Column : ColumnBase
        {
            /// <summary>
            /// ReversalBar_V2
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.ReversalBar_V2 ReversalBar_V2()
            {
                return _indicator.ReversalBar_V2(Input);
            }
    
            /// <summary>
            /// ReversalBar_V2
            /// </summary>
            /// <returns></returns>
            public Indicator.ReversalBar_V2 ReversalBar_V2(Data.IDataSeries input)
            {
                return _indicator.ReversalBar_V2(input);
            }
    
        }
    }
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        public partial class Strategy : StrategyBase
        {
            /// <summary>
            /// ReversalBar_V2
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.ReversalBar_V2 ReversalBar_V2()
            {
                return _indicator.ReversalBar_V2(Input);
            }
    
            /// <summary>
            /// ReversalBar_V2
            /// </summary>
            /// <returns></returns>
            public Indicator.ReversalBar_V2 ReversalBar_V2(Data.IDataSeries input)
            {
                if (InInitialize && input == null)
                    throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
    
                return _indicator.ReversalBar_V2(input);
            }
    
        }
    }
    #endregion
    ​

    Attached Files

    #2
    Hello mazpat_3,

    Thank you for your post.

    Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. That said, this thread will remain open in case anyone in the forum community would like to assist you with this conversion.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team to follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.

    Thank you for using NinjaTrader.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    633 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    364 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    567 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    568 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X