• 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

Overlapping lines. Need to separate them

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

    Overlapping lines. Need to separate them

    Hello,

    I set up 3 WMA lines on a chart manually via Indicator dialog box configured with High, Median and Low. I coded a testWMA strategy to be like this chart (indicator set up). I ended up with all three lines overlapping even I use High, Median and Low in the code. I tried different ways to separate the lines with no luck. Can you tell me what is correct way to do it?
    See attached picture.

    Thanks much in advance!
    traderjh

    Code:
    public class testWMA : Strategy
    {
    #region Variables
    private int upper = 5;
    private int middle = 5;
    private int lower = 5;
    private DataSeries upperPrice;
    private DataSeries middlePrice;
    private DataSeries lowerPrice;
    #endregion
    protected override void Initialize()
    {
    CalculateOnBarClose = false;
    Add(WMA(upper));
    Add(WMA(middle));
    Add(WMA(lower));
    WMA(upper).Plots[0].Pen.Color = Color.LimeGreen;
    WMA(middle).Plots[0].Pen.Color = Color.Blue;
    WMA(lower).Plots[0].Pen.Color = Color.Red;
    WMA(upper).Plots[0].Pen.Width = 3;
    WMA(middle).Plots[0].Pen.Width = 3;
    WMA(lower).Plots[0].Pen.Width = 3;
    upperPrice = new DataSeries(this);
    middlePrice = new DataSeries(this);
    lowerPrice = new DataSeries(this);
    }
    protected override void OnBarUpdate()
    {
    upperPrice.Set(WMA(High,upper)[0]);
    middlePrice.Set(WMA(Median,middle)[0]);
    lowerPrice.Set(WMA(Low,lower)[0]);
    }
    #region Properties
    #endregion
    Attached Files
    Last edited by traderjh; 06-03-2015, 03:25 PM. Reason: line in error

    #2
    Hello traderjh,

    You are adding 3 indicators using the same period for each.

    You supply 5 as the upper, middle, and lower. Are you expecting different values to be returned when you call the same indicator with the same period?

    Also, I think you want to be supplying the high series to the indicator for the high WMA, the median series for the middle WMA, and the Low series for the low WMA. This is not being done in your script.

    Add(WMA(High, 5));
    Add(WMA(Median, 5));
    Add(WMA(Low, 5));
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello traderjh,

      You are adding 3 indicators using the same period for each.

      You supply 5 as the upper, middle, and lower. Are you expecting different values to be returned when you call the same indicator with the same period?

      Also, I think you want to be supplying the high series to the indicator for the high WMA, the median series for the middle WMA, and the Low series for the low WMA. This is not being done in your script.

      Add(WMA(High, 5));
      Add(WMA(Median, 5));
      Add(WMA(Low, 5));
      Thank you for your reply.

      Yes, I do want the same period for all lines like the indicator chart on the left shown in the picture using all same period. You can see the indicator dialog box with 5's in all lines. Let me know if I need to clarify.

      traderjh
      Attached Files
      Last edited by traderjh; 06-03-2015, 04:10 PM. Reason: attached file

      Comment


        #4
        Hello traderjh,

        Did my suggestion not work for you?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          No, I intended to have same period for High, Median and Low lines. I attached this clarified picture here. Let me know if I need to clarify more.

          Thanks again,
          traderjh
          Attached Files

          Comment


            #6
            Hello traderjh,

            Have you tried my suggestion of supplying the correct input series?

            This is working on my end.

            Add(WMA(High, 5));
            Add(WMA(Median, 5));
            Add(WMA(Low, 5));

            Please attach an export of your updated code with this modification.

            To export your script do the following:
            1. Click File -> Utilities -> Export NinjaScript
            2. Enter a unique name for the file in the value for 'File name:'
            3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
            4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


            By default your exported file will be in the following location:
            • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


            Below is a link to the help guide on Exporting NinjaScripts.
            http://www.ninjatrader.com/support/h...nt7/export.htm
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Chelsea,

              Yes! It is working now on my end.

              Thank you very much. I appreciate your support.

              traderjh

              Comment


                #8
                Widening moving averages

                Hello,

                I wanted to add a number to High and Low but it doesn't accept. Is there a way to add a number to those moving averages? I did silly ways to try but...

                ....
                pipSize = Instrument.MasterInstrument.PointValue;
                ...
                Add(WMA((High+(10/pipSize*10)), 5));
                Add(WMA((Low-(10/pipSize*10)), 5));

                Error in above so I tried next:

                upperPrice.Set(WMA((High+(10/pipSize*10)),period)[0]);
                lowerPrice.Set(WMA((Low-(10/pipSize*10)),period)[0]);

                Again, error in above so I tried next:

                (upperPrice+(10/pipSize*10)).Set(WMA(High,period)[0]);
                (lowerPrice-(10/pipSize*10)).Set(WMA(Low,period)[0]);

                Is there a way?

                Many thanks!
                traderjh

                Comment


                  #9
                  Hi traderjh,

                  The Open, High, Low, and Close are dataseries that contain a value for every bar on the chart.

                  Your code is trying to add a number to a collection as if this was a one number value.

                  If you want to add these values to each bar's high so that the added number is used in the WMA calculation, then you need a second custom data series to hold these modified values.

                  For example:
                  In #region Variables:
                  private DataSeries myDataSeries;

                  In Initialize():
                  myDataSeries = new DataSeries(this);

                  In OnBarUpdate():
                  myDataSeries.Set(High[0]+(10/pipSize*10));
                  Print(WMA(myDataSeries, 5)[0]);

                  http://ninjatrader.com/support/helpG...ries_class.htm
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Still error...

                    Thank you for your reply.

                    I did this what you suggested and I still get error in compilation. Is it something to do with two values that WMA is using?

                    Code:
                    namespace NinjaTrader.Strategy
                    {
                        public class testWMA2Lines : Strategy
                        {
                            #region Variables
                    	    private int period = 10;
                    	    private int path = 5;
                    	    private double pipSize;
                    	    private DataSeries upperPrice;
                    	    private DataSeries lowerPrice;
                            #endregion
                            protected override void Initialize()
                            {
                    	    Add(WMA(High,period));
                                Add(WMA(Low,period));
                    	    WMA(High,period).Plots[0].Pen.Color = Color.LimeGreen;
                    	    WMA(Low,period).Plots[0].Pen.Color = Color.Red;
                    	    upperPrice = new DataSeries(this);
                    	    lowerPrice = new DataSeries(this);
                    	    pipSize = Instrument.MasterInstrument.PointValue;
                            }
                            protected override void OnBarUpdate()
                            {
                    	    upperPrice.Set(WMA((High[0]+(10/pipSize*10)),period)[0]);
                    	    lowerPrice.Set(WMA((Low[0]-(10/pipSize*10)),period)[0]);
                            }
                            #region Properties
                            #endregion
                        }
                    }

                    Comment


                      #11
                      Hello traderjh,

                      The following code is not what I have suggested:
                      Code:
                      upperPrice.Set(WMA((High[0]+(10/pipSize*10)),period)[0]);
                      lowerPrice.Set(WMA((Low[0]-(10/pipSize*10)),period)[0]);
                      Below is what I have suggested:
                      Code:
                      myDataSeries.Set(High[0]+(10/pipSize*10));
                      Print(WMA(myDataSeries, 5)[0]);
                      In other words set the upperPrice to the high plus calculated value, then supply upperPrice as the input series to WMA().
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Still can't get two separate lines

                        Ok, I tried this way you suggested and I still got only one line showing up on the chart but it does show two different input values on the output(print). I need the chart to show two lines, one with 10 pips added and other with its normal value. I still couldn't figure out what I do wrong here.

                        I attached a picture here that shows a chart and an output.

                        Thank you,
                        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.Indicator;
                        using NinjaTrader.Gui.Chart;
                        using NinjaTrader.Strategy;
                        #endregion
                        
                        namespace NinjaTrader.Strategy
                        {
                            [Description("")]
                            public class testWMAxx : Strategy
                            {
                                #region Variables
                        	private int period = 15;
                        	private double pipSize;
                        	private DataSeries myDataSeries1;
                        	private DataSeries myDataSeries2;
                                #endregion
                                protected override void Initialize()
                                {
                        			Add(WMA(High,period));
                        			Add(WMA(High,period));
                        			WMA(High,period).Plots[0].Pen.Color = Color.LimeGreen;
                        			WMA(High,period).Plots[0].Pen.Width = 3;
                        			WMA(High,period).Plots[0].Pen.Color = Color.Red;
                        			WMA(High,period).Plots[0].Pen.Width = 3;
                        			myDataSeries1 = new DataSeries(this);
                        			myDataSeries2 = new DataSeries(this);
                        			pipSize = Instrument.MasterInstrument.PointValue;
                                }
                                protected override void OnBarUpdate()
                                {
                        			myDataSeries1.Set(High[0]);
                        			myDataSeries2.Set(High[0]+(10/pipSize*10));
                        			Print("line1 " + WMA(myDataSeries1, period)[0]);
                        			Print("line2 " + WMA(myDataSeries2, period)[0]);
                                }
                                #region Properties
                                #endregion
                            }
                        }
                        Attached Files

                        Comment


                          #13
                          traderjh,

                          Your strategy is not drawing these plots.

                          The plots are appearing because of the Add(WMA(High,period)); line. This line is in there twice and the second one, since its using the same information, is a duplicate and is ignored.

                          The code you have in OnBarUpdate() is what is making the prints but is not drawing the line.

                          (Try removing that code in OnBarUpdate(). The line still draws the same because the code in OnBarUpdate() is not drawing that line, it is only making the prints.)

                          If you want two lines, you need to modify the indicator so that there are two plots.
                          Chelsea B.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Uwe1981, Today, 03:41 AM
                          1 response
                          14 views
                          0 likes
                          Last Post NinjaTrader_Kate  
                          Started by 7robert, Today, 10:07 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post 7robert
                          by 7robert
                           
                          Started by emuns, Today, 09:36 AM
                          1 response
                          3 views
                          0 likes
                          Last Post NinjaTrader_PaulH  
                          Started by lmatiukas, Today, 09:31 AM
                          0 responses
                          4 views
                          0 likes
                          Last Post lmatiukas  
                          Started by Irukandji, Today, 09:09 AM
                          3 responses
                          9 views
                          0 likes
                          Last Post NinjaTrader_PatrickG  
                          Working...
                          X