Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Wma

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

    Wma

    Hello,

    I am a paying customer of ninja trader and was wondering if I could get some help with something.

    I use a WMA in my trading and was wondering if it is at all possible to make the WMA indicator plot 2 lines, one above the WMA and one below the WMA 1.25pts +/- from where the WMA is.

    Thanks

    #2
    Hi ale la juve ale,

    Thanks for your post.

    To realize your idea, you can take a look at our tutorials in our help guide - http://www.ninjatrader-support.com/H...verview18.html

    This gives you a good overview how to create and modify indicators in NinjaScript.

    If you feel this is above your programming skills, you can always check with our NinjaScript development partners - http://www.ninjatrader.com/webnew/pa...injaScript.htm

    On a sidenote, I have been working on something similar for private use, but will post tomorrow, so you can see if it helps you and your trading.

    Have a great day!
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi ale la juve ale,
      try this constant width WMA channel from my private works, hopefully it can help you in your setup, too.

      Have a great weekend!!
      Attached Files
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Wicked,

        I'll post after trying it.

        Thank You

        Comment


          #5
          This is perfect. It saves me from moving around a horizontal line all day.


          Thanks Again

          Comment


            #6
            Modify this code

            Hi Bertrand,
            Would it be possible to modify this code or your code to make the top and bottom of the channel around the weighted moving average a WMA of the high, and a WMA of the low of the WMA itself, for example a 20 wma high - 20 wma low, and a 20 wma close?
            I started by coping and pasting this WMA code into a new indicator I created but then I got stuck.
            Thanks in advance, and Happy New Year,
            DT12

            Comment


              #7
              Here is the 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

              // This namespace holds all indicators and is required. Do not change it.
              namespace NinjaTrader.Indicator
              {
              /// <summary>
              /// Weighted moving average high - low - close
              /// </summary>
              [Description("Weighted moving average high - low - close")]
              public class WeightedWave : Indicator
              {
              #region Variables
              // Wizard generated variables
              private int highLength = 30; // Default setting for HighLength
              private int middleLength = 30; // Default setting for MiddleLength
              private int lowerLength = 30; // Default setting for LowerLength
              // 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(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "UpperWave"));
              Add(new Plot(Color.FromKnownColor(KnownColor.DarkCyan), PlotStyle.Line, "MiddleWave"));
              Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Line, "LowerWave"));
              Overlay = true;
              }

              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
              if (CurrentBar == 0)
              Value.Set(Input[0]);
              else
              {
              int back = Math.Min(Period - 1, CurrentBar);
              double val = 0;
              int weight = 0;
              for (int idx = back; idx >=0; idx--)
              {
              val += (idx + 1) * Input[back - idx];
              weight += (idx + 1);
              }
              Value.Set(val / weight);
              ]
              // Use this method for calculating your indicator values. Assign a value to each
              // plot below by replacing 'Close[0]' with your own formula.


              UpperWave.Set(Close[0]);
              MiddleWave.Set(Close[0]);
              LowerWave.Set(Close[0]);
              }

              #region Properties
              [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
              [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
              public DataSeries UpperWave
              {
              get { return Values[0]; }
              }

              [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
              [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
              public DataSeries MiddleWave
              {
              get { return Values[1]; }
              }

              [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
              [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
              public DataSeries LowerWave
              {
              get { return Values[2]; }
              }

              [Description("")]
              [GridCategory("Parameters")]
              public int HighLength
              {
              get { return highLength; }
              set { highLength = Math.Max(1, value); }
              }

              [Description("")]
              [GridCategory("Parameters")]
              public int MiddleLength
              {
              get { return middleLength; }
              set { middleLength = Math.Max(1, value); }
              }

              [Description("")]
              [GridCategory("Parameters")]
              public int LowerLength
              {
              get { return lowerLength; }
              set { lowerLength = Math.Max(1, value); }
              }
              #endregion
              }
              }

              #region NinjaScript generated code. Neither change nor remove.
              // This namespace holds all indicators and is required. Do not change it.
              namespace NinjaTrader.Indicator
              {
              public partial class Indicator : IndicatorBase
              {
              private WeightedWave[] cacheWeightedWave = null;

              private static WeightedWave checkWeightedWave = new WeightedWave();

              /// <summary>
              /// Weighted moving average high - low - close
              /// </summary>
              /// <returns></returns>
              public WeightedWave WeightedWave(int highLength, int lowerLength, int middleLength)
              {
              return WeightedWave(Input, highLength, lowerLength, middleLength);
              }

              /// <summary>
              /// Weighted moving average high - low - close
              /// </summary>
              /// <returns></returns>
              public WeightedWave WeightedWave(Data.IDataSeries input, int highLength, int lowerLength, int middleLength)
              {
              if (cacheWeightedWave != null)
              for (int idx = 0; idx < cacheWeightedWave.Length; idx++)
              if (cacheWeightedWave[idx].HighLength == highLength && cacheWeightedWave[idx].LowerLength == lowerLength && cacheWeightedWave[idx].MiddleLength == middleLength && cacheWeightedWave[idx].EqualsInput(input))
              return cacheWeightedWave[idx];

              lock (checkWeightedWave)
              {
              checkWeightedWave.HighLength = highLength;
              highLength = checkWeightedWave.HighLength;
              checkWeightedWave.LowerLength = lowerLength;
              lowerLength = checkWeightedWave.LowerLength;
              checkWeightedWave.MiddleLength = middleLength;
              middleLength = checkWeightedWave.MiddleLength;

              if (cacheWeightedWave != null)
              for (int idx = 0; idx < cacheWeightedWave.Length; idx++)
              if (cacheWeightedWave[idx].HighLength == highLength && cacheWeightedWave[idx].LowerLength == lowerLength && cacheWeightedWave[idx].MiddleLength == middleLength && cacheWeightedWave[idx].EqualsInput(input))
              return cacheWeightedWave[idx];

              WeightedWave indicator = new WeightedWave();
              indicator.BarsRequired = BarsRequired;
              indicator.CalculateOnBarClose = CalculateOnBarClose;
              #if NT7
              indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
              indicator.MaximumBarsLookBack = MaximumBarsLookBack;
              #endif
              indicator.Input = input;
              indicator.HighLength = highLength;
              indicator.LowerLength = lowerLength;
              indicator.MiddleLength = middleLength;
              Indicators.Add(indicator);
              indicator.SetUp();

              WeightedWave[] tmp = new WeightedWave[cacheWeightedWave == null ? 1 : cacheWeightedWave.Length + 1];
              if (cacheWeightedWave != null)
              cacheWeightedWave.CopyTo(tmp, 0);
              tmp[tmp.Length - 1] = indicator;
              cacheWeightedWave = tmp;
              return indicator;
              }
              }
              }
              }

              // This namespace holds all market analyzer column definitions and is required. Do not change it.
              namespace NinjaTrader.MarketAnalyzer
              {
              public partial class Column : ColumnBase
              {
              /// <summary>
              /// Weighted moving average high - low - close
              /// </summary>
              /// <returns></returns>
              [Gui.Design.WizardCondition("Indicator")]
              public Indicator.WeightedWave WeightedWave(int highLength, int lowerLength, int middleLength)
              {
              return _indicator.WeightedWave(Input, highLength, lowerLength, middleLength);
              }

              /// <summary>
              /// Weighted moving average high - low - close
              /// </summary>
              /// <returns></returns>
              public Indicator.WeightedWave WeightedWave(Data.IDataSeries input, int highLength, int lowerLength, int middleLength)
              {
              return _indicator.WeightedWave(input, highLength, lowerLength, middleLength);
              }
              }
              }

              // This namespace holds all strategies and is required. Do not change it.
              namespace NinjaTrader.Strategy
              {
              public partial class Strategy : StrategyBase
              {
              /// <summary>
              /// Weighted moving average high - low - close
              /// </summary>
              /// <returns></returns>
              [Gui.Design.WizardCondition("Indicator")]
              public Indicator.WeightedWave WeightedWave(int highLength, int lowerLength, int middleLength)
              {
              return _indicator.WeightedWave(Input, highLength, lowerLength, middleLength);
              }

              /// <summary>
              /// Weighted moving average high - low - close
              /// </summary>
              /// <returns></returns>
              public Indicator.WeightedWave WeightedWave(Data.IDataSeries input, int highLength, int lowerLength, int middleLength)
              {
              if (InInitialize && input == null)
              throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

              return _indicator.WeightedWave(input, highLength, lowerLength, middleLength);
              }
              }
              }
              #endregion

              Comment


                #8
                Hello DayTrader12,

                Thank you for your post.

                Are you looking for the highest and lowest value of the WMA over the 20 period or using the High and Low as the input for your WMA?

                So this...
                Code:
                			double middle	= WMA(Input, Period)[0];
                			
                			double upper	= WMA(High, Period)[0];
                			double lower	= WMA(Low, Period)[0];
                
                			Midline.Set(middle);
                			Upper.Set(upper);
                			Lower.Set(lower);
                Or this?
                Code:
                			double middle	= WMA(Input, Period)[0];
                			
                			double upper	= MAX(WMA(Period), Period)[0];
                			double lower	= MIN(WMA(Period), Period)[0];
                
                			Midline.Set(middle);
                			Upper.Set(upper);
                			Lower.Set(lower);

                Comment


                  #9
                  Wma

                  Hi Patrick,

                  Can I have one of each?

                  That way I can run them side by side to see which one works best.

                  Thanks for the help, and a Happy New Year to you,

                  DT12

                  Comment


                    #10
                    Hello DayTrader12,

                    Then you would edit the code for Bertrand's indicator with the code below but create another one by right clicking in the NinjaScript Editor and selecting Save As.

                    Originally posted by NinjaTrader_PatrickH View Post
                    Hello DayTrader12,

                    Thank you for your post.

                    Are you looking for the highest and lowest value of the WMA over the 20 period or using the High and Low as the input for your WMA?

                    So this...
                    Code:
                    			double middle	= WMA(Input, Period)[0];
                    			
                    			double upper	= WMA(High, Period)[0];
                    			double lower	= WMA(Low, Period)[0];
                    
                    			Midline.Set(middle);
                    			Upper.Set(upper);
                    			Lower.Set(lower);
                    Or this?
                    Code:
                    			double middle	= WMA(Input, Period)[0];
                    			
                    			double upper	= MAX(WMA(Period), Period)[0];
                    			double lower	= MIN(WMA(Period), Period)[0];
                    
                    			Midline.Set(middle);
                    			Upper.Set(upper);
                    			Lower.Set(lower);

                    Comment


                      #11
                      Thanks Patrick, let me try that.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by BarzTrading, Today, 07:25 AM
                      2 responses
                      21 views
                      1 like
                      Last Post BarzTrading  
                      Started by devatechnologies, 04-14-2024, 02:58 PM
                      3 responses
                      20 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Started by tkaboris, Today, 08:01 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post tkaboris  
                      Started by EB Worx, 04-04-2023, 02:34 AM
                      7 responses
                      163 views
                      0 likes
                      Last Post VFI26
                      by VFI26
                       
                      Started by Mizzouman1, Today, 07:35 AM
                      1 response
                      10 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Working...
                      X