Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Help

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

    Help

    Hi Can someone please help me add arrows to this indicator? i will like an arrow up or Down to show each time is changes color.



    /*
    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.FromStrin g(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.FromStrin g(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.FromStrin g(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.FromStrin g(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];

    lock (checkReversalBar_V2)
    {
    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;
    #if NT7
    indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
    indicator.MaximumBarsLookBack = MaximumBarsLookBack;
    #endif
    indicator.Input = input;
    Indicators.Add(indicator);
    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;
    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

    #2
    Try this out. Arrows added for when bars turn red or blue (with options)
    Attached Files

    Comment


      #3
      Hello odmassion,

      Thank you for your note.

      I added the following if statements to your code (in bold), which check to see if the last BarColorData was not equal to the current, and if so, draw an arrow.

      Please let us know if you need further assistance.

      Code:
      if(BarColorData[0] == 1) 
      {
      	BarColor = colorUp;
      	[B]if(BarColorData[1] != 1) //If last BarColorData was not equal to 1, than draw arrow.
      	{
      		DrawArrowUp( "My Up arrow" + CurrentBar, false, 0 , High[0], Color.Lime);
      	}[/B]
      } 
      else if(BarColorData[0] == -1) 
      {
      	BarColor = colorDown;
      [B]	if(BarColorData[1] != -1) 
      	{
      		DrawArrowDown( "My Down arrow" + CurrentBar, false, 0 , High[0], Color.Red);
      	}[/B]
      	
      }
      Alan P.NinjaTrader Customer Service

      Comment


        #4
        indicator

        Thank you so much.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by junkone, Today, 11:37 AM
        0 responses
        1 view
        0 likes
        Last Post junkone
        by junkone
         
        Started by quantismo, 04-17-2024, 05:13 PM
        5 responses
        34 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by proptrade13, Today, 11:06 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by love2code2trade, 04-17-2024, 01:45 PM
        4 responses
        34 views
        0 likes
        Last Post love2code2trade  
        Started by cls71, Today, 04:45 AM
        2 responses
        10 views
        0 likes
        Last Post eDanny
        by eDanny
         
        Working...
        X