• 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

Multi Time Frame and EMA diffs

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

    Multi Time Frame and EMA diffs

    Hope this makes sense.
    I have a multi time frame indicator called MultiTest. For instance, I added 3 minute bars data to MultiTest using Add(PeriodType.Minute, 3). I applied the MultiTest indicator to a 1 minute chart. I have the indicator set to CalculateOnBarClose = false so as to update on every tick. I then calculate EMA's for the two different time frames:
    ema1Minute = EMA(Closes[0], 10)[0];
    ema3Minute = EMA(Closes[1], 10)[0];

    I can plot these and they update real time (tick by tick) using something like this:
    The1MinuteEMA.Set(ema1Minute);
    The3MinuteEMA.Set(ema3Minute);

    However, if I take the difference of the 2 EMA's and try and plot then I can't get tick by tick updating of the difference. It only updates at the end of the 1 minute bar. For instance, if I do the following then I don't get tick by tick updating:
    Diff.Set(ema1Minute - ema3Minute)
    This only updates at the end of a the 1 minute bar and not tick by tick.

    I don't understand why the Diff of the two different time frame EMA's won't plot tick by tick while either of the individual EMA's will plot tick by tick. Thank you.

    #2
    Originally posted by higler View Post
    Hope this makes sense.
    I have a multi time frame indicator called MultiTest. For instance, I added 3 minute bars data to MultiTest using Add(PeriodType.Minute, 3). I applied the MultiTest indicator to a 1 minute chart. I have the indicator set to CalculateOnBarClose = false so as to update on every tick. I then calculate EMA's for the two different time frames:
    ema1Minute = EMA(Closes[0], 10)[0];
    ema3Minute = EMA(Closes[1], 10)[0];

    .
    I will have a quick stab at this since no one else has answered yet.

    Without seeing your code, I cant be sure but is it possible that you arn't putting the
    calcualtion for the difference in the correct "BarsInProgress" sequence. Naturally your vars would also have to be global so they dont reset to 0 between BarsInProgress.

    e.g

    I think the sequence would need to be as follows

    if (BarsInProgress == 0)
    {
    assign your 1 min ema val here

    }

    if (BarsInProgress == 1)
    {
    assign your 3 min ema val here
    now do your calculation
    }

    Comment


      #3
      Hello higler,

      Thanks for your post.

      When the data is first loaded on the chart it will be processing historical data and from that basis will calculate as if CalculateOnbarClose = true. Once the indicator is connected to live data it should be processing on a tic by tic basis.

      I've replicated the code you've shown and I do see that when connected to live data all three traces are updating in realtime, tick by tick.

      Can you provide a screenshot of what you are seeing and perhaps a bit more of your code?
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        I have listed the code below. See also the 2 attachments. Attachment "MultiTest 1min 3min plots.jpg" shows the 1 minute and 3 minute plots. They both update real time tick by tick. Attachment "Diff of 1min 3min.jpg" plots the difference. It does not update tick by tick (only at the end of each minute) even though the 1 min and 3 min plots are updating tick by tick. I've shown it on two different charts because if all three plots are shown simultaneously that it gets too compressed.

        Code follows:

        public class hMultiTest : Indicator
        {
        #region Variables
        double ema1Minute = 0;
        double ema3Minute = 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.FromKnownColor(KnownColor.Blue), PlotStyle.Line, "The1EMA"));
        Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "The3EMA"));
        Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Diff"));
        Add(PeriodType.Minute, 3);

        Overlay = false;
        CalculateOnBarClose = 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.
        if ((CurrentBars[0] <= 10) || (CurrentBars[1] <= 10)) return;

        ema1Minute = EMA(Closes[0], 10)[0];

        ema3Minute = EMA(Closes[1], 10)[0];

        The1EMA.Set(ema1Minute);
        The3EMA.Set(ema3Minute);
        Diff.Set(ema1Minute - ema3Minute);


        }

        #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 The1EMA
        {
        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 The3EMA
        {
        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 Diff
        {
        get { return Values[2]; }
        }

        #endregion
        }
        Attached Files

        Comment


          #5
          Hello,

          Thanks for your reply.

          I'm still not sure why you are not seeing the tic by tic change. I took your code and modified it to show the difference directly between the moving averages. I captured it in a video: http://screencast.com/t/crpUALVpN3iV
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Thank you. I'm going to take your code and run it on my system to see what happens.

            Comment


              #7
              Paul - Thank you or your help. I ran your code on my system and get the same results as you. What I find interesting, and don't understand (I'm not a mathematician), is that although the 2 different time frame EMA's update on every tick the difference between the two remains the same until the next minute bar, at which time the difference changes and again remains constant throughout the minute, etc. I would have thought that the difference between the two different time frame EMA's would at least change a little during the minute since it changes immediately (sometimes by quite a bit) at the beginning of a new minute. Maybe it has to do with how EMA's are calculated and weighted in their calculation. But, thank you.
              Last edited by higler; 10-12-2015, 08:05 AM.

              Comment


                #8
                Hello higler,

                The code I showed does show that the diff is being updated tick by tick. The issue is that you are looking at two EMAs which are reacting effectively in parallel and thus are not changing relative to each other, keeping the diff value the same. If you change 1 of the EMAs to an SMA then I think you will see an intra bar differences.

                Print ("CB: "+CurrentBars[0]+" Diff: "+Diff[0]);
                Paul H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by D Trader, Yesterday, 09:43 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by cassiano_sanches, 07-10-2020, 07:37 PM
                1 response
                14 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by terminatorT1000, 07-10-2020, 06:40 PM
                2 responses
                31 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by Giudiver, 07-10-2020, 04:29 PM
                2 responses
                17 views
                0 likes
                Last Post Giudiver  
                Started by rtwave, Today, 04:11 PM
                0 responses
                4 views
                0 likes
                Last Post rtwave
                by rtwave
                 
                Working...
                X