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

Daily Sma on 5 minute Chart

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

    Daily Sma on 5 minute Chart

    Good day

    I am struggling in adding daily SMA (with a period of 10 for example) on 5 minute chart. Can you direct me how can I do it? Thanxs

    Tranta

    #2
    Tranta,

    Thank you for your post.

    I am assuming by the sound of your post that you are not trying to program this.

    In which case here is how you add a SMA(10) to your chart.
    • Right click on the chart and select Indicators...
    • Select the SMA from the top left list and click New
    • Set the Period, to the right, to 10
    • Click OK to apply the settings and close the window


    Here is a link to help guide on working with indicators -
    http://www.ninjatrader.com/support/h...indicators.htm
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      I have tried to write a new indicator to get daily 5-day-SMA on 5-minute chart. So far I have not succeeded. Can You assist me?

      Tranta

      Comment


        #4
        Tranta,

        You would need to use multi-timeframes in your script.

        Add(PeriodType.Day, 1);

        This will add a 1 day data series to the script that can be used for calculations. Add the snippet to the Initialize() section.

        You would then use SMA(Closes[1], 5)[0] to access the 1 day data series and return your SMA value.

        Add SMA(Closes[1], 5)[0] to your Plot.Set();

        Take a look at the link below on working with Multi-timeframes and instruments -
        http://www.ninjatrader.com/support/h...nstruments.htm
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          I am sorry but if still doesnt work

          /// <summary>
          /// Denni SMA
          /// </summary>
          [Description("Denni SMA")]
          public class DenniSMA : Indicator
          {
          #region Variables
          // Wizard generated variables
          // 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(PeriodType.Day, 1);
          Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
          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.
          Plot0.Set(SMA(Closes[1], 5)[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 Plot0
          {
          get { return Values[0]; }
          }

          #endregion
          }
          }

          Comment


            #6
            Tranta,

            Do you receive a compile error? Check your log tab in the control center

            Additionally, you will need to load more than 5 days in the minute chart. Try changing the days to load to 20 or more.
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              I received this in log

              28.1.2014 15:48 Default Error on calling 'OnBarUpdate' method for indicator 'DenniSMA' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

              and I loaded 50days data

              Comment


                #8
                Tranta,

                Thank you.

                You will need to include a CurrentBar check into your logic at the beginning of OnBarUpdate()

                if(CurrentBar < 1)
                return;

                Additionally, here is a reference sample -
                http://www.ninjatrader.com/support/f...ead.php?t=3170
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you code now looks :

                  #region Variables
                  // Wizard generated variables
                  // 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(PeriodType.Day, 1);
                  Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                  Overlay = false;
                  }

                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()

                  { if(CurrentBar < 0)
                  return;


                  // Use this method for calculating your indicator values. Assign a value to each
                  // plot below by replacing 'Close[0]' with your own formula.
                  Plot0.Set(SMA(Closes[1], 5)[0]);


                  But indicator doesnt show anything on 5minut chart and log still shows this:

                  28.1.2014 16:02 Default Error on calling 'OnBarUpdate' method for indicator 'DenniSMA' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

                  Comment


                    #10
                    Tranta,

                    if you change the check to CurrentBar < 1
                    Does this change it?
                    Cal H.NinjaTrader Customer Service

                    Comment


                      #11
                      After change, nothing changed

                      Log:
                      28.1.2014 16:18 Default Error on calling 'OnBarUpdate' method for indicator 'DenniSMA' on bar 1: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

                      Code:

                      #region Variables
                      // Wizard generated variables
                      // 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(PeriodType.Day, 1);
                      Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                      Overlay = true;
                      }

                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()

                      { if(CurrentBar < 1)
                      return;


                      // Use this method for calculating your indicator values. Assign a value to each
                      // plot below by replacing 'Close[0]' with your own formula.
                      Plot0.Set(SMA(Closes[1], 5)[0]);
                      }

                      I begin to be desperate

                      Comment


                        #12
                        Tranta,

                        Please send me a note to support[at]ninjatrader[dot]com
                        Put ATTN Cal in the subject and reference this post in the body.

                        I would like to set up a remote assistance to help resolve the issue
                        Cal H.NinjaTrader Customer Service

                        Comment


                          #13
                          tantra. Here is an easy solution to your basic question of plotting an SMA10 of a Daily Data Series into a 5Min Chart. See attached. But perhaps that's too simple and I misunderstood your question.

                          sandman
                          Attached Files

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Javierw.ok, Today, 04:12 PM
                          0 responses
                          2 views
                          0 likes
                          Last Post Javierw.ok  
                          Started by timmbbo, Today, 08:59 AM
                          2 responses
                          10 views
                          0 likes
                          Last Post bltdavid  
                          Started by alifarahani, Today, 09:40 AM
                          6 responses
                          40 views
                          0 likes
                          Last Post alifarahani  
                          Started by Waxavi, Today, 02:10 AM
                          1 response
                          18 views
                          0 likes
                          Last Post NinjaTrader_LuisH  
                          Started by Kaledus, Today, 01:29 PM
                          5 responses
                          15 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Working...
                          X