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

Changing Inputs Between Dates

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

    Changing Inputs Between Dates

    Hello NT,

    I would like to change multiple inputs between certain dates. I was not able to do this with Strategy Builder. I tried the following code after OnBarUpdate() but got an error saying "Only assignment, call increment, decrement, and new object expressions can be used in a statement":

    Code:
     if ((Times[0][0].Date >= new DateTime(2012, 1, 1))
    && (Times[0][0].Date <= new DateTime(2014, 1, 1)))
    {
    Trendlength == 10;
    }
    What is the proper way to change inputs between date ranges?

    Thanks,
    Ben

    #2
    Hi Ben, thanks for writing in.

    You should use the DateTime.Compare method to make comparisons between datetime objects:

    https://docs.microsoft.com/en-us/dot...e?view=net-5.0 (publicly available)

    There is also a time filter example in the builder here:


    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris,

      I used the Strategy Builder to create the first two lines of the code to establish the date conditions. I think that part works OK as I did not get any error messages. The problem is the input value "Trendlength" is not changing during those two dates when I run the strategy. I think the issue is I don't know how to establish a revised input value as the code works it way through the data. Maybe I should be using a variable? Should it read "Trendlength = 10" instead of "Trendlength ==10"? Is it in the wrong location?

      Thanks,
      Ben

      Comment


        #4
        Hi harr5754,

        Sorry for not seeing that earlier, Trendlength == 10; is checking for equality, use Trandlength = 10; to assign the variable to 10.

        Kind regards
        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Thanks Chris,

          That took care of the error message I mentioned in my first post. Now I'm getting an error message that says, "The name 'Trendlength' does not exist in the current context". What do I need to do to provide the proper context?

          Thanks,
          Ben

          Comment


            #6
            Hi Ben,

            This means the Trendlength variable is not within the scope of the place you are using it or it is not defined. Do you have an integer variable called "Trendlength" defined within the Strategy class? e.g.

            Code:
            public class MyCustomStrategy: Strategy
            {
                private int Trendlength;
            
               //rest of the code. OnStateChange, OnBarUpdate, etc
            
            }
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Hey Chris, please disregard last query.
              Thanks
              Ben

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Jon17, Today, 04:33 PM
              0 responses
              1 view
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              4 views
              0 likes
              Last Post Javierw.ok  
              Started by timmbbo, Today, 08:59 AM
              2 responses
              10 views
              0 likes
              Last Post bltdavid  
              Started by alifarahani, Today, 09:40 AM
              6 responses
              41 views
              0 likes
              Last Post alifarahani  
              Started by Waxavi, Today, 02:10 AM
              1 response
              20 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Working...
              X