Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculation of EMA

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

    Calculation of EMA

    Hello there,

    whoever could help I'd appreciate it.

    When it comes to calculating an EMA, say EMA(50), I understand that this will depend on how many "Min Bars Required" I define on the backtest inputs.

    What if, however, I want to have the EMA being calculated starting at he beginning of each day?

    For example

    I backtest for a 5-day period of time and I'm using 1-minute bars. During the 3rd day for example, on a given bar ( >= 50), I want to calculate the EMA(50) but I want it to do it not using the entire historical data point series but only starting from the first bar of that day (where by definition EMA(50) on the first bar is equal to the current bar price).

    Thanks a lot.

    #2
    Hello quantq,

    Welcome to our forums.

    What it sounds like you want to do is dynamically update the number of bars used to calculate an average as the day progresses.

    First bar in series: EMA(1)
    Second bar in series EMA(2)
    ......
    50th bar in series EMA(50)

    You could probably accomplish this using a combination of FirstBarOfSession checks and then a for loop to update Period + 1 as it iterates through. You'll also have to turn on "Show Unstable Period for indicators" in your chart properties.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks Ryan.

      Is there any way I can track which bar of the day the current bar is? I know "CurrentBar" is not it. "CurrentBar" shows the position of the bar starting from where I initiated the series based on Min Bars required.

      How can I track the index of the bar starting from the beginning of the day. (Say 9:30am for equities)?

      Comment


        #4
        Hello Quantq,

        There is a built in method called BarsSinceSession() that does this. Session time is defined in your chart properties.



        The first bar of the session has BarsSinceSession() = 0.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Ryan, great!

          Now I think I should be able to work it out. Perhaps have to recode a variation of the existing EMA.

          Thanks.

          Comment


            #6
            Hello Ryan,

            I did follow your instructions (btw you can also with FirstBarofSession() as well) and it worked out perfect.

            However I have a little problem which I don't know how to solve. What if I bring up a new chart window, pull up the chart of a symbol and want to display my new indicator.

            Since my indicator depends obviously on when the session begins, where exactly do I define what the beginning of the session is? I see how I define that in backtesting but how about when I simply want to look at a chart?

            Comment


              #7
              Hello Quantq,

              Session times are defined in chart properties. Right click on your chart > Properties. There are fields for Session Begins and Session Ends.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                cool, thanks. Much appreciated!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by DJ888, 04-16-2024, 06:09 PM
                6 responses
                18 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by Jon17, Today, 04:33 PM
                0 responses
                1 view
                0 likes
                Last Post Jon17
                by Jon17
                 
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                6 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
                41 views
                0 likes
                Last Post alifarahani  
                Working...
                X