Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding time to time

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

    Adding time to time

    Hi all,

    I am currently trying to add time to time. For the purpose of not trading the first cross below but, waiting for a period of time and trading the second cross belowr if it takes place a certain time after the first cross below.

    I have been trying to utilise the code from

    but have not been able to get the code to work as yet.

    I was just wondering if someone would be able to offer any thoughts as to the mistake that is being made.

    The number 1000 was used to try and add 10 minutes to the time integer.

    Many thanks in advance for any help
    4blue

    PHP Code:
            #region Variables
    
            int TimeOfFirstCrossOver;
            int TimeOfAllowedCrossOver;
            int TimeOfAllowedCrossOverTwo;
    
            #endregion
    
            protected override void OnBarUpdate()
    
                TimeOfAllowedCrossOver = TimeOfFirstCrossOver + 1000;
                if (TimeOfAllowedCrossOver % 10000 > 5959)
                {
                    TimeOfAllowedCrossOverTwo = 10000*Math.Round(((TimeOfAllowedCrossOver)/10000),0);
                }
    
                // Condition set 1
                if (set of conditions == true)
                {
                    TimeOfFirstCrossOver = ToTime(Time[0]);           
                }
    
                // Condition set 2
                if (set of conditions == true
                    && ToTime(Time[0]) >= TimeOfFirstCrossOver)
                {
                    EnterLong(DefaultQuantity, "long 1");
                } 
    

    #2
    4blue, you would need to print the used int time variables to doublecheck they return what you would expect based on your manipulatations, you could of course also add a visual drawing action to cross check this directly on the chart to verify it triggers as you think.

    Comment


      #3
      hi Bertrand,

      the strategy did work prior to trying to implement the time component but will not compile with the code that i tried to implement for the time frame calculation.

      The two errors that come up are

      Strategy\ACross.cs The call is ambiguous between the following methods or properties: 'System.Math.Round(double, int)' and 'System.Math.Round(decimal, int)' CS0121 - click for info 69 39

      Strategy\ACross.cs Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?) CS0266 - click for info 69 33

      Iam not sure what the coding error is to first get the strategy to compile.

      many thanks
      4blue

      Comment


        #4
        4blue, have you seen the reference sample titled manipulating DateTime objects? It could help you out by working directly with the DateTime objects. For example, in your code, what would happen if you add ten minutes by adding 1000 to the time of 115900? You'd get 116900 which is definitely not a real time.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Thank you both,

          I have worked a quick solution that would work for adding anything less than 1 hour to the time (see below) but will have a look through the link you pointed out Austin.

          This works under the assumption that when an integer, for example 105900, is divided by 10000 the int returned is 10 (rounded down) and never rounded up to 11.


          PHP Code:
                      VariableOne = TimeOfFirstCrossBelow + 500;
                      if (TimeOfAllowedCrossOver % 10000 > 5959)
                      {
                          VariableTwo = (((VariableOne/10000)+1)*10000) + ((VariableOne - ((VariableOne/10000)*10000))-6000);
                      }
          
          TimeOfAllowedCrossBelow = (VariableOne > VariableTwo ? VariableOne : VariableTwo); 
          
          A little convoluted but simple and seems to stand up to what i need it for.
          Last edited by 4blue; 01-17-2010, 02:13 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          558 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X