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

how to specify displacement=1 for strategy indicators?

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

    how to specify displacement=1 for strategy indicators?

    i am trying to learn how to use the strategy analyzer. In so doing, I have written a strategy but cannot figure out how to specify displacement=1 for the strategy indicators [i.e.] do i do it when creating the strategy in the strategy builder or do i do it elsewhere?

    #2
    Hello,

    Thank you for the post.

    In this case the Visual Displacement property that can normally be used with Indicators would not be avaliable as the strategy is hosting the indicator. It is technically possible to manually code into a strategy Displacement = 1 to displace the visuals but not while using the builder.

    If you are trying to Visually displace the indicators from the builder, I will need to submit a feature request to expose the strategies Displacement property. Otherwise if you are trying to access data from 1 BarsAgo, you could use [1] instead of [0] to access the prior data.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse,
      Below is my code generated by the Strategy Builder. If I must unlock and change the code, kindly show me what changes to make.

      #region Using declarations
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.Indicators;
      using NinjaTrader.NinjaScript.DrawingTools;
      #endregion

      //This namespace holds Strategies in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Strategies
      {
      public class SampleMACrossOverStrategyJoeTest2 : Strategy
      {
      private DEMA DEMA1;
      private TEMA TEMA1;

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Dema & Tema Cross Over";
      Name = "SampleMACrossOverStrategyJoeTest2";
      Calculate = Calculate.OnEachTick;
      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.AllEntries;
      IsExitOnSessionCloseStrategy = true;
      ExitOnSessionCloseSeconds = 30;
      IsFillLimitOnTouch = false;
      MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
      OrderFillResolution = OrderFillResolution.Standard;
      Slippage = 0;
      StartBehavior = StartBehavior.WaitUntilFlat;
      TimeInForce = TimeInForce.Gtc;
      TraceOrders = false;
      RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
      StopTargetHandling = StopTargetHandling.PerEntryExecution;
      BarsRequiredToTrade = 20;
      // Disable this property for performance gains in Strategy Analyzer optimizations
      // See the Help Guide for additional information
      IsInstantiatedOnEachOptimizationIteration = true;
      DemaPeriod = 10;
      TemaPeriod = 20;
      }
      else if (State == State.Configure)
      {
      DEMA1 = DEMA(Convert.ToInt32(DemaPeriod));
      DEMA1.Plots[0].Brush = Brushes.Goldenrod;
      AddChartIndicator(DEMA1);
      TEMA1 = TEMA(Convert.ToInt32(TemaPeriod));
      TEMA1.Plots[0].Brush = Brushes.Goldenrod;
      AddChartIndicator(TEMA1);
      }
      }

      protected override void OnBarUpdate()
      {
      if (CurrentBars[0] < 1)
      return;

      // Set 1
      if (DEMA1[1] >= TEMA1[1])
      {
      EnterLong(Convert.ToInt32(DefaultQuantity), @"Entry Long");
      }
      // Set 2
      if (DEMA1[1] < TEMA1[1])
      {
      EnterShort(Convert.ToInt32(DefaultQuantity), @"Entry Short");
      }

      }

      #region Properties
      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(ResourceType = typeof(Custom.Resource), Name="DemaPeriod", Description="Signals when crosses Tema Period indicator", Order=1, GroupName="NinjaScriptStrategyParameters")]
      public int DemaPeriod
      { get; set; }

      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(ResourceType = typeof(Custom.Resource), Name="TemaPeriod", Order=2, GroupName="NinjaScriptStrategyParameters")]
      public int TemaPeriod
      { get; set; }
      #endregion

      }
      }

      Comment


        #4
        Hello,

        Thank you for the reply.

        To manually add Displacement to the script, you would need to unlock the code and then add the Displacement syntax to State.SetDefaults.

        There is an example of this property that shows where it would go in a script in the following help guide page:



        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        942 views
        0 likes
        Last Post spwizard  
        Started by Max238, Today, 01:28 AM
        0 responses
        9 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by rocketman7, Today, 01:00 AM
        0 responses
        4 views
        0 likes
        Last Post rocketman7  
        Started by wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        28 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 02-22-2024, 01:11 AM
        5 responses
        33 views
        0 likes
        Last Post wzgy0920  
        Working...
        X