Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is there already script somewhere here for 2 EMA crossovers?

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

    #16
    Originally posted by NinjaTrader_Josh View Post
    So title yours how you want them to be in Properties. What ever you name it in the line I have highlighted in Properties is what you have to call for the .Set.
    This is how properties now reads, but I get an error that '}' expected on the line in red below in col 16 but it doesnt fix it when added :
    #region Properties
    ///<summary>
    ///</summary>
    [Browsable(false)]
    [XmlIgnore()]
    public DataSeries Fast
    {
    get { return Values[1]; }
    }
    ///<summary>
    ///</summary>
    [Browsable(false)]
    [XmlIgnore()]
    public DataSeries Slow
    {
    get { return Values[0]; }
    }

    #endregion

    Comment


      #17
      this how variables reads:
      #region Variables
      privateint fast = 5;
      privateint slow = 6;

      #endregion

      and this is above properties:
      Value.Set(CurrentBar == 0 ? Close[0] : Close[0] * (2.0 / (1 + fast)) + (1 - (2.0 / (1 + fast))) * Value[1]);
      Value.Set(CurrentBar ==
      0 ? Open[0] : Open[0] * (2.0 / (1 + slow)) + (1 - (2.0 / (1 + slow))) * Value[1]);

      Comment


        #18
        simpletrades,

        You likely have some missing parenthesis or curly brackets above that line somewhere which makes all downstream editing erroneous.

        Again, you should NOT be using Value.Set. You need to call .Set on the actual plot names that you have defined. Please look at the relationship between all the parts at play in MACD. Look at the Initialize() how the Add() creates the plots. Look in the Properties how the plots names are created. Then look in OnBarUpdate() for how .Set is actually used on each one of them.
        Josh P.NinjaTrader Customer Service

        Comment


          #19
          Originally posted by NinjaTrader_Josh View Post
          Again, you should NOT be using Value.Set. You need to call .Set on the actual plot names that you have defined. .
          I had replaced Value with Fast and Slow but got more errors so I switched back to Value, but I'll redo it again and try to find the unmatched }

          Comment


            #20
            still stuck. I tried to copy what looked like it was needed out of MACD.
            I get an error now that there is no definition for plots (as shown below):

            fastEMA.Plots[0].Pen.Color = Color.Orange; slowEMA.Plots[0].Pen.Color = Color.Blue;

            Here's my current code:
            HTML Code:
            // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
            //
            #region Using declarations
            using System;
            using System.ComponentModel;
            using System.Diagnostics;
            using System.Drawing;
            using System.Drawing.Drawing2D;
            using System.Xml.Serialization;
            using NinjaTrader.Cbi;
            using NinjaTrader.Data;
            using NinjaTrader.Indicator;
            using NinjaTrader.Strategy;
            #endregion
            // This namespace holds all strategies and is required. Do not change it.
            namespace NinjaTrader.Indicator
            {
            /// <summary>
            /// exponential moving average crossovers
            /// </summary>
            [Description("Simple moving average cross over strategy.")]
            public class EMACrossOver :Indicator
            {
            #region Variables
            private int fast = 5;
            private int slow = 6;
            private DataSeries fastEMA;
            private DataSeries slowEMA;
            #endregion
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
            fastEMA.Plots[0].Pen.Color = Color.Orange; //EMA(Fast)
            slowEMA.Plots[0].Pen.Color = Color.Blue;//EMA(Slow)
            // Add(new Plot(Color.Orange, "Fast")); //this didnt work either
            //Add(new Plot(Color.Blue, "Slow")); // this didnt work either
             
            Overlay = true;
            PriceTypeSupported = true;
            CalculateOnBarClose = false;
            fastEMA = new DataSeries(this);
            slowEMA= new DataSeries(this);
            }
            /// <summary>
            /// Called on each bar update event (incoming tick).
            /// </summary>
            protected override void OnBarUpdate()
            {
             
            fastEMA.Set(CurrentBar == 0 ? Close[0] : Close[0] * (2.0 / (1 + fast)) + (1 - (2.0 / (1 + fast))) * fastEMA[1]);
            slowEMA.Set(CurrentBar == 0 ? Open[0] : Open[0] * (2.0 / (1 + slow)) + (1 - (2.0 / (1 + slow))) * slowEMA[1]);
            //above 2 lines Close[0] and Open[0] read Input[0] before
             
            }
            #region Properties
            /// <summary>
            /// </summary>
            [Browsable(false)]
            [XmlIgnore()] 
            public DataSeries Fast
            {
            get { return Values[1]; }
            }
            /// <summary>
            /// </summary>
            [Browsable(false)]
            [XmlIgnore()]
            public DataSeries Slow
            {
            get { return Values[0]; }
            }
             
            // 
            // [Description("Period for fast MA")]
            // [Category("Parameters")]
            // public int Fast
            // {
            // get { return fast; }
            // set { fast = Math.Max(1, value); }
            // }
            //
            // /// <summary>
            // /// </summary>
            // [Description("Period for slow MA")]
            // [Category("Parameters")]
            // public int Slow
            // {
            // get { return slow; }
            // set { slow = Math.Max(1, value); }
            // }
            #endregion
            }
            }
            #region NinjaScript generated code. Neither change nor remove.
            // This namespace holds all indicators and is required. Do not change it.
            namespace NinjaTrader.Indicator
            {
            public partial class Indicator : IndicatorBase
            {
            private EMACrossOver[] cacheEMACrossOver = null;
            private static EMACrossOver checkEMACrossOver = new EMACrossOver();
            /// <summary>
            /// Simple moving average cross over strategy.
            /// </summary>
            /// <returns></returns>
            public EMACrossOver EMACrossOver()
            {
            return EMACrossOver(Input);
            }
            /// <summary>
            /// Simple moving average cross over strategy.
            /// </summary>
            /// <returns></returns>
            public EMACrossOver EMACrossOver(Data.IDataSeries input)
            {
            if (cacheEMACrossOver != null)
            for (int idx = 0; idx < cacheEMACrossOver.Length; idx++)
            if (cacheEMACrossOver[idx].EqualsInput(input))
            return cacheEMACrossOver[idx];
            EMACrossOver indicator = new EMACrossOver();
            indicator.BarsRequired = BarsRequired;
            indicator.CalculateOnBarClose = CalculateOnBarClose;
            indicator.Input = input;
            indicator.SetUp();
            EMACrossOver[] tmp = new EMACrossOver[cacheEMACrossOver == null ? 1 : cacheEMACrossOver.Length + 1];
            if (cacheEMACrossOver != null)
            cacheEMACrossOver.CopyTo(tmp, 0);
            tmp[tmp.Length - 1] = indicator;
            cacheEMACrossOver = tmp;
            Indicators.Add(indicator);
            return indicator;
            }
            }
            }
            // This namespace holds all market analyzer column definitions and is required. Do not change it.
            namespace NinjaTrader.MarketAnalyzer
            {
            public partial class Column : ColumnBase
            {
            /// <summary>
            /// Simple moving average cross over strategy.
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.EMACrossOver EMACrossOver()
            {
            return _indicator.EMACrossOver(Input);
            }
            /// <summary>
            /// Simple moving average cross over strategy.
            /// </summary>
            /// <returns></returns>
            public Indicator.EMACrossOver EMACrossOver(Data.IDataSeries input)
            {
            return _indicator.EMACrossOver(input);
            }
            }
            }
            // This namespace holds all strategies and is required. Do not change it.
            namespace NinjaTrader.Strategy
            {
            public partial class Strategy : StrategyBase
            {
            /// <summary>
            /// Simple moving average cross over strategy.
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.EMACrossOver EMACrossOver()
            {
            return _indicator.EMACrossOver(Input);
            }
            /// <summary>
            /// Simple moving average cross over strategy.
            /// </summary>
            /// <returns></returns>
            public Indicator.EMACrossOver EMACrossOver(Data.IDataSeries input)
            {
            if (InInitialize && input == null)
            throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
            return _indicator.EMACrossOver(input);
            }
            }
            }
            #endregion
            Last edited by simpletrades; 08-12-2009, 09:30 PM.

            Comment


              #21
              simpletrades, you have commented out 'Add Plots' section in your Initialize(), so you can't customize those later - you would also need to refer to both plots individually to change the colors as you like to...

              Code:
               
              Add(new Plot(Color.Orange, "Fast")); 
              Add(new Plot(Color.Blue, "Slow"));
               
              Plots[0].Pen.Color = Color.Orange; //EMA(Fast)
              Plots[1].Pen.Color = Color.Blue;//EMA(Slow)

              Comment


                #22
                Originally posted by NinjaTrader_Bertrand View Post
                simpletrades, you have commented out 'Add Plots' section in your Initialize(), so you can't customize those later - you would also need to refer to both plots individually to change the colors as you like to...

                Code:
                 
                Add(new Plot(Color.Orange, "Fast")); 
                Add(new Plot(Color.Blue, "Slow"));
                 
                Plots[0].Pen.Color = Color.Orange; //EMA(Fast)
                Plots[1].Pen.Color = Color.Blue;//EMA(Slow)
                I thought the pairs were mutually exclusive--one pair of orange-blue or the other.
                i'll try it. thanks.

                Comment


                  #23
                  I had an Indie Ninja provided me with an EMA crossover, that also painted the bars. Cyan or Lime if 5 ema crossed above 89 ema, or red if 5ema crossed below ema. With new version of Ninja 7 I can not find it. does anyone have the .zip indie file?? Thanks!
                  Scottiep

                  Comment


                    #24
                    Hello Scottiep,

                    I'm not familiar with this indicator and does not sound like one that is on our forums or included with NinjaTrader.

                    Can you remember the name of the indicator so that I may search for it?
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    579 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    334 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    101 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    554 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    551 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X