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

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.
    BertrandNinjaTrader Customer Service

    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 lorem, 04-25-2024, 09:18 AM
          16 responses
          64 views
          0 likes
          Last Post lorem
          by lorem
           
          Started by doihaveto13, Today, 12:46 PM
          2 responses
          4 views
          0 likes
          Last Post doihaveto13  
          Started by Vitamite, Today, 12:48 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by owen5819, 05-11-2024, 02:24 PM
          3 responses
          21 views
          0 likes
          Last Post owen5819  
          Started by MrAdamSK, 04-02-2024, 11:25 PM
          3 responses
          41 views
          0 likes
          Last Post NinjaTrader_Zachary  
          Working...
          X