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

Same EMA but from multiple time frames

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

    Same EMA but from multiple time frames

    Hi.

    There is another multiple time frames indicator I am working on where I cannot get the lines to plot on the chart. What I am trying to do is by using only one DataSeries/InputSeries to plot the EMA of three additional timeframes. For example using a 1Min InputSeries and chart I want this indicator to plot a 13period EMA of the 2Min Data Series as well as a 13period EMA of the 3Min Data Series as well as a 13period EMA of a 5Min Data Series. The EMA is constant, the timeframes should be user definable as well as their individual colors.

    I seem to have everything together but the three lines just don't plot. I have attached an image of the code I use and the indicator window that opens. Just in case I have attached as well the indicator thus far.

    Is what I am trying to do with this even possible? And if yes, could you please look it over and advise where I am off.

    sandman
    Attached Files

    #2
    Originally posted by sandman View Post
    Hi.

    There is another multiple time frames indicator I am working on where I cannot get the lines to plot on the chart. What I am trying to do is by using only one DataSeries/InputSeries to plot the EMA of three additional timeframes. For example using a 1Min InputSeries and chart I want this indicator to plot a 13period EMA of the 2Min Data Series as well as a 13period EMA of the 3Min Data Series as well as a 13period EMA of a 5Min Data Series. The EMA is constant, the timeframes should be user definable as well as their individual colors.

    I seem to have everything together but the three lines just don't plot. I have attached an image of the code I use and the indicator window that opens. Just in case I have attached as well the indicator thus far.

    Is what I am trying to do with this even possible? And if yes, could you please look it over and advise where I am off.

    sandman
    Your OnBarUpdate() has no code to draw a Plot, so none will be drawn.

    Comment


      #3
      Thanks koganam.

      I now spent several hours trying different variations to fix what you said. I could not get the three EMA lines to show up. Attached is the latest version of code that I tried. Must still be doing something very wrong (not a coding expert I am).

      Help please.

      sandman
      Attached Files

      Comment


        #4
        Hello Sandman,

        Thank you for your post.

        Do you see any errors listed in the Log tab of the NinjaTrader Control Center when applying the indicator to the chart? If so what does this error report?

        Can you provide the code in your post rather than a screenshot so we may test this item on our end?

        I look forward to your response.

        Comment


          #5
          Maybe this would help -

          There is a multi - timeframe, multi MA indy called xcMovAvg, here is the link:

          Comment


            #6
            caveroute. I looked at that one already. Contains too many things I do not need and I could not make sense of the code to apply to mine. Thank you anyway.

            sandman

            Comment


              #7
              Patrick.

              Thanks. I had never seen this Log tab. Neat. Yes, it says:
              "Error on calling OnBarUpDate method for indicator DAEMAMultiTFs on bar 20: Index was outside the bounds of the array." Sofar so good but with my little coding education that is unfortunately Chinese for me. I attach the indicator, and would appreciate your help.

              sandman
              Attached Files

              Comment


                #8
                Originally posted by sandman View Post
                Patrick.

                Thanks. I had never seen this Log tab. Neat. Yes, it says:
                "Error on calling OnBarUpDate method for indicator DAEMAMultiTFs on bar 20: Index was outside the bounds of the array." Sofar so good but with my little coding education that is unfortunately Chinese for me. I attach the indicator, and would appreciate your help.

                sandman
                You have only 3 Plots. Your properties should access Values[0], Values[1], Values[2],not 1 to 3.

                Comment


                  #9
                  Hello sandman,

                  Thank you for your response.

                  Koganam is correct here, the DataSeries need to access the correct values. These values, like the barsAgo index, are accessed beginning at 0. You will need to change the properties section to reflect the following for the Plots:
                  Code:
                  #region Properties
                  	
                  		/// <summary>
                  		/// </summary>
                  		[Browsable(false)]
                  		[XmlIgnore()]
                  		public DataSeries Plot1
                  		{
                  			get { return Values[0]; }
                  		}
                  		
                  		
                  		/// <summary>
                  		/// </summary>
                  		[Browsable(false)]
                  		[XmlIgnore()]
                  		public DataSeries Plot2
                  		{
                  			get { return Values[1]; }
                  		}
                  		
                  		/// <summary>
                  		/// </summary>
                  		[Browsable(false)]
                  		[XmlIgnore()]
                  		public DataSeries Plot3
                  		{
                  			get { return Values[2]; }
                  		}
                  For information on the DataSeries Class in NinjaScript please visit the following link: http://www.ninjatrader.com/support/h...ries_class.htm

                  Please let me know if I may be of further assistance.

                  Comment


                    #10
                    Koganam, and Patrick.

                    Thank you very much. It took me a while to figure out where the Properties section was (I was searching before I saw Patrick's message). hm, blush

                    I now changed those values and the lines pop up. Relief. But they are zig zag lines. See attached image and code used.

                    Is that because they are calculated based on the 1min Data Series, or is there a way to smooth them out.

                    sandman
                    Attached Files

                    Comment


                      #11
                      Hello sandman,

                      Thank you for your response.

                      Each value of the EMAs is calculated on the bar series close, even though your 1 minute has closed the larger (let's say 5 minute) bar series has yet to close and the value is the same. This then plot the same value onto the 1 minute bar for 5 bars.

                      To correct this you could do what you have done earlier and set each indicator to it's own BarsInProgress check.
                      Code:
                      if (BarsInProgress == 1) 
                          		
                      				{ 
                      					Plot1.Set(EMA(BarsArray[1],13)[0]);	
                          			} 
                      			else if (BarsInProgress == 2) 
                          			{ 
                      					Plot2.Set(EMA(BarsArray[2],13)[0]);	
                          			} 
                      			else if (BarsInProgress == 3)
                      				{ 
                      					Plot3.Set(EMA(BarsArray[3],13)[0]);	
                          			}
                      Please let me know if I may be of further assistance.

                      Comment


                        #12
                        Technically the appearance as a step function is correct. If you want to smooth the steps, there are several ways to do so.

                        (1) Interpolation

                        This is achieved by linking the stair cases, see chart attached. However, the indicator needs to repaint the last section in order to do the smoothing. The smoothing can also be done without repainting, but in that case you would introduce an additional lag.

                        (2) Tweaking the indicator

                        I understand that you try to build an EMA for a higher timeframe. For both EMA and SMA there is a simple solution: multiply the period of the EMA with the timeframe factor.

                        -> a 13-period EMA on a 3 min chart is near-identical to a 39-period EMA on a 1-minute chart
                        -> a 13-period EMA on a 10 min chart is near identical to a 130-period EMA on a 1 min chart

                        Of course there are minor differences created by session templates and exponential smoothing, but they can be neglected.

                        Originally posted by sandman View Post
                        Koganam, and Patrick.

                        Thank you very much. It took me a while to figure out where the Properties section was (I was searching before I saw Patrick's message). hm, blush

                        I now changed those values and the lines pop up. Relief. But they are zig zag lines. See attached image and code used.

                        Is that because they are calculated based on the 1min Data Series, or is there a way to smooth them out.

                        sandman
                        Attached Files

                        Comment


                          #13
                          Patrick.

                          Thanks for the suggestion. I noticed when I apply the indicator to a time frame and then use it to plot LOWER time frame EMAs it works beautiful. Like using an Input/DataSeries of 15Minutes and then have it plot the EMAs from the 10, 5 and 3minutes for example, that comes out very smooth. It's when I want it to plot HIGHER timeframe EMAs is when it produces the zigzag lines. See attached first image with an example for both.

                          I then used your suggestion but it still does not plot correctly. See Image 2. Do you have any other input for me? That last version of the indicator is attached just in case you want to try it out.

                          sandman
                          Attached Files

                          Comment


                            #14
                            Originally posted by sandman View Post
                            Patrick.

                            Thanks for the suggestion. I noticed when I apply the indicator to a time frame and then use it to plot LOWER time frame EMAs it works beautiful. Like using an Input/DataSeries of 15Minutes and then have it plot the EMAs from the 10, 5 and 3minutes for example, that comes out very smooth. It's when I want it to plot HIGHER timeframe EMAs is when it produces the zigzag lines. See attached first image with an example for both.

                            I then used your suggestion but it still does not plot correctly. See Image 2. Do you have any other input for me? That last version of the indicator is attached just in case you want to try it out.

                            sandman
                            The step function is as expected. Whenever a bar of the secondary bar series is completed, the indicator is calculated. This leads to a change in the indicator value on your chart. This value remains constant, until the next value is retrieved. That is the logic and your chart shows exactly what is intended.

                            Comment


                              #15
                              Hello Sandman,

                              Thank you for your response.

                              Harry is correct here, the step would be correct when using the different time frames for the EMAs. My suggestion did not work as it only updates when the bar closes for that bar series.

                              The higher time frame for the primary bar series means the plots will have to draw on a higher time frame and this will smooth the value, but with a smaller primary bar series it will have the step effect.

                              Please let me know if you have any questions.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by CortexZenUSA, Today, 12:53 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post CortexZenUSA  
                              Started by CortexZenUSA, Today, 12:46 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post CortexZenUSA  
                              Started by usazencortex, Today, 12:43 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post usazencortex  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              168 responses
                              2,265 views
                              0 likes
                              Last Post sidlercom80  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              3 responses
                              11 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X