Announcement

Collapse
No announcement yet.

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

    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

        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
            
            }

            Comment


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

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Mindset, 04-21-2026, 06:46 AM
              0 responses
              88 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by M4ndoo, 04-20-2026, 05:21 PM
              0 responses
              134 views
              0 likes
              Last Post M4ndoo
              by M4ndoo
               
              Started by M4ndoo, 04-19-2026, 05:54 PM
              0 responses
              68 views
              0 likes
              Last Post M4ndoo
              by M4ndoo
               
              Started by cmoran13, 04-16-2026, 01:02 PM
              0 responses
              119 views
              0 likes
              Last Post cmoran13  
              Started by PaulMohn, 04-10-2026, 11:11 AM
              0 responses
              67 views
              0 likes
              Last Post PaulMohn  
              Working...
              X