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

Compiled NT 8 strategy not available in strategy list

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

    Compiled NT 8 strategy not available in strategy list

    Hi,
    I put together a NT 8 strategy and compiled it with no errors (some warnings). When trying to add the strategy to simulate it is not listed as available. Only the default NT 8 system strategies are available (the @ ones). I restarted NT 8 and recompiled the strategy with no luck. Any help will be appreciated.

    Here are few lines at the start of the strategy:

    #region Using declarations
    using System;
    using System.Collections.Generic;// this allows using List
    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;
    using System.Collections; // this allows using ArrayList
    #endregion
    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class HZMES01 : Strategy
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "HZMES01";
    Calculate = Calculate.OnPriceChange;
    EntriesPerDirection = 3;
    EntryHandling = EntryHandling.UniqueEntries;
    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;
    }
    else if (State == State.Configure)
    {
    AddDataSeries("ES 12-16", Data.BarsPeriodType.Volume, 10000, Data.MarketDataType.Last);
    }
    }
    Last edited by hgheith; 10-09-2016, 05:03 PM.

    #2
    Originally posted by hgheith View Post
    ,

    Code:
    public class HZMES01 : Strategy
    {
     
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "HZMES01";
    }
    Is the filename also: HZMES01 ?

    Comment


      #3
      Thank You Sledge.
      Yes, the file name is HZMES01.cs and is placed at Documents\NinjaTrader 8\bin\Custom\Strategies\

      Comment


        #4
        Originally posted by hgheith View Post
        Thank You Sledge.
        Yes, the file name is HZMES01.cs and is placed at Documents\NinjaTrader 8\bin\Custom\Strategies\
        It worked here for me:

        http://screencast.com/t/3sC63K6ivV


        I did new Ninjascript - Generated code, removed all the code except for the generic OnBarUpdate, and pasted your code in, did right click -> save as, put in your file name.

        Had some issues with "MyCustomStrategy" having the same name in the space of HZMES01. So I changed that the HZMES02 and everything compiled.

        Went into the chart->strategies, and HZMES01 was available.

        Are there any other steps you are doing? Did you create this in the editor? With the strategy builder?

        Comment


          #5
          Thank You Sledge. I started from the strategy editor. I followed your steps and the strategy became available. I tested all additions I thought to add and now realize that the problem was related to a list definition I added under the State defaults. I moved it to under the State.Configure and the strategy is now available.

          if(State == State.SetDefaults)
          {
          ...
          }
          else if (State == State.Configure)
          {
          foreach(string x in instNameArr)
          {
          AddDataSeries(x, BarsPeriodType.Volume, instVol);
          }
          ...

          Comment


            #6
            I barely remember some issue with AddDataSeries in State.SetDefault .... or suffering bad case of Déjà vu. I spent 30 minute searching and can't find previous post.

            Comment


              #7
              Hello hgheith,

              Thank you for your post.

              In the screenshot you sent us over here at Platform Support you had AddDataSeries in SetDefaults which would result in the error I sent you via email.
              Strategy 'HZMES01': Error on calling 'OnStateChange' method: 'AddDataSeries' cannot be called from this state. Please see the Help Guide article on 'AddDataSeries' for more information.
              I see you edited your post here and the AddDataSeries() is not in the SetDefaults State. Are you still seeing this issue with AddDataSeries in the Configure State?

              Comment


                #8
                Thank You for you follow up.
                Yes, placing the AddDataSeries under State.Configure fixed reading the list.

                Another related question is the difference between "if" vs "else if" (State== State.Configure). Not sure it has an impact, but this is in relation to another error I am still receiving when accessing EMA(xx)[y] for any y except 0.

                Here is the code:
                if (State == State.Configure)
                {
                foreach(string x in instNameArr)
                {
                AddDataSeries(x, BarsPeriodType.Volume, instVol);
                }
                EMA(21);
                EMA(100);
                }

                protected override void OnBarUpdate()
                {
                Print("we are here 1");
                Print("Times[instID][0] = " + Times[instID][0]);
                Print("EMA(21)[0] = " + EMA(21)[0]);
                Print("EMA(100)[0] = " + EMA(100)[0]);
                Print("EMA(21)[1] = " + EMA(21)[1]);
                Print("EMA(100)[1] = " + EMA(100)[1]);

                The result is:
                we are here 1
                Times[instID][0] = 3/19/2015 2:38:09 PM
                EMA(21)[0] = 2080
                EMA(100)[0] = 2080
                Strategy 'HZMES02': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
                Disabling NinjaScript strategy 'HZMES02/87522429'

                So it seems EMA series is not added?

                Thank You
                Last edited by hgheith; 10-10-2016, 08:42 PM.

                Comment


                  #9
                  Originally posted by hgheith View Post
                  Strategy 'HZMES02': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
                  Disabling NinjaScript strategy 'HZMES02/87522429'

                  So it seems EMA series is not added?
                  CurrentBar check needed.

                  http://ninjatrader.com/support/forum...ad.php?t=56884

                  http://ninjatrader.com/support/forum...arupdate+index

                  Comment


                    #10
                    Thank You Sledge. Adding CurrentBar check solved the problem.
                    I would like to note this was not needed when I was running the script in NT 7.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by jasinhbca, Today, 01:20 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post jasinhbca  
                    Started by jhjhawkins, Today, 12:25 PM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_Kate  
                    Started by rexsole, Today, 11:48 AM
                    1 response
                    15 views
                    0 likes
                    Last Post NinjaTrader_PatrickG  
                    Started by jeronymite, Yesterday, 05:05 PM
                    3 responses
                    54 views
                    0 likes
                    Last Post NinjaTrader_ChristopherJ  
                    Started by Don22Trader1, Yesterday, 05:54 PM
                    3 responses
                    50 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X