Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plot ema from different timeframe

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

    Plot ema from different timeframe

    Hi i am plotting 2 emas from different timeseries.
    I have two issues
    1. How can i make sure to remove the falling stick of the ema indicator see attachment
    2. ema89 is not plotting. Why?

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class EMAon5minData : Indicator
        {
            private EMA EMA34, EMA89;
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Indicator here.";
                    Name                                        = "EMAon5minData";
                    Calculate                                    = Calculate.OnBarClose;
                    IsOverlay                                    = true;
                    DisplayInDataBox                            = true;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                        = true;
                    DrawVerticalGridLines                        = true;
                    PaintPriceMarkers                            = true;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
                    AddPlot(Brushes.Orange, "EMAPlot34");
                    AddPlot(Brushes.Cyan, "EMAPlot89");
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(this.Instrument.FullName, new BarsPeriod { BarsPeriodType = (BarsPeriodType)2018, BaseBarsPeriodValue = 10, Value = 10, Value2 = 50 });
                }
                else if (State == State.DataLoaded)
                {
                    EMA34 = EMA(BarsArray[1], 34);  //set EMA here so we make sure it's calculated on the secondary data series
                    EMA89 = EMA(BarsArray[1], 89);
                }
    
            }
    
            protected override void OnBarUpdate()
            {
    
                if (CurrentBars[0] < 1 || CurrentBars[1] < 20) // make sure there's at least one bar for primary series and at least 20 of the secondary series prior to processing
                    return;
    
                if(BarsInProgress == 0) // if OnBarUpdate was called from the primary bar series, then set the current value to the latest EMA1 value
    
                    Value[0] = EMA34[0];    
                    Value[1] = EMA89[0];    
    
            }
    
            #region Properties
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> EMAPlot34
            {
                get { return Values[0]; }
            }
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> EMAPlot89
            {
                get { return Values[1]; }
            }
            #endregion
    
        }
    }​
    Click image for larger version

Name:	image.png
Views:	233
Size:	23.2 KB
ID:	1282407

    #2
    Hello tkaboris,

    Your BarsInProgress condition is not surrounding your code, you need to use curly braces if you want to have an if condition apply to multiple lines of code:

    Code:
    if(BarsInProgress == 0)
    {
        Value[0] = EMA34[0];
        Value[1] = EMA89[0];
    }
    You also have the wrong code for setting the plots, you are setting the current bar value of Plot 1 and the Previous bar value of Plot 1. You need to use the properties you made for your plots instead.

    EMAPlot34 = EMA34[0];
    EMAPlot89 = EMA89[0];


    Beyond that you would need to use a Print to see what value the EMA89 has when you access it. You are using a custom bars type so I would not be able to tell how that should appear on the chart you are using. ​

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    648 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    369 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    572 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    574 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X