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

Hard code instrument to trade

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

    Hard code instrument to trade

    Hi,
    I am modifying my code to trade a fixed instrument which will be hard coded in the script. I am doing this so I can share the script and it would become useless with contract rollover.
    The strategy works with ninzaRenko bars, but when I start to AddDataSeriesType, I do not have in the list the ninzarenko option.
    How can I add the data series so I can be able to hard code it? The instrument to be hard coded is MNQ 03-24


    Appreciate the help!

    #2
    Try doing this search.

    Which reveals this thread,
    How do I change the minute entry in a strategy to a ninZaRenko entry 10-4 his is a piece of code that needs to be modified. else if (State == State.Configure) { AddDataSeries(Data.BarsPeriodType.Minute, 1); } Because in the stratgey builder you can not choose ninZaRenko and you want to apply a second check before boarding


    Comment


      #3
      Thanks bltdavid! very helpful.

      How about locking the instrument to trade? Would you know/]have references for this?

      Comment


        #4
        Hello carlosgutierrez,

        By using the instrument name in the AddDataSeries() call, BarsInProgress 1 will always be that instrument.
        When using 1 as the barsInProgressIndex parameter to the order method, that order will always be submitted to that series instrument.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,
          I currently have :::
          protected override void OnBarUpdate()
          {
          if (BarsInProgress != 0)
          return;

          if (CurrentBars[0] < 1)
          return;​

          Should it be :::


          protected override void OnBarUpdate()
          {
          if (BarsInProgress == 1)
          return;


          if (CurrentBars[0] < 1)
          return;​

          ????

          Comment


            #6
            Hi Chelsea,
            I currently have :::
            protected override void OnBarUpdate()
            {
            if (BarsInProgress != 0)
            return;

            if (CurrentBars[0] &lt; 1)
            return;​

            Should it be :::


            protected override void OnBarUpdate()
            {
            if (BarsInProgress == 1)
            return;


            if (CurrentBars[0] &lt; 1)
            return;​

            ????

            Comment


              #7
              Hello carlosgutierrez,

              I am referring to the barsInProgressIndex supplied to the order method, which sets the series the order is placed to.

              EnterLong(int barsInProgressIndex, int quantity, string signalName)
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Changed it and does not seem to block the instruement, this is part of the code:

                protected override void OnStateChange()
                {
                if (State == State.SetDefaults)​

                if (State == State.Configure)
                {
                AddDataSeries(new BarsPeriod()
                {
                BarsPeriodType = (BarsPeriodType)12345,
                Value = 50,
                Value2 = 1
                }
                );

                AddDataSeries("MNQ 03-24");
                }



                protected override void OnBarUpdate()
                {
                if (BarsInProgress != 0)
                return;

                if (CurrentBars[0] < 1)
                return;​

                // Set 1- in this set we get the conditions for getting into a long trade. and set the trailing stop loss for the runner position.
                if (Close[0] >= Open[0])

                {

                EnterLong(1, Convert.ToInt32(ScalpingPosition), @"Long1");

                }




                Comment


                  #9
                  Hello carlosgutierrez,

                  You have called AddDataSeries() twice. This means the MNQ 03-24 series will be barsInProgressIndex 2.

                  EnterLong(2, Convert.ToInt32(ScalpingPosition), @"Long1");
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    as always, amazing support

                    Thanks!

                    Comment


                      #11
                      Final question,
                      How can I disable the properties to uneditable by the user in the parameter window?

                      to have the row look like this and not make it possible to change it.
                      Click image for larger version

Name:	image.png
Views:	30
Size:	5.2 KB
ID:	1290513


                      Also, I would like to remove some options from the parameter window. How can I remove them from it with out breaking it?

                      Currently I am trying the following

                      */
                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Period", Order=1, GroupName="Settings")]
                      public int Period
                      { get; set; }

                      [NinjaScriptProperty]
                      [Range(0, double.MaxValue)]
                      [Display(Name="Multiplier", Order=2, GroupName="Settings")]
                      public double Multiplier
                      { get; set; }

                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Smooth", Order=3, GroupName="Settings")]
                      public int Smooth
                      { get; set; }​


                      */


                      And get the following:

                      Click image for larger version

Name:	image.png
Views:	26
Size:	29.5 KB
ID:	1290514

                      Comment


                        #12
                        To comment those lines out, you should use the
                        two character string '//' in front of each line.

                        After you comment them out, you'll need to
                        stop using those properties completely in
                        your code (that's where those error msgs
                        are probably coming from) because those
                        properties no longer exist, because, duh,
                        you've commented them out.

                        -=o=-

                        If you still want to use the properties, but just
                        want to prevent the user from changing the
                        value, that's possible, too.

                        To do that, you need to make those properties
                        readonly -- which means they remain visible
                        in the property grid, but any changes to the
                        values by the user are ignored by your
                        NinjaScript object. 'Readonly' is kinda like
                        making the property 'greyed-out' in the grid.

                        To do this, you'll need to do two things.

                        1. Remove the [NinjaScriptProperty]
                        from each of the 3 properties.

                        2. Change the { get; set; } for each of
                        those 3 properties to a private set, like this,
                        { get; private set; }

                        -=o=-

                        Note that:
                        [NinjaScriptProperty] and private set
                        are mutually exclusive, because of the magic auto
                        generated code at the bottom of the indicator.

                        But, since this is a Strategy object, and strategies
                        do not have auto generated code, you might be able
                        to use them together in a strategy. That is, you may
                        not have to remove (or comment out) the
                        [NinjaScriptProperty] line.

                        I'm not sure what the optimization mode in Strategy
                        Analyzer will do, it has to be able to set the property
                        value to optimize it, so you'll have to check that yourself.
                        (I suspect private set variables will be greyed-out in
                        the Strategy Analyzer optimization mode.)

                        -=o=-

                        More information on readonly properties is here.

                        (Btw, if that link doesn't work for you, then try Firefox.
                        It is valid and created correctly -- Chrome & Edge
                        sometimes have problems with NT forum links, but
                        I've never seen FireFox fail.)

                        Last edited by bltdavid; 02-08-2024, 08:09 PM.

                        Comment


                          #13
                          Originally posted by carlosgutierrez View Post
                          Also, I would like to remove some options from the parameter window. How can I remove them from it with out breaking it?
                          That's a little more complicated.

                          Try this search.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by rhyminkevin, Today, 04:58 PM
                          3 responses
                          48 views
                          0 likes
                          Last Post Anfedport  
                          Started by iceman2018, Today, 05:07 PM
                          0 responses
                          5 views
                          0 likes
                          Last Post iceman2018  
                          Started by lightsun47, Today, 03:51 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post lightsun47  
                          Started by 00nevest, Today, 02:27 PM
                          1 response
                          14 views
                          0 likes
                          Last Post 00nevest  
                          Started by futtrader, 04-21-2024, 01:50 AM
                          4 responses
                          50 views
                          0 likes
                          Last Post futtrader  
                          Working...
                          X