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!!!

    Please help me modify the following indicator for NT7 to paint an arrow on the first tick of d new bar when the bar 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
    Hello,

    Thank you for the post.

    If you are trying to complete an action on the first tick of a bar, you can use FirstTickOfBar



    To append an action when the color changes, you could add a condition to the OnBarUpdate region in the file. To check the value of the plot on the FirstTickOfBar it would like the following:


    Code:
    if (CurrentBar > 0 && FirstTickOfBar)
    {
        if(BarColorData[1] == 1) {
            DrawArrowUp("UpArrow" + CurrentBar, true, 0, Low[0] - TickSize, Color.Red);
        } else if(BarColorData[1] == -1) {
             DrawArrowDown("DownArrow" + CurrentBar, true, 0, Low[0] - TickSize, Color.Red);
        }
    }



    This would check the plots prior bars value on the first tick of bar, then plot an arrow according to the plots value. This could could be added to the top of OnBarUpdate:

    Code:
    protected override void OnBarUpdate()
    {
        if (CurrentBar > 0 && FirstTickOfBar)
        {
            if(BarColorData[1] == 1) {
                DrawArrowUp("UpArrow" + CurrentBar, true, 0, Low[0] - TickSize, Color.Red);
            } else if(BarColorData[1] == -1) {
                 DrawArrowDown("DownArrow" + CurrentBar, true, 0, Low[0] - TickSize, Color.Red);
            }
        }
    }
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello

      Hi, can you please help me add the modification to the indicator? I don't know where to put that code you wrote. Can you please can you please complete the modification. Am not a programmer so, I really didn't know where to add those code that you gave me. Please please help me do the modification.
      Thanks

      Comment


        #4
        Hello Odmassion,

        You should add the code Jesse provided within OnBarUpdate. So for example,

        Code:
        protected override void OnBarUpdate()
        {
           if(CurrentBar < 4) 
           {
             return;
           }
        
           if (CurrentBar > 0 && FirstTickOfBar)
           {
              if(BarColorData[1] == 1) 
              {
                 DrawArrowUp("UpArrow" + CurrentBar, true, 0, Low[0] - TickSize, Color.Red);
              } 
             else if(BarColorData[1] == -1) 
             {
                DrawArrowDown("DownArrow" + CurrentBar, true, 0, Low[0] - TickSize, Color.Red);
             }
        }
        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Hi, thanks for replying. Sorry to bother you again. I don't know Where to put those codes that you guys gave to me. Can you please enter them in the right location and help me complete the indicator. I have no idea what part of the script I should put the coding that you gave me. Can you please insert them in location and complete the indicator for me?
          Thanks again for your help.

          Comment


            #6
            Hello odmassion,

            In the support department at NinjaTrader we do not create, debug, or modify code for our clients. This is so that we can maintain a high level of service for all of our clients as well as our partners.

            We do have a large ecosystem available to help you with programming logic questions. You can post on our forum and ask the other 40,000+ forum members.


            You can also contact a professional NinjaScript Consultants who would be eager to create or modify this script at your request or assist you with your script. Please let me know if you would like our business development follow up with you with a list of professional NinjaScript Consultants who would be happy to create this script or any others at your request.

            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Kaledus, Today, 01:29 PM
            4 responses
            11 views
            0 likes
            Last Post Kaledus
            by Kaledus
             
            Started by alifarahani, Today, 09:40 AM
            5 responses
            22 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by gentlebenthebear, Today, 01:30 AM
            3 responses
            16 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by PhillT, Today, 02:16 PM
            2 responses
            7 views
            0 likes
            Last Post PhillT
            by PhillT
             
            Started by frankthearm, Yesterday, 09:08 AM
            14 responses
            47 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Working...
            X