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

Add(WMA(8)) error

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

    Add(WMA(8)) error

    Hello,

    I read NT guide carefully but I got argument value error at Add(WMA(8)) and I couldn't figure out what I am missing. Can you shed light on this? I just want to see the values from WMA in 3 timeframes on the 5 min chart.

    Thanks,
    -traderjh

    Code:
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    #endregion
    namespace NinjaTrader.Indicator
    {
        [Description("Show WMA")]
        public class ShowWMA : Indicator
        {
            #region Variables
            #endregion
            protected override void Initialize()
            {
                            Overlay = false;
    			Enabled = true;
    			CalculateOnBarClose = false;
    			Add(PeriodType.Minute, 30);
    			Add(PeriodType.Minute, 60);
    			Add(WMA(8));
            }
            protected override void OnBarUpdate()
            {
    				DrawTextFixed("wma",
    				"WMA0: " + WMA(BarsArray[0],8)[0] +
    				"\nWMA1: " + WMA(BarsArray[1],8)[1] +
    				"\nWMA2: " + WMA(BarsArray[2],8)[2]
    				,TextPosition.TopLeft,Color.Yellow,new Font("Arial", 12),Color.Black,Color.Black,10);
            }
            #region Properties
            #endregion
        }
    }

    #2
    traderjh, adding indicators in for display would unfortunately only for for strategies - here's a tip that would go over the details - http://www.ninjatrader.com/support/f...ead.php?t=3228

    You can add the other timeframes though in for your indicator script and calculate the WMA's on each barsarray in the BarsInProgress == 0 for this indicator, so the primary series where you plots would be run in.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      It works in strategy and now...

      Thank you for the reply and the link! I put the code in strategy and it worked.

      Now, I need clarification on pointing to right timeframe. I tried WMA(4)[1], WMA(4)(0) Plots[1] etc and I still get errors. What is the proper syntax for pointing?

      Many thanks.

      Code:
      protected override void Initialize()
              {
                      Overlay = false;
      		Enabled = true;
      		CalculateOnBarClose = false;
                      WMA(8).Plots[0].Pen.Color = Color.Yellow; [B]// point to 5 min(primary)[/B]
      		WMA(8).Plots[0].Pen.Color = Color.Red;  [B]// point to 30 min[/B]
      		WMA(8).Plots[0].Pen.Color = Color.Blue; [B]// point to 60 min[/B]
      		WMA(8).Plots[0].Pen.Width = 3;  [B]// How can I point this to all timeframes?[/B]
      		Add(PeriodType.Minute, 30);
      		Add(PeriodType.Minute, 60);
      		Add(WMA(8));
              }
              protected override void OnBarUpdate()
              {
      		DrawTextFixed("wma",
      		"WMA0: " + WMA(BarsArray[0],8)[0] +
      		"\nWMA1: " + WMA(BarsArray[1],8)[1] +
      		"\nWMA2: " + WMA(BarsArray[2],8)[2]
      		,TextPosition.TopLeft,Color.Yellow,new Font("Arial", 12),Color.Black,Color.Black,10);
              }
      Last edited by traderjh; 10-17-2013, 09:55 AM. Reason: editing correction

      Comment


        #4
        traderjh, plotting from a strategy directly would need another technique, which is detailed here in this sample - http://www.ninjatrader.com/support/f...ead.php?t=6651

        I've attached this example customized for your use and timeframes, so it can hopefully serve as a good base for future works.
        Attached Files
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Close instead of High

          Many thanks!

          You mentioned in the code that StrategyPlot(0).Value.Set(WMA(8)[0]); is only set to High value. Is there a way to use Close instead of High? I tried Close[0](WMA(8)[0] and it doesn't work.

          Regards,.
          -traderjh

          Comment


            #6
            Hi,

            You can control that using the following:

            Code:
            			StrategyPlot(0).Value.Set(WMA(Close, 8)[0]);
            			StrategyPlot(1).Value.Set(WMA(Closes[1], 8)[0]);
            			StrategyPlot(2).Value.Set(WMA(Closes[2], 8)[0]);
            Alternatively, if you wanted to use the Low for example:

            Code:
            			StrategyPlot(0).Value.Set(WMA(Low, 8)[0]);
            			StrategyPlot(1).Value.Set(WMA(Lows[1], 8)[0]);
            			StrategyPlot(2).Value.Set(WMA(Lows[2], 8)[0]);
            MatthewNinjaTrader Product Management

            Comment


              #7
              lines are bit off....

              Hi,

              The lines aren't aligned as I want. You can see two sets of indicator WMA and strategy WMA on the chart to compare moving average lines. The strategy WMA lines are off and not smooth. How can I set this code(last two plots) to point to 30min and 60min instead of 5min. See attached picture below.

              Thanks,
              -traderjh
              Attached Files

              Comment


                #8
                traderj, so are the values actually incorrect for you? I would not expect them to be smooth but showing a stairstep effect, as you really calculate on the higher timeframe and only have a datapoint then every x bars only when viewed from the lower one.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  all three pointing to one timeframe

                  Originally posted by NinjaTrader_Bertrand View Post
                  traderj, so are the values actually incorrect for you? I would not expect them to be smooth but showing a stairstep effect, as you really calculate on the higher timeframe and only have a datapoint then every x bars only when viewed from the lower one.
                  See the values of minutes in indicator dialog window in attached picture here. I am using SampleStrategyPlot2 to test and all three strategies are pointing to 5 minute. I want one strategy to point to one 5 minute, next strategy should point to 30 minute and the third strategy should point to 60 minutes. Let me know if I am not clear enough.

                  Thanks.
                  Attached Files
                  Last edited by traderjh; 10-18-2013, 09:38 AM. Reason: clarification

                  Comment


                    #10
                    That's unfortunately not correct in understanding - the strategy script uses 3 indicators it adds to the primary series - that's your 5 min here for all 3. It would then populate those indicator plots with values from your added series / timesframes in the strategy - those would not come through in indicator plot series from the UI. So the indicator itself is just a placeholder to allow the strategy to plot.
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Thanks for your reply. Ok. I understand.

                      Are there any other techniques to retrieve data from 2nd and 3rd timeframes's indicators?

                      Comment


                        #12
                        You're welcome, those would be the techniques available - however if you don't need the strategy for execution the same would be done easier as well directly from an indicator, which also could add in series and then directly plot, so in essence the same multi series concept could be used.

                        Further script examples would be preinstalled with NT under the SampleMultTimeFrame and SampleMultiInstrument strategy scripts. The complete framework available would be documented here -

                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Will this work?

                          Ok...

                          Based on my understanding from NT's guide under multi-time frame and instruments, is this workable to get WMA prices from each 5, 30 and 60 minute timeframe instead of using Add(StrategyPlot)?

                          // in 5 min chart
                          Add(PeriodType.Minute, 30);
                          Add(Instrument.FullName,PeriodType.Minute,30,Marke tDataType.Ask);
                          Add(WMA(8)); <<< (Need something to indicate connection to above)

                          Add(PeriodType.Minute, 60);
                          Add(Instrument.FullName,PeriodType.Minute,60,Marke tDataType.Ask);
                          Add(WMA(8)); <<< (Need something to indicate connection to above)

                          Thanks again.
                          Last edited by traderjh; 10-18-2013, 12:54 PM. Reason: clarification

                          Comment


                            #14
                            Hello traderjh,

                            You would not be able to as you would not have access the the BarsArray object that you would need to reference the different time frames. So you would only be able to add the Indicator to the Primary Series.



                            You may add another Strategy Plot and then inside of OnBarUpdate() use the WMA(BarsArray[1], 8)[0] to set the value of the Strategy Plot to the value of the Indicator so you can still see the plot of the chart.

                            Let us know if you have any further questions.
                            JCNinjaTrader Customer Service

                            Comment


                              #15
                              Chart compared

                              Hello all,

                              Please bear with me.

                              I attached a picture of two charts for your review. In the picture:
                              Left chart has regular indicator of WMA 8 in each 5, 30 and 60 minutes timeframe, It is good.
                              Right chart has SampleStrategyPlot2 with WMA 8 and it only points to 5 minutes. Not pointing to 5, 30 and 60. Even it uses BarsArray[0], [1] and [2]. See below part of code.

                              StrategyPlot(0).Value.Set(WMA(8)[0]); // this points to 5 minutes and is good
                              StrategyPlot(1).Value.Set(WMA(BarsArray[1], 8)[0]); // this should point to 30 minutes
                              StrategyPlot(2).Value.Set(WMA(BarsArray[2], 8)[0]); // this should point to 60 minutes

                              Let me know if I am not clear enough. Can you show the correct code to get each timeframe WMA price?

                              Many thanks!
                              -traderjh
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cre8able, Today, 03:20 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post cre8able  
                              Started by Fran888, 02-16-2024, 10:48 AM
                              3 responses
                              47 views
                              0 likes
                              Last Post Sam2515
                              by Sam2515
                               
                              Started by martin70, 03-24-2023, 04:58 AM
                              15 responses
                              114 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by The_Sec, Today, 02:29 PM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              2 responses
                              31 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Working...
                              X