Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculating Daily and Intraday EMA In Same Strategy

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

    Calculating Daily and Intraday EMA In Same Strategy

    Hi all,

    So I've looked around about this topic quite a bit, and found various threads and posts and even some videos on how to add a higher timeframe indicator (like a moving average) to a lower timeframe chart via an additional panel. I want to do this in code. Taking some notes from the other threads I found, I learned the following need to be done to get to my solution. Here's what I need to do:

    - I want to calculate both the daily 50EMA and the 5-minute 50EMA in the same strategy. I want to use the daily 50EMA value as a filter for my 5-minute trades. From all my researching, here's what it seems like I need

    1) Add my secondary data series using AddDataSeries(BarsPeriodType.Day, 1)
    2) In OnBarUpdate() check when BarsInProgress == 1 indicating that we are calculating daily bars
    3) Set the value of the ema using Value[0] = emaDaily[0]. (not 100% sure if this is needed?)
    4) Store the value of the daily ema in a variable so we can use it in our primary series entry logic (BarsInProgress == 0)

    My results are that the intraday ema calculation seems fine, and is fairly in line with other platforms. The problem is that the daily ema value seems way off from other platforms like ThinkOrSwim. Am I missing something? Or could this just be due to a data discrepancy, or even indicator code differences between the platforms? I want to make sure my code is correct before proceeding, and it would be great to get some confirmation of that.

    I've attached a short file below for more context.

    Thanks as always


    - Jay

    Attached Files
    jaybedreamin
    NinjaTrader Ecosystem Vendor - Zion Trading Algos

    #2
    Hello jaybedreamin,

    The step 3 and 4 are not needed.

    The easiest way to accomplish this would be to use the strategy builder to generate the syntax. In the builder you would use the additional data screen to add the daily series. Then in set 1 you can make a condition using the two ema values and press view code, that will generate all the code needed for comparing the two indicators.

    When you make a condition in the builder using an indicator it has a field called input series, if you click Set inside that box it will bring up a window where you can choose the daily series. For the second indicator you can leave the default input selected. That will pass the daily series to the ema so that when you are getting values from that ema variable that represents the daily ema.

    Another benefit of using the builder is that it will limit the processing to the primary series so you don't have to worry about using BarsInProgress logic.

    If you are comparing against other platforms they may use different daily data which may cause differences from NinjaTrader data. Daily bars can represent the RTH orr ETH hours depending on the broker. You can optionally add a 1440 minute series to create daily bars based on the minute data as another way to compare against different data sources.
    Last edited by NinjaTrader_Jesse; 09-15-2023, 09:37 AM.

    Comment


      #3
      Jesse, you are always a great help. Thank you for letting me know that steps 3 and 4 are not needed.

      I will play around with the Strategy Builder and compare the generated code with my manual approach.

      jaybedreamin
      NinjaTrader Ecosystem Vendor - Zion Trading Algos

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      66 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      141 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      76 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      47 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      51 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X