Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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:	113
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. ​
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by rhyminkevin, Yesterday, 04:58 PM
    5 responses
    62 views
    0 likes
    Last Post dp8282
    by dp8282
     
    Started by realblubb, Today, 09:28 AM
    0 responses
    2 views
    0 likes
    Last Post realblubb  
    Started by AaronKoRn, Yesterday, 09:49 PM
    1 response
    18 views
    0 likes
    Last Post Rikazkhan007  
    Started by ageeholdings, Today, 07:43 AM
    0 responses
    12 views
    0 likes
    Last Post ageeholdings  
    Started by pibrew, Today, 06:37 AM
    0 responses
    4 views
    0 likes
    Last Post pibrew
    by pibrew
     
    Working...
    X