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

Outside Bar

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

    Outside Bar

    Hi please help me correct this code I want to see out side bars marked with "OB" how can I make changes in the following script.
    regards
    nh
    HTML Code:
     {            
                if (CurrentBar == 0)
                {
                    return;
                }
                if (High[0] > High[1] 
                    && Low[0] < Low[1]) // outside bar
                    {
                    if ( outsidedepends == true) // Outsidebar labeling depends on prior labeling
                        {
                        if (L == 1
                            & Close[0] > Open[0]) // outside H
                            {
                            DrawText("H"+CurrentBar, "H", 0, High[0] + TextTicksOffset * TickSize, textColorH, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                            H = 1;
                            L = 0;
                            }
                        else if (H == 1
                            & Close[0] < Open[0])// outside L
                            {    
                            DrawText("L"+CurrentBar, "L", 0, Low[0] - TextTicksOffset * TickSize, textColorL, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                            H = 0;
                            L = 1;
                            }
                        else  // Outsidebar labeling starts neutral with H and L
                            {
                            DrawText("H"+CurrentBar, "H", 0, High[0] + TextTicksOffset * TickSize, textColorH, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                            DrawText("L"+CurrentBar, "L", 0, Low[0] - TextTicksOffset * TickSize, textColorL, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                            H = 1;
                            L = 1;
                            }
                        }
                    else  // Outsidebar labeling starts neutral with H and L
                            {
                            DrawText("H"+CurrentBar, "H", 0, High[0] + TextTicksOffset * TickSize, textColorH, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                            DrawText("L"+CurrentBar, "L", 0, Low[0] - TextTicksOffset * TickSize, textColorL, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                            H = 1;
                            L = 1;
                            }    
                    }
                else if (High[0] > High[1] // H bar
                    && L == 1)
                    {
                        DrawText("H"+CurrentBar, "H", 0, High[0] + TextTicksOffset * TickSize, textColorH, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                        H = 1;
                        L = 0;
                    }
                else if (Low[0] < Low[1] // L bar
                    && H == 1)
                    {
                        DrawText("L"+CurrentBar, "L", 0, Low[0] - TextTicksOffset * TickSize, textColorL, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                        H = 0;
                        L = 1;
                    }

    #2
    Hi ninja hattori,

    Can you please clarify the issue you are experiencing with this code/indicator.
    TimNinjaTrader Customer Service

    Comment


      #3
      Thanks to the original creator of this indicator,
      changed script to show out side bar and inside bar marked as OB and IB.This indicator is based on Al Brooks PA.This indicator shows only high(H) and low(L) ,how can I see bars numbers as H1,H2.....and L1,L2....... as per brooks price action >
      download setup 1


      Its a long script so posting half in the next post
      HTML Code:
      // A little help to label the bars with H1, H2, H3, ... and L1, L2, L3, ... 
      // As discussed in the book "Reading Price Charts Bar by Bar" by Al Brooks.
      // No, the "indicator" is not able to guess the correct numbers of H1, H2 ... 
      // The rules therefore are not strict enough. But you know them...
      // ... and to add the numbers could improve your results in counting the legs.
      // For adding the correct numbers to the labels, just click the letter and then double click to edit.
      // We are always waiting for the close of the bar. So CalculateOnBarClose is set to true.
      // v0.2 Outsidebar depending on previous labeling and close of outsidebar.
      // If depending is set to "false", the outsidebar will be labeled with both H and L and 
      // starts there from a neutral position. If depending is set to "true" , it is 
      // labeled only with H (L) if the last label was L (H) and the bar close > open (close < open), 
      // and "counting" will then not be set to neutral.
      // v0.3 Insidebar label added.
      
      #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;
      using NinjaTrader.Gui.Design;
      using NinjaTrader.Cbi;
      #endregion
      
      // This namespace holds all indicators and is required. Do not change it.
      namespace NinjaTrader.Indicator
      {
          [Description("LegHLiii")]
          [Gui.Design.DisplayName("LegHLiii")]
          public class LegHLiii : Indicator
          {
              
              #region Variables
              private int H = 0;
              private int L = 0;
              private bool iii = true; // iii on/off
              private bool outsidedepends = true; // Outsidebar labeling depends on prior bars on/off 
              private int textTicksOffset = 2; // Default setting for text ticks offset from bars
              private int textTicksiiiOffset = 1; // Default setting for iii ticks offset from bars
              private Font textFont;
              private Font iiiFont;
              private int textSize = 6; // Default text size
              private int textiiiSize = 5; // Default iii text size
              private Color textColorH = Color.Gray; // Color of H
              private Color textColorL = Color.Gray; // Color of L
              private Color textColoriii = Color.Red; // Color of iii
              #endregion
      
              /// <summary>
              /// This method is used to configure the indicator and is called once before any bar data is loaded.
              /// </summary>
              protected override void Initialize()
              {
                  PaintPriceMarkers     = false;
                  Overlay                = true;        
                  CalculateOnBarClose = true;
                  iiiFont = new Font("Arial", textiiiSize, FontStyle.Regular);
                  textFont = new Font("Arial", textSize, FontStyle.Regular);
              }
      
              protected override void OnBarUpdate()
                  
              {            
                  if (CurrentBar == 0)
                  {
                      return;
                  }
                  if (High[0] > High[1] 
                      && Low[0] < Low[1]) // outside bar
                      {
                      if ( outsidedepends == true) // Outsidebar labeling depends on prior labeling
                          {
                          if (L == 1
                              & Close[0] > Open[0]) // outside H
                              {
                              DrawText("H"+CurrentBar, "H", 0, High[0] + TextTicksOffset * TickSize, textColorH, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                              H = 1;
                              L = 0;
                              }
                          else if (H == 1
                              & Close[0] < Open[0])// outside L
                              {    
                              DrawText("L"+CurrentBar, "L", 0, Low[0] - TextTicksOffset * TickSize, textColorL, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                              H = 0;
                              L = 1;
                              }
                          else  // Outsidebar labeling starts neutral with H and L
                              {
                              DrawText("H"+CurrentBar, "H", 0, High[0] + TextTicksOffset * TickSize, textColorH, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                              DrawText("L"+CurrentBar, "L", 0, Low[0] - TextTicksOffset * TickSize, textColorL, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                              H = 1;
                              L = 1;
                              }
                          }
                      else  // Outsidebar labeling starts neutral with H and L
                              {
                              DrawText("H"+CurrentBar, "H", 0, High[0] + TextTicksOffset * TickSize, textColorH, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                              DrawText("L"+CurrentBar, "L", 0, Low[0] - TextTicksOffset * TickSize, textColorL, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                              H = 1;
                              L = 1;
                              }    
                      }
                  else if (High[0] > High[1] // H bar
                      && L == 1)
                      {
                          DrawText("H"+CurrentBar, "H", 0, High[0] + TextTicksOffset * TickSize, textColorH, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                          H = 1;
                          L = 0;
                      }
                  else if (Low[0] < Low[1] // L bar
                      && H == 1)
                      {
                          DrawText("L"+CurrentBar, "L", 0, Low[0] - TextTicksOffset * TickSize, textColorL, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                          H = 0;
                          L = 1;
                      }
                      
                  // Insidebar labeling with i
                  // I replaced the i with an * (chart is better readable)
                  if (iii == true)
                      {
                          if (L == 1
                              && Low[0] >= Low[1] && High[0] <= High[1])
                          {
                              DrawText("i"+CurrentBar, "IB", 0, Low[0] - iiiTextTicksOffset * TickSize, textColoriii, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                          }
                          else if (H == 1
                              && Low[0] >= Low[1] && High[0] <= High[1])
                          {
                              DrawText("i"+CurrentBar, "IB", 0, High[0] + iiiTextTicksOffset * TickSize, textColoriii, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                          }
                          else if (H == 1
                              && L == 1
                              && Low[0] >= Low[1] && High[0] <= High[1])
                          {
                              DrawText("i"+CurrentBar, "IB", 0, High[0] + iiiTextTicksOffset * TickSize, textColoriii, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                          }
                      }
                      if (High[0] > High[1] 
                      && Low[0] < Low[1])
                          {
                              DrawText("i"+CurrentBar, "OB", 0, High[0] + iiiTextTicksOffset * TickSize, textColoriii, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                          }
              }
      

      Comment


        #4
        HTML Code:
        #region Properties
                
                [Description("Insidebars iii")]
                [Category("Parameters")]
                public bool iiiLabel
                {
                    get { return iii; }
                    set { iii = value; }
                }
                
                [Description("Outsidebar labeling depends on prior labeling or not ")]
                [Category("Parameters")]
                public bool Outsidedepends
                {
                    get { return outsidedepends; }
                    set { outsidedepends = value; }
                }
                
                [Description("Text ticks away from bar")]
                [Category("Parameters")]
                public int TextTicksOffset
                {
                    get { return textTicksOffset; }
                    set { textTicksOffset = Math.Max(1, value); }
                }
                        
                [Description("iii ticks away from bar")]
                [Category("Parameters")]
                public int iiiTextTicksOffset
                {
                    get { return textTicksiiiOffset; }
                    set { textTicksiiiOffset = Math.Max(1, value); }
                }
                
                [Description("Text size")]
                [Category("Parameters")]
                public int TextSize
                {
                    get { return textSize; }
                    set { textSize = Math.Max(1, value); }
                }
                    
                [Description("iii text size")]
                [Category("Parameters")]
                public int iiiTextSize
                {
                    get { return textiiiSize; }
                    set { textiiiSize = Math.Max(1, value); }
                }
                
                [Description("Color of H")]
                [Category("Visual")]
                [Gui.Design.DisplayName ("textColorH")]
                public Color TextColorH
                {
                    get { return textColorH; }
                    set { textColorH = value; }
                }
                [Browsable(false)]
                public string TextColorHSerialise
                {
                    get { return Gui.Design.SerializableColor.ToString(textColorH); }
                    set { textColorH = Gui.Design.SerializableColor.FromString(value); }
                }
                
                [Description("Color of L")]
                [Category("Visual")]
                [Gui.Design.DisplayName ("textColorL")]
                public Color TextColorL
                {
                    get { return textColorL; }
                    set { textColorL = value; }
                }
                [Browsable(false)]
                public string TextColorLSerialise
                {
                    get { return Gui.Design.SerializableColor.ToString(textColorL); }
                    set { textColorL = Gui.Design.SerializableColor.FromString(value); }
                }    
                
                [Description("Color of iii")]
                [Category("Visual")]
                [Gui.Design.DisplayName ("textColoriii")]
                public Color TextColoriii
                {
                    get { return textColoriii; }
                    set { textColoriii = value; }
                }
                [Browsable(false)]
                public string TextColoriiiSerialise
                {
                    get { return Gui.Design.SerializableColor.ToString(textColoriii); }
                    set { textColoriii = Gui.Design.SerializableColor.FromString(value); }
                }
                #endregion
            }
        }
        
        #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 LegHLiii[] cacheLegHLiii = null;
        
                private static LegHLiii checkLegHLiii = new LegHLiii();
        
                /// <summary>
                /// LegHLiii
                /// </summary>
                /// <returns></returns>
                public LegHLiii LegHLiii(bool iiiLabel, int iiiTextSize, int iiiTextTicksOffset, bool outsidedepends, int textSize, int textTicksOffset)
                {
                    return LegHLiii(Input, iiiLabel, iiiTextSize, iiiTextTicksOffset, outsidedepends, textSize, textTicksOffset);
                }
        
                /// <summary>
                /// LegHLiii
                /// </summary>
                /// <returns></returns>
                public LegHLiii LegHLiii(Data.IDataSeries input, bool iiiLabel, int iiiTextSize, int iiiTextTicksOffset, bool outsidedepends, int textSize, int textTicksOffset)
                {
                    checkLegHLiii.iiiLabel = iiiLabel;
                    iiiLabel = checkLegHLiii.iiiLabel;
                    checkLegHLiii.iiiTextSize = iiiTextSize;
                    iiiTextSize = checkLegHLiii.iiiTextSize;
                    checkLegHLiii.iiiTextTicksOffset = iiiTextTicksOffset;
                    iiiTextTicksOffset = checkLegHLiii.iiiTextTicksOffset;
                    checkLegHLiii.Outsidedepends = outsidedepends;
                    outsidedepends = checkLegHLiii.Outsidedepends;
                    checkLegHLiii.TextSize = textSize;
                    textSize = checkLegHLiii.TextSize;
                    checkLegHLiii.TextTicksOffset = textTicksOffset;
                    textTicksOffset = checkLegHLiii.TextTicksOffset;
        
                    if (cacheLegHLiii != null)
                        for (int idx = 0; idx < cacheLegHLiii.Length; idx++)
                            if (cacheLegHLiii[idx].iiiLabel == iiiLabel && cacheLegHLiii[idx].iiiTextSize == iiiTextSize && cacheLegHLiii[idx].iiiTextTicksOffset == iiiTextTicksOffset && cacheLegHLiii[idx].Outsidedepends == outsidedepends && cacheLegHLiii[idx].TextSize == textSize && cacheLegHLiii[idx].TextTicksOffset == textTicksOffset && cacheLegHLiii[idx].EqualsInput(input))
                                return cacheLegHLiii[idx];
        
                    LegHLiii indicator = new LegHLiii();
                    indicator.BarsRequired = BarsRequired;
                    indicator.CalculateOnBarClose = CalculateOnBarClose;
                    indicator.Input = input;
                    indicator.iiiLabel = iiiLabel;
                    indicator.iiiTextSize = iiiTextSize;
                    indicator.iiiTextTicksOffset = iiiTextTicksOffset;
                    indicator.Outsidedepends = outsidedepends;
                    indicator.TextSize = textSize;
                    indicator.TextTicksOffset = textTicksOffset;
                    indicator.SetUp();
        
                    LegHLiii[] tmp = new LegHLiii[cacheLegHLiii == null ? 1 : cacheLegHLiii.Length + 1];
                    if (cacheLegHLiii != null)
                        cacheLegHLiii.CopyTo(tmp, 0);
                    tmp[tmp.Length - 1] = indicator;
                    cacheLegHLiii = 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>
                /// LegHLiii
                /// </summary>
                /// <returns></returns>
                [Gui.Design.WizardCondition("Indicator")]
                public Indicator.LegHLiii LegHLiii(bool iiiLabel, int iiiTextSize, int iiiTextTicksOffset, bool outsidedepends, int textSize, int textTicksOffset)
                {
                    return _indicator.LegHLiii(Input, iiiLabel, iiiTextSize, iiiTextTicksOffset, outsidedepends, textSize, textTicksOffset);
                }
        
                /// <summary>
                /// LegHLiii
                /// </summary>
                /// <returns></returns>
                public Indicator.LegHLiii LegHLiii(Data.IDataSeries input, bool iiiLabel, int iiiTextSize, int iiiTextTicksOffset, bool outsidedepends, int textSize, int textTicksOffset)
                {
                    return _indicator.LegHLiii(input, iiiLabel, iiiTextSize, iiiTextTicksOffset, outsidedepends, textSize, textTicksOffset);
                }
        
            }
        }
        
        // This namespace holds all strategies and is required. Do not change it.
        namespace NinjaTrader.Strategy
        {
            public partial class Strategy : StrategyBase
            {
                /// <summary>
                /// LegHLiii
                /// </summary>
                /// <returns></returns>
                [Gui.Design.WizardCondition("Indicator")]
                public Indicator.LegHLiii LegHLiii(bool iiiLabel, int iiiTextSize, int iiiTextTicksOffset, bool outsidedepends, int textSize, int textTicksOffset)
                {
                    return _indicator.LegHLiii(Input, iiiLabel, iiiTextSize, iiiTextTicksOffset, outsidedepends, textSize, textTicksOffset);
                }
        
                /// <summary>
                /// LegHLiii
                /// </summary>
                /// <returns></returns>
                public Indicator.LegHLiii LegHLiii(Data.IDataSeries input, bool iiiLabel, int iiiTextSize, int iiiTextTicksOffset, bool outsidedepends, int textSize, int textTicksOffset)
                {
                    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.LegHLiii(input, iiiLabel, iiiTextSize, iiiTextTicksOffset, outsidedepends, textSize, textTicksOffset);
                }
        
            }
        }
        #endregion

        Comment


          #5
          Hi ninja hattori,

          The creator is using...
          DrawText("H"+CurrentBar, "H", 0, High[0] + TextTicksOffset * TickSize, textColorH, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

          to paint "H" on the chart, you would change that see another text on the chart.
          More info at - http://www.ninjatrader-support.com/H....html?DrawText

          If you want them to count up, you could use "H" + CurrentBar, or some derivative of CurrentBar from a calculation.
          TimNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by zstheorist, Today, 07:52 PM
          0 responses
          6 views
          0 likes
          Last Post zstheorist  
          Started by pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          150 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Started by mattbsea, Today, 05:44 PM
          0 responses
          6 views
          0 likes
          Last Post mattbsea  
          Started by RideMe, 04-07-2024, 04:54 PM
          6 responses
          33 views
          0 likes
          Last Post RideMe
          by RideMe
           
          Started by tkaboris, Today, 05:13 PM
          0 responses
          6 views
          0 likes
          Last Post tkaboris  
          Working...
          X