• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

help me with this strategy

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

    help me with this strategy

    hello!
    i would like to create a strategy with crossabove and below the ema with indicator. Any idea? i try this but it isn't correct:
    if (CrossBelow(DMI(14),EMA(DMI, 14), 1))
    Many thank's for the assistance and have a fantastic 2015!
    Attached Files

    #2
    bergimax, thanks for the wishes - we all wish you a great 2015 as well!

    The snippet looks correct, however from your chart - the DMI is just overlaid on the price data, correct? So both are using different scales then, so you will not get a 'true' crossover a system could act on.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      thank's for the replay!
      tell me if i understand correctly. the two different indicator is overlying.the ema over the dmi. Using the Crossover it don't look the Cross exactly? if yes, can i use this?

      if(DMI[1]>=EMA(DMI, 14)[1] &&
      DMI[0]<EMA(DMI, 14)[0])
      what do you think?

      Comment


        #4
        bergimax, that should work as well. My comment was in relation to your screenshot - here it looks like you look for crossovers with the DMI and the EMA of the prices.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          ahh ok!!! i do create an apposite indicator in your opinion? and if yes i modify the dmi in what way?
          thank's

          Comment


            #6
            Would not be aware of an easy workaround, as those would not really cross - this is just a visual effect then for working on different scales. You can see what you program would see if both the price based EMA and the DMI would be set on the same scale.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              ok! i create an indicator that works with the same scale but i not find the code to insert the crosses in my startegy..

              /// <summary>
              /// Directional Movement Index. Directional Movement Index is quite similiar to Welles Wilder's Relative Strength Index. The difference is the DMI uses variable time periods (from 3 to 30) vs. the RSI's fixed periods.
              /// </summary>
              [Description("The Directional Movement Index is quite similiar to Welles Wilder's Relative Strength Index. The difference is the DMI uses variable time periods (from 3 to 30) vs. the RSI's fixed periods.")]
              public class DMIEma : Indicator
              {
              #region Variables
              private int period = 14;
              private int periodEma = 14;
              private DataSeries dmMinus;
              private DataSeries dmPlus;
              private DataSeries tr;
              #endregion
              /// <summary>
              /// This method is used to configure the indicator and is called once before any bar data is loaded.
              /// </summary>
              protected override void Initialize()
              {
              Add(new Plot(Color.Green, "DMI"));
              Add(new Plot(Color.Orange, "EMA"));
              dmMinus = new DataSeries(this);
              dmPlus = new DataSeries(this);
              tr = new DataSeries(this);
              }
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
              if (CurrentBar == 0)
              {
              dmMinus.Set(0);
              dmPlus.Set(0);
              tr.Set(High[0] - Low[0]);
              Value.Set(0);
              }
              else
              {
              dmMinus.Set(Low[1] - Low[0] > High[0] - High[1] ? Math.Max(Low[1] - Low[0], 0) : 0);
              dmPlus.Set(High[0] - High[1] > Low[1] - Low[0] ? Math.Max(High[0] - High[1], 0) : 0);
              tr.Set(Math.Max(High[0] - Low[0], Math.Max(Math.Abs(High[0] - Close[1]), Math.Abs(Low[0] - Close[1]))));
              double diPlus = (SMA(tr, Period)[0] == 0) ? 0 : SMA(dmPlus, Period)[0] / SMA(tr, Period)[0];
              double diMinus = (SMA(tr, Period)[0] == 0) ? 0 : SMA(dmMinus, Period)[0] / SMA(tr, Period)[0];
              Value.Set((diPlus + diMinus == 0) ? 0 : (diPlus - diMinus) / (diPlus + diMinus));
              Values[1].Set(EMA(Value, PeriodEma)[0]);
              }
              }
              #region Properties
              /// <summary>
              /// </summary>
              [Description("Numbers of bars used for calculations")]
              [GridCategory("Parameters")]
              public int Period
              {
              get { return period; }
              set { period = Math.Max(1, value); }
              }

              [Description("Numbers of bars used for calculations")]
              [GridCategory("Parameters")]
              public int PeriodEma
              {
              get { return periodEma; }
              set { periodEma = 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 DMIEma[] cacheDMIEma = null;
              private static DMIEma checkDMIEma = new DMIEma();
              /// <summary>
              /// The Directional Movement Index is quite similiar to Welles Wilder's Relative Strength Index. The difference is the DMI uses variable time periods (from 3 to 30) vs. the RSI's fixed periods.
              /// </summary>
              /// <returns></returns>
              public DMIEma DMIEma(int period, int periodEma)
              {
              return DMIEma(Input, period, periodEma);
              }
              /// <summary>
              /// The Directional Movement Index is quite similiar to Welles Wilder's Relative Strength Index. The difference is the DMI uses variable time periods (from 3 to 30) vs. the RSI's fixed periods.
              /// </summary>
              /// <returns></returns>
              public DMIEma DMIEma(Data.IDataSeries input, int period, int periodEma)
              {
              if (cacheDMIEma != null)
              for (int idx = 0; idx < cacheDMIEma.Length; idx++)
              if (cacheDMIEma[idx].Period == period && cacheDMIEma[idx].PeriodEma == periodEma && cacheDMIEma[idx].EqualsInput(input))
              return cacheDMIEma[idx];
              lock (checkDMIEma)
              {
              checkDMIEma.Period = period;
              period = checkDMIEma.Period;
              checkDMIEma.PeriodEma = periodEma;
              periodEma = checkDMIEma.PeriodEma;
              if (cacheDMIEma != null)
              for (int idx = 0; idx < cacheDMIEma.Length; idx++)
              if (cacheDMIEma[idx].Period == period && cacheDMIEma[idx].PeriodEma == periodEma && cacheDMIEma[idx].EqualsInput(input))
              return cacheDMIEma[idx];
              DMIEma indicator = new DMIEma();
              indicator.BarsRequired = BarsRequired;
              indicator.CalculateOnBarClose = CalculateOnBarClose;
              #if NT7
              indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
              indicator.MaximumBarsLookBack = MaximumBarsLookBack;
              #endif
              indicator.Input = input;
              indicator.Period = period;
              indicator.PeriodEma = periodEma;
              Indicators.Add(indicator);
              indicator.SetUp();
              DMIEma[] tmp = new DMIEma[cacheDMIEma == null ? 1 : cacheDMIEma.Length + 1];
              if (cacheDMIEma != null)
              cacheDMIEma.CopyTo(tmp, 0);
              tmp[tmp.Length - 1] = indicator;
              cacheDMIEma = tmp;
              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>
              /// The Directional Movement Index is quite similiar to Welles Wilder's Relative Strength Index. The difference is the DMI uses variable time periods (from 3 to 30) vs. the RSI's fixed periods.
              /// </summary>
              /// <returns></returns>
              [Gui.Design.WizardCondition("Indicator")]
              public Indicator.DMIEma DMIEma(int period, int periodEma)
              {
              return _indicator.DMIEma(Input, period, periodEma);
              }
              /// <summary>
              /// The Directional Movement Index is quite similiar to Welles Wilder's Relative Strength Index. The difference is the DMI uses variable time periods (from 3 to 30) vs. the RSI's fixed periods.
              /// </summary>
              /// <returns></returns>
              public Indicator.DMIEma DMIEma(Data.IDataSeries input, int period, int periodEma)
              {
              return _indicator.DMIEma(input, period, periodEma);
              }
              }
              }
              // This namespace holds all strategies and is required. Do not change it.
              namespace NinjaTrader.Strategy
              {
              public partial class Strategy : StrategyBase
              {
              /// <summary>
              /// The Directional Movement Index is quite similiar to Welles Wilder's Relative Strength Index. The difference is the DMI uses variable time periods (from 3 to 30) vs. the RSI's fixed periods.
              /// </summary>
              /// <returns></returns>
              [Gui.Design.WizardCondition("Indicator")]
              public Indicator.DMIEma DMIEma(int period, int periodEma)
              {
              return _indicator.DMIEma(Input, period, periodEma);
              }
              /// <summary>
              /// The Directional Movement Index is quite similiar to Welles Wilder's Relative Strength Index. The difference is the DMI uses variable time periods (from 3 to 30) vs. the RSI's fixed periods.
              /// </summary>
              /// <returns></returns>
              public Indicator.DMIEma DMIEma(Data.IDataSeries input, int period, int periodEma)
              {
              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.DMIEma(input, period, periodEma);
              }
              }
              }
              #endregion

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by timcjpfx, Today, 03:52 AM
              0 responses
              1 view
              0 likes
              Last Post timcjpfx  
              Started by tonynt, Today, 01:42 AM
              0 responses
              7 views
              0 likes
              Last Post tonynt
              by tonynt
               
              Started by NT-Roland, Yesterday, 04:36 PM
              0 responses
              3 views
              0 likes
              Last Post NT-Roland  
              Started by Newtrader101, Yesterday, 03:40 PM
              2 responses
              14 views
              0 likes
              Last Post Newtrader101  
              Started by Branpo, Yesterday, 02:58 PM
              2 responses
              15 views
              0 likes
              Last Post Branpo
              by Branpo
               
              Working...
              X