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

10 weeks MA

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

    10 weeks MA

    Hi there,

    I am attempting to make a script for 10 weeks moving average of friday close developed by Larry Williams. I made script based on NinjaTrader SMA Indicator, but it seems doesn't work.

    Here is modified piece of code:

    protected override void OnBarUpdate()
    {
    if (CurrentBar == 0 && Time[0].DayOfWeek == DayOfWeek.Friday)
    Value.Set(Input[0]);
    else
    if (Time[0].DayOfWeek == DayOfWeek.Friday)
    {
    double last = Value[1] * Math.Min(CurrentBar, Period);

    if (CurrentBar >= Period)
    Value.Set((last + Input[0] - Input[Period]) / Math.Min(CurrentBar, Period));

    else
    Value.Set((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1));

    }

    I want filter out only friday's Close for 10 weeks and plot solid line into chart.

    Please, could you help me guys.

    regards

    sniper29a

    #2
    Not sure how it should look but your code looks like you only set a value if its Friday which would mean that other days, you will have draw nothing in your chart. If you want to calculate a value on on Friday and plot this value up until next Thursday, you would need to store the Friday calculation in a variable.

    logic:

    if (Friday)
    fridayValue = some calculation

    Value.Set(fridayValue)
    RayNinjaTrader Customer Service

    Comment


      #3
      Hi Ray,

      thanks for reply.

      All I need is indicator which uses ONLY friday close and plot only solid line based on friday close. Rest of days must be not counted.

      Indeed, indicator doesn't plot anything yet. All I have seen is sometimes price tag (possibly on friday), but no solid line.

      Is it even possible to program script like that?

      sniper29a

      Comment


        #4
        My code concept will do that, a solid line for each week based on the prior friday's calculation.
        RayNinjaTrader Customer Service

        Comment


          #5
          I tried following to find out if simple friday close shows:

          if (CurrentBar == 0 && Time[0].DayOfWeek == DayOfWeek.Friday)
          {
          double FridayValue = Close[0];
          Value.Set(FridayValue);
          }

          else
          if (Time[0].DayOfWeek == DayOfWeek.Friday)
          {
          double FridayValue = Close[0];
          Value.Set(FridayValue);

          Unfortunatelly, It doesn't plot anything. Do I miss something? I am new with NinjaTrader. I may have not enough knowledge with your programming language...thanks

          Could you post your code you would use, please?

          Comment


            #6
            Hello,


            Thank you for your post.

            I will test this and reply to your post with recommendations later this afternoon.
            DenNinjaTrader Customer Service

            Comment


              #7
              Try something like this:

              Under the variables section:

              double fridayValue = 0;

              then in OnBarUpdate():

              Code:
              if (Time[0].DayOfWeek == DayOfWeek.Friday)
                  fridayValue = Close[0];
              
              if (fridayValue > 0)
                  Value.Set(fridayValue);
              RayNinjaTrader Customer Service

              Comment


                #8
                thanks for reply. It works, but second branching doesn't filter out only fridays. once I put in something like that

                Code:
                if (FridayValue > 0 && Time[0].DayOfWeek == DayOfWeek.Friday)
                or
                Code:
                if ((FridayValue > 0) && (Time[0].DayOfWeek == DayOfWeek.Friday))
                It stops to work again. Why It suppose to be friday > 0 AND Friday. Isn't it?

                Comment


                  #9
                  Welcome to the world of debugging...You will have to take a closer look at your code to see why it does not work as expected.
                  RayNinjaTrader Customer Service

                  Comment


                    #10
                    I love this world, but I am lost.

                    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>
                        /// Larryho 10-ti tydenni MA patecnich close
                        /// </summary>
                        [Description("Larryho 10-ti tydenni MA patecnich close")]
                        public class TWMA : Indicator
                        {
                            #region Variables
                            private int        period    = 10;
                            private double    FridayValue = 0;
                            #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.Blue, "TWMA"));
                                
                                Overlay    = true;            
                                PriceTypeSupported    = true;
                            }
                    
                            /// <summary>
                            /// Called on each bar update event (incoming tick)
                            /// </summary>
                            protected override void OnBarUpdate()
                            {
                                if (Time[0].DayOfWeek == DayOfWeek.Friday)
                                    FridayValue = Close[0];
                                
                                [B]if (FridayValue > 0 && Time[0].DayOfWeek == DayOfWeek.Friday) //doesn't work???? [/B]
                                        {
                                            Value.Set(FridayValue);
                                            //double last = Value[1] * Math.Min(CurrentBar, Period);
                                            
                                            //if (CurrentBar >= Period)
                                            //    Value.Set((last + Input[0] - Input[Period]) / Math.Min(CurrentBar, Period));
                                            
                                            //else
                                            //    Value.Set((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1));
                                
                                        }
                            }
                    
                            #region Properties
                            /// <summary>
                            /// </summary>
                            //[Description("Numbers of bars used for calculations")]
                            //[Category("Parameters")]
                            public int Period
                            {
                                get { return period; }
                                set { period = 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 TWMA[] cacheTWMA = null;
                    
                            private static TWMA checkTWMA = new TWMA();
                    
                            /// <summary>
                            /// Larryho 10-ti tydenni MA patecnich close
                            /// </summary>
                            /// <returns></returns>
                            public TWMA TWMA()
                            {
                                return TWMA(Input);
                            }
                    
                            /// <summary>
                            /// Larryho 10-ti tydenni MA patecnich close
                            /// </summary>
                            /// <returns></returns>
                            public TWMA TWMA(Data.IDataSeries input)
                            {
                    
                                if (cacheTWMA != null)
                                    for (int idx = 0; idx < cacheTWMA.Length; idx++)
                                        if (cacheTWMA[idx].EqualsInput(input))
                                            return cacheTWMA[idx];
                    
                                TWMA indicator = new TWMA();
                                indicator.BarsRequired = BarsRequired;
                                indicator.CalculateOnBarClose = CalculateOnBarClose;
                                indicator.Input = input;
                                indicator.SetUp();
                    
                                TWMA[] tmp = new TWMA[cacheTWMA == null ? 1 : cacheTWMA.Length + 1];
                                if (cacheTWMA != null)
                                    cacheTWMA.CopyTo(tmp, 0);
                                tmp[tmp.Length - 1] = indicator;
                                cacheTWMA = tmp;
                                Indicators.Add(indicator);
                    
                                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>
                            /// Larryho 10-ti tydenni MA patecnich close
                            /// </summary>
                            /// <returns></returns>
                            [Gui.Design.WizardCondition("Indicator")]
                            public Indicator.TWMA TWMA()
                            {
                                return _indicator.TWMA(Input);
                            }
                    
                            /// <summary>
                            /// Larryho 10-ti tydenni MA patecnich close
                            /// </summary>
                            /// <returns></returns>
                            public Indicator.TWMA TWMA(Data.IDataSeries input)
                            {
                                return _indicator.TWMA(input);
                            }
                    
                        }
                    }
                    
                    // This namespace holds all strategies and is required. Do not change it.
                    namespace NinjaTrader.Strategy
                    {
                        public partial class Strategy : StrategyBase
                        {
                            /// <summary>
                            /// Larryho 10-ti tydenni MA patecnich close
                            /// </summary>
                            /// <returns></returns>
                            [Gui.Design.WizardCondition("Indicator")]
                            public Indicator.TWMA TWMA()
                            {
                                return _indicator.TWMA(Input);
                            }
                    
                            /// <summary>
                            /// Larryho 10-ti tydenni MA patecnich close
                            /// </summary>
                            /// <returns></returns>
                            public Indicator.TWMA TWMA(Data.IDataSeries input)
                            {
                                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.TWMA(input);
                            }
                    
                        }
                    }
                    #endregion
                    As I have written early. If I use one criteria, it works. Once I put condition AND condition. it doesn't work, so tell me what can I debug?

                    Comment


                      #11
                      The condition you put in then does not match your desired outcome. This is a logic issue, you need to re-think it. The code is doing what you tell it to do.

                      Sorry I can't be of more help.
                      RayNinjaTrader Customer Service

                      Comment


                        #12
                        I possibly misunderstood concept of barupdate. It is called every bar. So if condition doesn't mach it just skip to next bar then?

                        I require:

                        only friday close for 10 weeks

                        so it is impossible then. If I filter out only fridays, it will not plot line between because there is gap betwen friday to friday.

                        Is it right?

                        I suppose that I could plot line on friday-to-friday basis, but it doesn't work then...

                        thanks for patience guys

                        Comment


                          #13
                          That is correct.
                          RayNinjaTrader Customer Service

                          Comment


                            #14
                            Ok thanks, I stopped to hunt holy grail

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by gravdigaz6, Today, 11:40 PM
                            1 response
                            7 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by MarianApalaghiei, Today, 10:49 PM
                            3 responses
                            10 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by XXtrader, Today, 11:30 PM
                            0 responses
                            4 views
                            0 likes
                            Last Post XXtrader  
                            Started by love2code2trade, Yesterday, 01:45 PM
                            4 responses
                            28 views
                            0 likes
                            Last Post love2code2trade  
                            Started by funk10101, Today, 09:43 PM
                            0 responses
                            9 views
                            0 likes
                            Last Post funk10101  
                            Working...
                            X