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

Sentiment As an Indicator

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

    #16
    Hello randl,

    Thank you for your response.

    Two items of concern here. First is that Plot0 is being set to the value I believe you intend for the EMA plot because the EMA plot is never set. Secondly, the CurrentBar < 1 will only work for the first bar series but you need to check the four other bar series in your code.

    Please see the MarketThrustEdit attached to this response for the corrections.
    Attached Files

    Comment


      #17
      Sentiment as an Indicator

      Sorry to say, the fix did not work. Did you try it in your machine? Also I move the download file into the "Indicators folder, but somehow the system does not see it (attached). When I try to call out your file from a chart, it is not there. However, when I go to the repository (the picture below), it is there. So how does this work?
      Attached Files

      Comment


        #18
        Originally posted by randl View Post
        Sorry to say, the fix did not work. Did you try it in your machine? Also I move the download file into the "Indicators folder, but somehow the system does not see it (attached). When I try to call out your file from a chart, it is not there. However, when I go to the repository (the picture below), it is there. So how does this work?
        Did you compile the indicator after you copied it to the indicator directory?

        Comment


          #19
          Sentiment as an Indicator

          I guess I forgot, However, I failed to say, I copied the code into my copy (and compiled it) and...no joy. they both have an EMA Label now (the white one thinks its an 8 and the red one 13). I want the calculation AND and an EMA to plot.
          Attached Files

          Comment


            #20
            Originally posted by randl View Post
            I guess I forgot, However, I failed to say, I copied the code into my copy (and compiled it) and...no joy. they both have an EMA Label now (the white one thinks its an 8 and the red one 13). I want the calculation AND and an EMA to plot.
            You cannot Plot 2 things when you have only one Plot defined. If you want to Plot the EMA, you need to define a separate Plot to hold its values.

            Comment


              #21
              Hello randl,

              Thank you for your responses here.

              The original file contained no definition for the EMA plot, the Plot0 alone was set.

              I believe you may wish to do something like the following:
              Code:
                      protected override void Initialize()
                      {
                          Add("^ADV", PeriodType.Minute, 1);
              			Add("^DECL", PeriodType.Minute, 1);
              			Add("^UVOL", PeriodType.Minute, 1);
              			Add("^DVOL", PeriodType.Minute, 1);
              			Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Plot0"));
              			Add(new Plot(Color.White, "EMA"));
              			BarsRequired = 1;
              			Add(new Line(Color.Yellow, 0, "Lower"));
                          Overlay				= false;
              
                      }
              
                      /// <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
                          // plot below by replacing 'Close[0]' with your own formula.
              			if(CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired || CurrentBars[2] <= BarsRequired || CurrentBars[3] <= BarsRequired || CurrentBars[4] <= BarsRequired)
              				return;
                          Values[0].Set((Closes[1][0] * Closes[3][0]) - (Closes[2][0] * Closes[4][0]));
              			Values[1].Set(EMA(eMA)[0]);
              However, the range of the Plot0 is so large the EMA plots as a flat line as it's range is much smaller. This is due to the scaling of the panel being based on the plots here. If you wanted one of them overlayed on top you would need to create another indicator or remove the EMA from this indicator and just plot it from the Indicators menu.

              Please let me know if I may be of further assistance.

              Comment


                #22
                Oh no, I am sorry, I just assumed C# would calculate the EMA of the item being calculated. Apparently, or rather, I think you are telling me it is calculating the EMA of Price, which is not what I want.

                So, do I have to create my own Moving average based on the data output of my calculation?

                Comment


                  #23
                  Hello randl,

                  Thank you for your response.

                  You would need to create a DataSeries to store the calculation then pass the DataSeries as the input for the EMA:
                  Code:
                  			myDataSeries.Set((Closes[1][0] * Closes[3][0]) - (Closes[2][0] * Closes[4][0]));
                              Value.Set(EMA(myDataSeries, eMA)[0]);
                  For information on the DataSeries class in NinjaTrader please visit the following link: http://www.ninjatrader.com/support/h...ries_class.htm

                  Please let me know if I may be of further assistance.

                  Comment


                    #24
                    Thanks for the help. I did as you suggested and also read the page you sent me.
                    Here are the lines I added after the actual calculation (these are the last 2 lines coded by the user in the script):

                    MTEMA.Set((Closes[1][0] * Closes[3][0]) - (Closes[2][0] * Closes[4][0]));
                    Value.Set(EMA(MTEMA, eMA)[0]);

                    And got an error code - CS0103: The name 'MTEMA' does not exist in the current context (on both lines)

                    Comment


                      #25
                      Hello,

                      Thank you for your response.

                      Was MTEMA set in the Initialize() method? Was it declared in the variables?
                      Code:
                      #region Variables
                      private DataSeries myDataSeries; // Define a DataSeries variable
                      #endregion
                       
                      // Create a DataSeries object and assign it to the variable
                      protected override void Initialize() 
                      { 
                          myDataSeries = new DataSeries(this);

                      Comment


                        #26
                        Yes, I read the URL you sent me and tried several things. The code you see below is the last thing I tried. It gave me a different set of errors. I also tried it without the {} (brackets?), and that did not work. I don't remember what errors it gave me, but the list was longer.

                        #region Variables
                        // Wizard generated variables
                        private int eMA = 8; // Default setting for EMA
                        // 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()
                        {
                        Add("^ADV", PeriodType.Minute, 1);
                        Add("^DECL", PeriodType.Minute, 1);
                        Add("^UVOL", PeriodType.Minute, 1);
                        Add("^DVOL", PeriodType.Minute, 1);
                        Add(new Plot(Color.Red, "MT"));
                        BarsRequired = 1;
                        Add(new Line(Color.Yellow, 0, "Lower"));
                        {
                        private DataSeries MTEMA; // Defines the MTEMA Variable
                        Add(new Plot(Color.White, "MTEMA"));
                        }
                        Overlay = false;

                        Thanks for your help.

                        Comment


                          #27
                          Hello randl,

                          Thank you for your response.

                          That is incorrect, please review the following to acurately add the DataSeries:
                          Code:
                          #region Variables
                          private DataSeries mTEMA; // Define a DataSeries variable
                          #endregion
                           
                          // Create a DataSeries object and assign it to the variable
                          protected override void Initialize() 
                          { 
                              mTEMA = new DataSeries(this);

                          Comment


                            #28
                            Sentiment as an Indicator

                            Thank you Patrick. here is the code I added in that region:

                            protected override void Initialize()
                            {
                            mTEMA = new DataSeries((Closes[1][0] * Closes[3][0]) - (Closes[2][0] * Closes[4][0]));
                            Add("^ADV", PeriodType.Minute, 1);
                            Add("^DECL", PeriodType.Minute, 1);
                            Add("^UVOL", PeriodType.Minute, 1);
                            Add("^DVOL", PeriodType.Minute, 1);
                            Add(new Plot(Color.Red, "MT"));
                            BarsRequired = 1;
                            Add(new Line(Color.Yellow, 0, "Lower"));
                            Add(new Plot(Color.White, "MTEMA"));
                            Overlay = false;
                            }

                            Attached, please find the errors I got.
                            Attached Files

                            Comment


                              #29
                              Hello randl,

                              Thank you for your response.

                              Quite literally it needs to read "mTEMA = new DataSeries(this);". 'this' is not a place holder, it needs to be set there to be synced with the bar series of the script.

                              So your code would need to look like this:
                              Code:
                              #region Variables
                              private DataSeries mTEMA;
                              #endregion
                               
                              protected override void Initialize() 
                              { 
                                  mTEMA = new DataSeries(this);
                              }
                              
                              protected override void OnBarUpdate()
                              {
                              mTEMA.Set((Closes[1][0] * Closes[3][0]) - (Closes[2][0] * Closes[4][0]));
                              }
                              Please let me know if I may be of further assistance.
                              Last edited by NinjaTrader_PatrickH; 11-07-2013, 12:17 PM. Reason: incorrect data series listed

                              Comment


                                #30
                                Sentiment as an Indicator

                                Thank you Patrick and thank you for your patience (believe it or not, I am taking the Script Education from Ninja, but it is slow going I guess). What you gave me worked but I cold not get it to plot. This is what I was doing for plotting:

                                Add(new Plot(Color.White, "MTEMA"));

                                But then, I had a similar statement for plotting MT and, I dont know how the interpreter can tell the difference or assign on or the other.

                                Add(new Plot(Color.Red, "MT"));

                                See the attached plot and Properties figure.
                                Attached Files

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Kaledus, Today, 01:29 PM
                                1 response
                                4 views
                                0 likes
                                Last Post NinjaTrader_Jesse  
                                Started by frankthearm, Yesterday, 09:08 AM
                                13 responses
                                45 views
                                0 likes
                                Last Post frankthearm  
                                Started by PaulMohn, Today, 12:36 PM
                                2 responses
                                16 views
                                0 likes
                                Last Post PaulMohn  
                                Started by Conceptzx, 10-11-2022, 06:38 AM
                                2 responses
                                53 views
                                0 likes
                                Last Post PhillT
                                by PhillT
                                 
                                Started by yertle, Yesterday, 08:38 AM
                                8 responses
                                37 views
                                0 likes
                                Last Post ryjoga
                                by ryjoga
                                 
                                Working...
                                X