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

Restriction/prohibition on some conditions in strategy

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

    Restriction/prohibition on some conditions in strategy

    Hello. For example, there is strategy with lots of conditions. To check what conditions work fine, what not, I'd like to add some restrictions/prohibitions. Can I do it in Initialize()?
    For example, I 'd like to check strategy performance with and without targetOrder (profit taking via limit order). So, can I set
    Code:
    Initialize()
    targetOrder = null;
    or something like this?
    What you can advice to have opportunity to manipulate some conditions without "Comment"/"Uncomment selection" manually?

    #2
    Hi alexstox,

    I'm not quite certain about the targetOrder = null;. If your strategy has code like if (targetOrder != null) { // execute code } this may prevent that condition from executing if you set this to null in Initialize().

    However, it seems that you would like groups of conditions to not trigger. I would recommend that you use a variable for this and add a check for the variable to each conditional you are trying to control.

    For example:
    In #region Variables:
    private bool evaluateAll = false; (<- I had to correct that line. Added private bool to the beginning)

    In the conditions:
    if (evaluateAll == true && Close[0] > Close[1])
    {
    // execute code
    }

    Set the variable to true when you would like the conditions to evaluate and false when you don't.
    Last edited by NinjaTrader_ChelseaB; 12-26-2013, 03:59 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by alexstox View Post
      Hello. For example, there is strategy with lots of conditions. To check what conditions work fine, what not, I'd like to add some restrictions/prohibitions. Can I do it in Initialize()?
      For example, I 'd like to check strategy performance with and without targetOrder (profit taking via limit order). So, can I set
      Code:
      Initialize()
      targetOrder = null;
      or something like this?
      What you can advice to have opportunity to manipulate some conditions without "Comment"/"Uncomment selection" manually?
      Use a boolean parameter, and only call the Set() statements if the boolean variable is true.

      Comment


        #4
        Where can I read more about Set()?

        Comment


          #5
          Hi alexstox,

          .Set() is method that is available to data series. You can read about this in the help guide link below.
          http://www.ninjatrader.com/support/h...ries_class.htm
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Please provide any example how Set() can be useful in my question?

            Comment


              #7
              Originally posted by alexstox View Post
              Please provide any example how Set() can be useful in my question?
              How did you intend to use your targetOrder?

              Comment


                #8
                Hello alexstox,

                Lets say that I am creating a custom data series that will hold the difference between the high and the low so that you can check back on these values.
                This will be similar to looking back at past Close values.

                First you can create a custom data series.

                In #region Variables:
                private DataSeries myDataSeries;

                In the Initialize() method:
                myDataSeries = new DataSeries(this, MaximumBarsLookBack.Infinite);

                Now that the data series has been initialized you can set a value for this in OnBarUpdate
                myDataSeries.Set(High[0]-Low[0]);

                Then to call the data back a bar later, use myDataSeries[1]. (myDataSeries[barsAgoValue])


                Plots on a chart are created from a dataseries. NinjaTrader will handle the creation of this for you.

                To add a plot in Initialize() write:
                Add(new Plot(Color.Orange, "myPlot"));

                This will create a Value variable that you can use to set the plot value.
                Value.Set(High[0]);

                This code will plot connecting the high of the bars.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Well, there is strategy, that is full of conditions: filters, enters, drawn objects etc. Sometimes it's hard to "Comment/Uncomment" selection to turn off some rules/conditions, because they are in different places. Even with not big script of 2000 rows of code. Especially when you changed something and want to redo/undo changes.
                  So, in this case it would be great to have opportunity to manage some conditions without boolean if() before every condition.
                  Is there some abilities in NT script? Maybe some restrictions in Initialize()? Or it's only via switch

                  Code:
                  switch (expression)
                  {  case value1:
                        break;
                    case value2:
                        break;
                     default:
                        break;
                  }

                  Comment


                    #10
                    Originally posted by alexstox View Post
                    Well, there is strategy, that is full of conditions: filters, enters, drawn objects etc. Sometimes it's hard to "Comment/Uncomment" selection to turn off some rules/conditions, because they are in different places. Even with not big script of 2000 rows of code. Especially when you changed something and want to redo/undo changes.
                    So, in this case it would be great to have opportunity to manage some conditions without boolean if() before every condition.
                    Is there some abilities in NT script? Maybe some restrictions in Initialize()? Or it's only via switch

                    Code:
                    switch (expression)
                    {  case value1:
                          break;
                      case value2:
                          break;
                       default:
                          break;
                    }
                    A switch statement with an enum is one possibility, yes.

                    Comment


                      #11
                      Hello alexstox,

                      The switch is almost like an if statement that compares only one variable to a series of values.

                      It may be possible to have your code use this switch, but I can only imagine this working if you have altered versions (duplicate code sections) of the completed code in each case of the switch.

                      It may work for what you want, but I think its going to require some restructuring of your code.
                      Chelsea B.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Segwin, 05-07-2018, 02:15 PM
                      14 responses
                      1,788 views
                      0 likes
                      Last Post aligator  
                      Started by Jimmyk, 01-26-2018, 05:19 AM
                      6 responses
                      837 views
                      0 likes
                      Last Post emuns
                      by emuns
                       
                      Started by jxs_xrj, 01-12-2020, 09:49 AM
                      6 responses
                      3,292 views
                      1 like
                      Last Post jgualdronc  
                      Started by Touch-Ups, Today, 10:36 AM
                      0 responses
                      12 views
                      0 likes
                      Last Post Touch-Ups  
                      Started by geddyisodin, 04-25-2024, 05:20 AM
                      11 responses
                      62 views
                      0 likes
                      Last Post halgo_boulder  
                      Working...
                      X