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 NullPointStrategies, Today, 05:17 AM
              0 responses
              52 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              130 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              70 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              43 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              47 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X