• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

LastPrice

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

    LastPrice

    Hello.

    Firstly, I am a complete novice to NT scripts. I am trying to use the Market Analyzer to monitor some instruments. Of course the current limitation of Market Analyzer is that one can not set up things like cell conditions for columns based on comparing data in multiple columns. A way around this as has been advised by NT support is to create indicators to do the comparisons and then set the cell condition based on the values of the new indicators. On this basis I embarked on attempting to write indicator(s) for what I need.

    One of my needs is for the Market Analyzer to check to see if the LastPrice of an instrument is equal to the Upper Band or Lower Band (these are indicators included in another indicator - VWAP, which I have already loaded into NT). So amongst my columns in Market Analyzer is LastPrice, Lower Band, and Upper Band.

    To achieve the above, I have tried to write two (I am sure this can be made into just the one indicator, but beyond my capabilities at present) indicators (one for when the Last Price equals Upper Band, and one for when Last Price equals Lower Band), to return value 1 if condition is met, and value 0 otherwise. I then add these new indicators as columns on Market Analyzer, and set the cell condition based on the values 1 or 0.

    Below is the code I have written with the help of the indicator wizard and my very limited understanding of C# so far. I have yet to test the code but it compiled successfully. My problem/questions though are:

    1. Just for the purpose of coming up with a code, I have used 'Close'. I can't seem to find the synthax for 'LastPrice', if this exist at all. If it does not, what can I use?

    2. Logically, is the code Ok i.e. would it do what i want it to?

    Many thanks
    Dan


    Code:
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
        /// <summary>
        /// Last price equals upper band (MPD+VWAP)
        /// </summary>
        [Description("Last price equals upper band (MPD+VWAP)")]
        public class LPisUB : 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()
            {
               // Set the value
               Value.Set(Close[0] == VWAP().UpperBand[0] ? 1 : 0);
            }

    #2
    Indicator to determine tight consolidation?

    Hello,

    Continuing with my quest. Though still not had any reply/assistance to my first request for help.

    Below is a very crude and primitive attempt to write an indicator that returns 1 if condition is met or 0 otherwise. The condition is basically to look at the last four bars to see if 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


    Any assistance would be much appreciated.

    Many thanks
    Dan


    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)
                 {
                    maxHlessDayH = true;
                 }
                if (minLlessDayL >= 0 && minLlessDayL < 0.5)
                 {
                    minLlessDayL = true;
                 }
             
                
                 Value.Set(MaxRng4Bars = true && maxHlessDayH = true && minLlessDayL = true  ? 1 :0);
                    
            }

    Comment


      #3
      Hello,

      Thanks for the forum post.

      It looks like you are missing closing brackets } at the end of OnBarUpdate.

      What I would recommend is creating a new indicator as a nwe shell which has all the correct bracketing. Then copying over the OnBarUpdate() section and variables into the new strategy in between the OnBarUpdate() {}

      -Brett
      BrettNinjaTrader Product Management

      Comment


        #4
        Hello,

        Thanks for your reply. I have inserted the missing '}' , but still getting same errors. Just one mistake I have just noticed in the code. Where I

        wrote maxHlessDayH = true; and minLlessDayL = true; in previous code, it should acatually read CloseToHigh = True; and CloseToLow = True;
        I have amended this in the code below. Many thanks.


        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);
                        
                }
              }
            }

        Comment


          #5
          Not seem to getting much assistance with this. Would someone please at least tell me whether the 'Close' price is the same as the 'LastPrice'? Thanks

          Comment


            #6
            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);
                        
                        }

            Comment


              #7
              NT Support, yet again I ask. Is the 'LastPrice' in MA same thing as 'Close' price to use for developing and indicator, as there does not seem to be 'LastPrice' to be found when developing an indicator? Thanks

              Comment


                #8
                Hello,

                Please note our official support hours here:

                http://www.ninjatrader.com/Support

                As far as the code we unfortuantely cannot help write or review code for clients. I can only answer and specific questions you have on NinjaScript.

                If you would like assistance with the code logic to make sure that it will work as you expect you will want to contact a NinjaScript consultant.

                http://www.ninjatrader.com/partners#...pt-Consultants

                Finally, as far as your question on the Close price this would be the same as LastPrice.

                -Brett
                BrettNinjaTrader Product Management

                Comment


                  #9
                  Hello NT_Brett.

                  Many thanks for your response. Much obliged.

                  Dan

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by bchip, Today, 09:25 AM
                  1 response
                  5 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by Tomass, Today, 09:25 AM
                  2 responses
                  5 views
                  0 likes
                  Last Post Tomass
                  by Tomass
                   
                  Started by hundert, Today, 08:37 AM
                  2 responses
                  15 views
                  0 likes
                  Last Post hundert
                  by hundert
                   
                  Started by ronaldgreene828, Today, 08:16 AM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_PatrickG  
                  Started by hir04068, Today, 01:36 AM
                  1 response
                  17 views
                  0 likes
                  Last Post NinjaTrader_PaulH  
                  Working...
                  X