Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

5mim ema loaded on 15min chart

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

    5mim ema loaded on 15min chart

    Hello i want to load my 5min 200ema on to my 15min chart can i do this?

    I see an indicator higher timeframe ema on lower charts. I basically want the opposite.

    Strategy is fine also
    Last edited by Christopher Leggit; 05-26-2024, 08:59 PM.

    #2
    You can load a 5-minute 200 EMA onto a 15-minute chart in NinjaScript by using the AddDataSeries method to add the 5-minute data series to your 15-minute chart, and then calculating the EMA based on the 5-minute data. Here is a step-by-step guide on how to achieve this: Steps to Load 5-minute 200 EMA on a 15-minute Chart
    1. Add the 5-minute Data Series: Use the AddDataSeries method to add the 5-minute data series.
    2. Calculate the EMA: Calculate the 200-period EMA based on the 5-minute data series.
    3. Plot the EMA on the 15-minute Chart: Plot the calculated EMA on your primary 15-minute chart.
    HTML Code:
    using NinjaTrader.NinjaScript.Strategy;
    using NinjaTrader.Data;
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public class FiveMinuteEMAOnFifteenMinuteChart : Strategy
        {
            private EMA ema5Min;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description = "Strategy to plot 5-minute 200 EMA on 15-minute chart";
                    Name = "FiveMinuteEMAOnFifteenMinuteChart";
                    Calculate = Calculate.OnEachTick;
                }
                else if (State == State.Configure)
                {
                    // Add the 5-minute data series
                    AddDataSeries(Data.BarsPeriodType.Minute, 5);
                }
                else if (State == State.DataLoaded)
                {
                    // Initialize the 5-minute EMA
                    ema5Min = EMA(BarsArray[1], 200);
                }
            }
    
            protected override void OnBarUpdate()
            {
                // Ensure we are only processing on the primary data series (15-minute chart)
                if (BarsInProgress == 0)
                {
                    // Plot the 5-minute 200 EMA on the 15-minute chart
                    double emaValue = ema5Min[0];
                    PlotEMA(emaValue);
                }
            }
    
            private void PlotEMA(double value)
            {
                Draw.TextFixed(this, "emaValue", "5-Minute 200 EMA: " + value.ToString(), TextPosition.TopRight);
            }
        }
    }
    ​
    1. OnStateChange:
      • State.SetDefaults: Sets the default properties for the strategy.
      • State.Configure: Adds the 5-minute data series using AddDataSeries(Data.BarsPeriodType.Minute, 5).
      • State.DataLoaded: Initializes the 5-minute 200 EMA using EMA(BarsArray[1], 200).
    2. OnBarUpdate:
      • Checks if the BarsInProgress is 0, ensuring the logic runs only on the primary data series (15-minute chart).
      • Retrieves the current value of the 5-minute 200 EMA using ema5Min[0].
      • Calls PlotEMA to display the EMA value on the chart.
    3. PlotEMA Method:
      • Uses Draw.TextFixed to display the EMA value on the chart. You can modify this method to plot the EMA value in other ways, such as using Draw.Line or creating a custom plot.
    Note
    • Ensure that you have enough historical data loaded to calculate the 200-period EMA on the 5-minute chart.
    • You can further customize the PlotEMA method to better fit your visualization needs.

    This implementation adds the 5-minute data series, calculates the 200-period EMA based on the 5-minute data, and then plots this EMA value on the primary 15-minute chart.

    Comment


      #3
      Thank you very much Ryan so helpful

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      54 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      72 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X