Indicator to check consolidation - futures io
futures io futures trading



Indicator to check consolidation


Discussion in NinjaTrader

Updated
    1. trending_up 3,507 views
    2. thumb_up 2 thanks given
    3. group 3 followers
    1. forum 4 posts
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Indicator to check consolidation

(login for full post details)
  #1 (permalink)
London, UK
 
Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker: IB, Kinetic
Trading: Stocks, Forex
 
Posts: 98 since Nov 2011
Thanks: 47 given, 16 received

Hello people.

Would be very grateful for your assistance with this code please. I have already posted it on the NT forum, but not getting much response/assistance at present. Basically its an indicator I am trying to write to use in the Market Analyzer of NT. I am a complete novice to NT scripts and C#, and this is just my crude and primitive attempt using the NT indicator wizard and nicking snippets of code here and there.

What I am after is an indicator to return 1 if a condition is met or 0 otherwise. The condition is basically to look at the last four bars to see if are in a very narrow range (highest range not more than say 0.25c) and also if close to the day's high or low so far.

Not surprisingly, it failed to compile, giving me the following errors:
Class member declaration expected
Invalid token 'namespace' in class, struct, or interface member declaration
Invalid token '{' in class, struct, or interface member declaration
} expected

Many thanks for you assistance.


 
Code
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    /// <summary>
    /// Checks if last 4 bars have very narrow range and close to day high or low
    /// </summary>
    [Description("Checks if last 4 bars have very narrow range and close to day high or low")]
    public class Consolidating : Indicator
    {
        #region Variables
        // Wizard generated variables
        // User defined variables (add any user defined variables below)
        #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                = false;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            bool MaxRng4Bars = false;
            double maxHigh = MAX(High,4)[0];
            double minLow =  MIN(Low,4)[0];
            double maxHlessDayH = CurrentDayOHL().CurrentHigh[0] - maxHigh;
            double minLlessDayL = minLow - CurrentDayOHL().CurrentLow[0];
            bool CloseToHigh = false;
            bool CloseToLow = false;
            
            if (Range()[0]<0.26 && Range()[1]<0.26 && Range()[2]<0.26 && Range()[3]<0.26)
             {
                MaxRng4Bars = true;
             { 
            if (maxHlessDayH >= 0 && maxHlessDayH < 0.5)
             {
                CloseToHigh = true;
             }
            if (minLlessDayL >= 0 && minLlessDayL < 0.5)
             {
                CloseToLow = true;
             }
         
            
             Value.Set(MaxRng4Bars = true && CloseToHigh = true && CloseToLow = true  ? 1 :0);
                
        }

Started this thread Reply With Quote

Can you help answer these questions
from other members on futures io?
Short Interest Ratio indicator?
ThinkOrSwim
What blockvolume is visible? - order processing
NinjaTrader
Which kind of Blockvolume is visible? - order processing
Emini and Emicro Index
Reading A set of Trading Signals
EasyLanguage Programming
Webinar: Finding your own way in trading w/Adam Grimes
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Battlestations: Show us your trading desks!
111 thanks
Selling Options on Futures?
109 thanks
Rank your Futures vs Stocks trading priority
37 thanks
Want your NinjaTrader indicator created, free?
26 thanks
Bitcoin storage wallet recommendations
18 thanks
 
(login for full post details)
  #2 (permalink)
London, UK
 
Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker: IB, Kinetic
Trading: Stocks, Forex
 
Posts: 98 since Nov 2011
Thanks: 47 given, 16 received

Ok, been working on the code (basically through trial and error, not too sure exactly what I am doing ). However, the amended code below so far has compiled successfully. I have not tested it yet as the markets (US stocks) are currently closed. Logically though, does it look correct, will it do what I want it to do? Many thanks.


 
Code
protected override void OnBarUpdate()
        {
            
            
            double maxHlessDayH = CurrentDayOHL().CurrentHigh[0] - MAX(High,4)[0];
            double minLlessDayL = MIN(Low,4)[0] - CurrentDayOHL().CurrentLow[0];
            int MaxRng4Bars, CloseToHigh, CloseToLow;
            
            if (Range()[0]<0.26 && Range()[1]<0.26 && Range()[2]<0.26 && Range()[3]<0.26)
                          
                 MaxRng4Bars = 1;
            else
            {
                 MaxRng4Bars = 0;
            }
              
            if (maxHlessDayH >= 0 && maxHlessDayH < 0.5)
             
                 CloseToHigh = 1;
            else
            {
                 CloseToHigh = 0;
            }
             
            if (minLlessDayL >= 0 && minLlessDayL < 0.5)
            
                 CloseToLow = 1;
            else
             {
                  CloseToLow = 0;
             }
           
            if (MaxRng4Bars == 1 && CloseToHigh == 1 && CloseToLow == 1)
                
             Value.Set(1);
            else
            {
             Value.Set(0);
            
            }

Started this thread Reply With Quote
 
(login for full post details)
  #3 (permalink)
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
 
gregid's Avatar
 
Posts: 651 since Aug 2009
Thanks: 320 given, 620 received


As a novice, make sure you use curly brackets with every if statement, ie:

 
Code
                            
if (X)
{
     
//statement 
}
else
{
    
//statement

C# will process only first line after if when curly bracket is missing so it is a good practice to use them, especially when you don't know what your are doing

Reply With Quote
The following user says Thank You to gregid for this post:
 
(login for full post details)
  #4 (permalink)
London, UK
 
Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker: IB, Kinetic
Trading: Stocks, Forex
 
Posts: 98 since Nov 2011
Thanks: 47 given, 16 received


gregid View Post
As a novice, make sure you use curly brackets with every if statement, ie:

 
Code
                            
if (X)
{
     
//statement 
}
else
{
    
//statement

C# will process only first line after if when curly bracket is missing so it is a good practice to use them, especially when you don't know what your are doing

Thanks for the tip gregid. Logically though, apart from the missing curly brackets, does the code look ok? Thanks

Started this thread Reply With Quote
 
(login for full post details)
  #5 (permalink)
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
 
gregid's Avatar
 
Posts: 651 since Aug 2009
Thanks: 320 given, 620 received

your conditions are quite simple so I don't see why it wouldn't work. Just load it, test and see for yourself =)

Reply With Quote
The following user says Thank You to gregid for this post:


futures io Trading Community Platforms and Indicators NinjaTrader > Indicator to check consolidation


Last Updated on February 26, 2012


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts