Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator displacement in strategy wizard

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

    Indicator displacement in strategy wizard

    In a chart you can set indicator displacement.
    Chart > indicators > parameters > visual > displacement.
    Can this be done in the strategy wizard, if so how?

    In the condition builder, the bars ago indicator parameter does not work
    in the same way as the Indicator parameter displacement on a chart (already tried).

    Does anyone know the raw code, I can use unlocked code once
    I have the bulk of the strategy done in the wizard.

    Thanks in adavance for any help.

    #2
    Obsidian, what kind of condition do you attempt to setup in the wizard?

    What cannot work in a strategy is setting up a negative displacement - it might work visually but then you obviously miss the values to fill to gap on the right hand edge to match up to the current developing candle.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hello NinjaTrader_Bertrand,

      I'm trying to program this in the wizard (see attached image)
      Both MA same value, blue MA is displaced by 2 bars on chart settings.

      I've tried +ve and -ve values in condition builder for bars ago.
      As you say its not the correct parameter really to do the same thing as on the chart example.

      Is there a way to program the attached image example in the wizard or raw code?
      Attached Files

      Comment


        #4
        Obsidian, should be doable via the wizard, as long as you don't need a 'predicted' value of the MA that would not exist in realtime of course. If you just check against the value of the MA against 2 bars ago, why would that not work?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          You mean using the bars ago parameter in the condiotion builder yes?
          I've tested on market replay with different MA values, all ok.

          Then I set both MA values the same, with the second one set to
          2 bars ago and -2 bars ago.

          Actually, looking at it now, maybe I should be using the lookback period instead?
          I'll try that now and post back.

          Cheers for replies so far BTW.

          Comment


            #6
            No, lookback period does not do what I want either, just tried it.
            When the strategy is enabled on a chart, only one MA (both same value) can be seen.

            The second one is not being displaced.
            I can't find a way to do this in the wizard (screenshot of displaced MA on chart):


            I'm starting to think it may be a problem only raw coding can solve?

            Comment


              #7
              Correct, for the visual Add() that the strategy can do - this won't work work directly from the wizard, as it would just add the indicator including it's default plots, it would not allow for a custom displacement. However for your condition setup internally in the strategy checking via a bars ago of the indicator series it would work.

              A workaround for the display would be for example - create a copy of the MA where you hard code a displacement then into it's Initialize() method -



              Than visualize the regular and displaced custom MA in your strategy.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Cheers NinjaTrader_Bertrand.

                I'll try unlocking the code and inserting:

                Code:
                //  Initialize method of a custom indicator
                protected override void Initialize()
                {
                     Add(new  Plot(Color.Orange, "SMA"));
                     Displacement = 2; // Plots the indicator value from 2 bars  ago on the current bar
                }
                That looks like the only way, bars ago in the wizard does not produce any trades in
                market replay either, so the visual lack of displacement is not the only problem.

                I'll try inserting the above code and post back.
                Thanks again for replies so far.

                Comment


                  #9
                  Originally posted by NinjaTrader_Bertrand View Post
                  However for your condition setup internally in the strategy checking via a bars ago of the indicator series it would work.
                  The wizard still doesn't work.
                  I have tried a simple MA cross, as in the condition builder image attached.
                  I then unlocked the code after compiling.
                  The bars ago and offset parameter values have not been compiled into the code by the
                  wizard.

                  Below is the raw code:
                  Code:
                  #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.Gui.Chart;
                  using NinjaTrader.Strategy;
                  #endregion
                  
                  // This namespace holds all strategies and is required. Do not change it.
                  namespace NinjaTrader.Strategy
                  {
                      /// <summary>
                      /// Enter the description of your strategy here
                      /// </summary>
                      [Description("Enter the description of your strategy here")]
                      public class MAcrossTEST : Strategy
                      {
                          #region Variables
                          // Wizard generated variables
                          // User defined variables (add any user defined variables below)
                          #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()
                          {
                              Add(EMA(18));
                              Add(EMA(18));
                              Add(EMA(18));
                              Add(EMA(18));
                              SetTrailStop("", CalculationMode.Ticks, 100, false);
                  
                              CalculateOnBarClose = true;
                          }
                  
                          /// <summary>
                          /// Called on each bar update event (incoming tick)
                          /// </summary>
                          protected override void OnBarUpdate()
                          {
                              // Condition set 1
                              if (CrossAbove(EMA(18), EMA(18), 3))
                              {
                                  EnterLong(100000, "");
                              }
                  
                              // Condition set 2
                              if (CrossBelow(EMA(18), EMA(18), 3))
                              {
                                  EnterShort(100000, "");
                              }
                          }
                  
                          #region Properties
                          #endregion
                      }
                  }
                  As you can see, only the lookback period has been compiled by the wizard.
                  I've checked this on a seperate install of Ninja, same result.
                  Unless I'm missing something is this a bug with the wizard?
                  Attached Files

                  Comment


                    #10
                    Hello Obsidian,

                    Thank you for your response.

                    This is occuring as you are using conditions that use the CrossAbove() and CrossBelow() methods. The CrossAbove() and CrossBelow() methods use their own look back period to check if the first DataSeries crosses above or below the second DataSeries within the look back period. So the barsago integer would have no effect here as you are not asking for the comparison of two points on two EMAs but rather whether an 18 period EMA crosses above or below an 18 period EMA within the last 3 bars, which will never return True as the condition is comparing two values that are always the same.

                    If you wish to compare whether the EMA(18)[0] is greater than the EMA(18)[4] then use the '>' (greater than) condition. So your code would read as the following in the NinjaScript Editor:
                    Code:
                    if (EMA(18)[0] > EMA(18)[4])
                    And the opposite for whether the EMA(18)[0] is less than the EMA(18)[4]:
                    Code:
                    if (EMA(18)[0] < EMA(18)[4])
                    For information on CrossAbove() and CrossBelow() please visit the following links:
                    Please let me know if I may be of further assistance.

                    Comment


                      #11
                      Many thanks NinjaTrader_PatrickH.
                      Makes perfect sense, I've even used close price > MA before,
                      so I should have thought of that myself.
                      Thanks again.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by algospoke, Yesterday, 06:40 PM
                      2 responses
                      19 views
                      0 likes
                      Last Post algospoke  
                      Started by ghoul, Today, 06:02 PM
                      3 responses
                      14 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by jeronymite, 04-12-2024, 04:26 PM
                      3 responses
                      45 views
                      0 likes
                      Last Post jeronymite  
                      Started by Barry Milan, Yesterday, 10:35 PM
                      7 responses
                      21 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by AttiM, 02-14-2024, 05:20 PM
                      10 responses
                      181 views
                      0 likes
                      Last Post jeronymite  
                      Working...
                      X