Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time offset ? NT8

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

    Time offset ? NT8

    Hello !
    Is there a way in NT8 to get an offset, but for time, example :

    Code:
    (Times[0][0].TimeOfDay >= HeureNews.TimeOfDay)
    On this piece of code, i put in a strategy, the hour of a news if there is one in the session, and if the timeofday is equal or greater than the time of news, i'm going to flatten the account.
    But, if i want for the condition set to trigger 2 minutes before the news, and so the value : HeureNews. Do i have the need to manually take of 2 minutes in the configuration of the value of HeureNews, so the value is two minutes before the news, or is there a way to have a time offset, like :

    Code:
    (Times[0][0].TimeOfDay >= (HeureNews.TimeOfDay - 120 * Second))
    Or something that could do the job, so i put in the value, the real time and moment of the news, but the condition is triggered two minutes the value of HeureNews ?

    Maybe by having HeureNews which is the basic value, then we take off 2 minute of this value (is it possible ?), then we do
    TimeOfDay >= (NewOutputMinus2minutes.TimeOfDay)

    Thanks ! Have a great day

    #2
    Hello,

    Thank you for the post.

    Because NinjaScript is C#, this would be a DateTime object and you are comparing TimeSpan objects which both have some nice math methods.

    There are some good examples here: https://www.dotnetperls.com/datetime

    For what you are trying to do, you could use the subtract method:

    Code:
    if(Times[0][0].TimeOfDay >= HeureNews.TimeOfDay.Subtract(TimeSpan.FromMinutes(2)))
    { }
    You could also look into using the ToTime method which converts DateTime objects to an integer which can be easier to work with: http://ninjatrader.com/support/helpG...ightsub=totime

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks !
      I have made the code with timespan seconds.

      And i have also a last question, where i could need some help

      So, for the news system, i'm using a bool to know if we have a news in the session, then a DataTime to get the time of the news
      Code:
      		[NinjaScriptProperty]
      		[Display(ResourceType = typeof(Custom.Resource), Name="News ?", Description="Si une news vas se produire dans la session", Order=4, GroupName="NinjaScriptStrategyParameters")]
      		public bool News
      		{ get; set; }
      
      		[NinjaScriptProperty]
      		[PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
      		[Display(ResourceType = typeof(Custom.Resource), Name="Heure News", Description="Si News est true, mettre l'heure de la news", Order=5, GroupName="NinjaScriptStrategyParameters")]
      		public DateTime HeureNews
      		{ get; set; }
      Is it possible, to show the second input, only if the first one is on true, to avoid for example, to put the hour of a news, but to forget to put it on true.
      So to have :
      Code:
      if News == true
      show the input HeureNews
      But, to have it on the menu, and not the ninjascript, so if i put the first input in true, in the menu, without having to launch the strategy, and the ninjascript, the second input, HeureNews, will appear and could then be modified.

      Thanks !

      Comment


        #4
        Hello,

        Yes, this is possible but does take a little bit of work.

        We have a sample that demonstrates a few different concepts, one of which is hiding properties based on a bool value: http://ninjatrader.com/support/forum...ad.php?t=97919


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks for the link !

          I have tried to adapt it to a strategy, i have look over and over the code of the script that is used to hide an input in the menu, but sadly, i cannot figure out what's wrong with the code, and the input don't get hidden, and stay if my double is true or false.
          Since i dont really know from when the problem come from, since i replicate the sample, adapt it to a strategy, and change the names of a few things, i'm simply passing you the code, and hope you can help me on this, thanks a lot !!

          Code:
          				GetPropertiesSupported						= true;
          				News										= false;
          				HeureNews									= DateTime.Parse("00:00");
          
                  #region  NewsGroup:  Show/hide properties based on secondary input
          
                  [RefreshProperties(RefreshProperties.All)] // Needed to refresh the property grid when the value changes
                  [Display (Name ="News", Description="Si une news vas se produire dans la session", Order = 1, GroupName = "NewsGroup")]
                  public bool News
                  { get; set; }
          
          		[PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
                  [Display(ResourceType = typeof(Custom.Resource), Name="Heure News", Description="Si News est true, mettre l'heure de la news", Order = 2, GroupName = "NewsGroup")]
                  public DateTime HeureNews
                  { get; set; }
          
                  #endregion
          
          	}
             		 #region NewsParametres:  Show/hide properties based on secondary input & Disable/enable properties based on secondary input
            		 public class Converteur : StrategyBaseConverter  // or IndicatorBaseConverter
              {
                  public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs)
                  {
                      // we need the indicator instance which actually exists on the grid
                      FibAutoTrailStoplongshort strategy = component as FibAutoTrailStoplongshort;
          
                      // base.GetProperties ensures we have all the properties (and associated property grid editors)
                      // NinjaTrader internal logic determines for a given indicator
                      PropertyDescriptorCollection propertyDescriptorCollection = base.GetPropertiesSupported()
                                                                                  ? base.GetProperties(attrs)
                                                                                  : TypeDescriptor.GetProperties(attrs);
          
                      if (strategy == null || propertyDescriptorCollection == null)
                          return propertyDescriptorCollection;
          
          
                      #region NewsGroup:  Show/hide properties based on secondary input
          
                      // These two values are will be shown/hidden (toggled) based on "News" bool value
                      PropertyDescriptor HeureNews = propertyDescriptorCollection["HeureNews"];
          
                      // This removes the following properties from the grid to start off with
                      propertyDescriptorCollection.Remove(HeureNews);
          				
                      // Now that We've removed the default property descriptors, we can decide if they need to be re-added
                      // If "ShowHideToggle" is set to true, re-add these values to the property collection
                      if (strategy.News)
                      {
                          propertyDescriptorCollection.Add(HeureNews);
                      }
          
                      // otherwise, nothing else to do since they were already removed
          
                      #endregion
                      return propertyDescriptorCollection;
                  }
          
                  // Important:  This must return true otherwise the type convetor will not be called
                  public override bool GetPropertiesSupported(ITypeDescriptorContext context)
                  { return true; }
              }
          			#endregion
          }
          Edit : PS : Everything compile well, but its the hiding of the input, the reason for all this code, that don't work and happen :/
          Last edited by Robinson94; 07-14-2017, 10:41 AM.

          Comment


            #6
            Hello,

            Thank you for the reply.

            Would you be able to attach the actual .cs file you are working on? I am missing some variables from what you have provided and it would be best to review the same syntax you are to see what specifically was missed.

            You can locate the file in the folder: Documents\NinjaTrader 8\bin\Custom\Strategies

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Here's the file, there is a big part about what the strategy actually do, the variables and input are at the start of the file, and part about hiding an input in the menu are at the bottom. Thanks a lot !
              PS : i'm still building the script, so there is a lot of print and sound play to do tests, and a bit of junks, but if you find anything that don't make sense, i would be glad to hear from you
              Attached Files

              Comment


                #8
                Hello,

                Thank you for providing the file.

                I will review this and reply back once I have further details.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hello,

                  I reviewed the file and do see there were some problems with the implementation.

                  For simplicity sake, I created a reduced sample of the IndicatorTypeConverter as a Strategy with only the Hidden properties part.

                  I would suggest to import and test the sample, and then do a SaveAs from the sample which could be used as a framework for your script.

                  Please take note that you need to change the Class names in this sample if you duplicate it, the new file would need to be checked to ensure all references point to the correct new file and new names.

                  I look forward to being of further assistance.
                  Attached Files
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks a lot, its working

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by bortz, 11-06-2023, 08:04 AM
                    47 responses
                    1,611 views
                    0 likes
                    Last Post aligator  
                    Started by jaybedreamin, Today, 05:56 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post jaybedreamin  
                    Started by DJ888, 04-16-2024, 06:09 PM
                    6 responses
                    19 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by Jon17, Today, 04:33 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post Jon17
                    by Jon17
                     
                    Started by Javierw.ok, Today, 04:12 PM
                    0 responses
                    22 views
                    0 likes
                    Last Post Javierw.ok  
                    Working...
                    X