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

Flag/Range Indicator

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

    Flag/Range Indicator

    I have been trying to create an indicator which identifies when a MIN of 4 to a MAX of say 20 bars are within a 2.5pts range. Any time the range is broken, the range should end and it should attempt to identify a new range. I have been having the following problems:
    1. When the range is broken, if the bar that breaks the range is still within 2.5pts of say the last four bars of the previous range, it identifies that as a range. What I would like is for the indicator to look for a new range once one is broken, so each bar could only be included in a range once.
    2. The dot that marks each range to appear only twice, once at the start of the range, and once at the end.
    3. I don’t seem to be able to get it to work in the limited manner I have currently coded for between a min and max lookback period. It only seems to work when one period is used.

    My current code is below.
    Any assistance would be much appreciated.
    Thank you!

    Code:
    #region Variables
            // Wizard generated variables
                private double flagPriceRangeMultiplier = 10; // Default setting for FlagRange 10 x TickSize = 2.5pts
                private double mediumPriceRangeMultiplier = 14; // Default setting for MediumRange 14 x TickSize = 3.5pts
                private double largePriceRangeMultiplier = 18; // Default setting for LargeRange 18 x TickSize = 4.5pts
            // User defined variables (add any user defined variables below)
    			private int minLookBackPeriod = 6; //Default setting for minimum look back period
    			private int maxLookBackPeriod = 15; //Default setting for maximum look back period
    			private string TagBullVol = "bullVol";
    			private string TagBearVol = "bearVol";
    			
    			bool maxMinWithinFlag; //Set to true below if all bars in minimum look back period (currently 4 for ES) are within the defined price range
    			int maxMinWithinFlagBar; //below it defines the 1st bar of the minimum look back period (currently 4 for ES) within the defined price range 
    
            #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()
            {
                Overlay				= true;
    
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // Use this method for calculating your indicator values. Assign a value to each
    
        if (CurrentBar < (minLookBackPeriod - 1)) return;
    
        if (FirstTickOfBar)
        {
            
    		int counter = 0;
    		
    		for (int i = 0; i < minLookBackPeriod; i++)
            {
                if ((MAX(High, minLookBackPeriod)[i] - MIN(Low, minLookBackPeriod)[i]) <= flagPriceRangeMultiplier * TickSize) counter++;
    
            }
    		
    		 
            if (counter >= minLookBackPeriod) 
    	{
    		DrawDot(TagBullVol + CurrentBar, AutoScale, 0, Low[1] - 6 * TickSize, Color.Blue); 
    	}
    		
    		Print(Time.ToString()+"Counter:"+counter);

    #2
    Hello GeorgeW,

    Thank you for your post.

    Can you please clarify what you mean by "when the range is broken"? What denotes the range being broken?

    Just to clarify, what denotes a "range"? Are these all the bars contained within your minimum look back period?

    I look forward to assisting further.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Hello ZacharyG,

      All the bars of a range (or consolidation area) are contained within 2.5pts of the ES. The 2,5pts denotes the range. The 1st bar to go outside this 2,5pts breaks the range and may start a new range, but cannot be part of a range which includes any of the previous bars (even if it and the last 4 bars of the previous range falls within 2,5pts). the number of bars can be from a min of 4 up to a max to be defined.

      Let me know if you need any more info.

      Thank you.

      Comment


        #4
        Originally posted by GeorgeW View Post
        Hello ZacharyG,

        All the bars of a range (or consolidation area) are contained within 2.5pts of the ES. The 2,5pts denotes the range. The 1st bar to go outside this 2,5pts breaks the range and may start a new range, but cannot be part of a range which includes any of the previous bars (even if it and the last 4 bars of the previous range falls within 2,5pts). the number of bars can be from a min of 4 up to a max to be defined.

        Let me know if you need any more info.

        Thank you.
        That means that you have to store the barNumber on which the range is broken, then start your "range identifying" code block only after a requisite number of bars have passed since the breakBar.

        Comment


          #5
          So does this mean that I am dealing with a loop where I put in a break when the range is broken, and then the whole loop starts again for the next range?

          Comment


            #6
            Originally posted by GeorgeW View Post
            So does this mean that I am dealing with a loop where I put in a break when the range is broken, and then the whole loop starts again for the next range?
            Not quite.

            It is like this in pseudocode.
            Code:
            if (RangeIsBroken) NewRangeStartBar = CurrentBar;
            if (CurrentBar - NewRangeStartBar >= MinumumBarsUsedToDetermineRange) CurrentRange = GetRange();
            Depending in what you are writing, you may or may not need else clauses. CurrentRange of course could be a struct or class, or you might prefer to record separately the High and Low of the range.
            Last edited by koganam; 01-08-2016, 03:24 PM.

            Comment


              #7
              Ok, thanks for the help Koganam. I will give that a go over the weekend.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Jon17, Today, 04:33 PM
              0 responses
              1 view
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              4 views
              0 likes
              Last Post Javierw.ok  
              Started by timmbbo, Today, 08:59 AM
              2 responses
              10 views
              0 likes
              Last Post bltdavid  
              Started by alifarahani, Today, 09:40 AM
              6 responses
              41 views
              0 likes
              Last Post alifarahani  
              Started by Waxavi, Today, 02:10 AM
              1 response
              19 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Working...
              X