• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Return Time Since Entry

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

    Return Time Since Entry

    PaulH - From customer service created a simple indicator that returns the time it took to create a range bar.

    https://ninjatrader.com/support/foru...e-of-range-bar

    What would be the best way to modify this to return the time since a position was entered?

    I have a strategy set to take multiple entries but need to limit excessive trading. I would like to only enter a new trade if more than 30 minutes has passed.

    I am using range candles otherwise I would just use Bars Since Entry. I thought I would create an indicator that I could reference in the strategy builder.

    Any advice would be appreciated.

    Stefan

    #2
    Hello sdauteuil,

    Thanks for your post.

    You would not be able to accomplish your goal in the strategy builder due to the limitations of the strategy builder. There no means to work beyond the simple time checks allowed in the strategy builder.

    What I would suggest would be to Unlock the strategy coding and then work directly in Ninjascript. You can set a bool variable when you are in a position and then when you are flat and the bool is true, you can save the time in a time variable. You can then reset that bool when 30 minute have passed. The bool state would be used as part of the entry conditions.

    Alternately, (and easier) if you add a secondary 1 minute time series you can directly count the number of 1 minute bars since the exit (when you went flat.).

    If you would like this created for you, we can provide references to 3rd party Ninjascript service providers.



    Paul H.NinjaTrader Customer Service

    Comment


      #3
      I would like to learn to be able to do this myself. I have been trading a long time but am new to programming automated strategies. With other strategies I have been able to create most of the code using the strategy builder and then do some simple modifications.

      That being said I had the same 2 ideas to achieve this. I think referencing a 1 minute bar would be the easiest.

      I have 2 questions I will put below in separate posts.

      Comment


        #4
        I added the 1 minute data series
        AddDataSeries(Data.BarsPeriodType.Minute, 1);

        I added the BarsSinceEntryExecution statement in the entry condition section. This works fine referencing the primary range bar series. A trade is taken if there has been no prior entries or it has be at least 30 bars since the first entry/

        // condition group 1
        && ((BarsSinceEntryExecution(0, @"Long Entry", 0) == -1)
        || (BarsSinceEntryExecution(0, @"Long Entry", 0) > 30)))

        How would I modify the BarsSinceEntryExecution code to reference the minute bar as the entry instead of the range bar?


        Comment


          #5
          Using another method I would save the entry time as a variable when the entry conditions were met and on the next entry filter the current time to > 30 minutes.
          I am not sure what “type” to define the variable as.
          I have 2 snippets of code I picked up from the forum. Is DateTime a “type” – like a string or double?
          One sample has a question mark after the DateTime not sure what the purpose of that is.

          Basically what would be the best method to save the EntryTime as a variable

          //define variable to hold entry execution time
          private DateTime? EntryTime;
          //action when entry conditions met
          EnterLong();
          EntryTime = Time[0];


          //define variable to hold entry execution time
          private DateTime EntryTime;
          //action when entry conditions met
          EnterLong();
          EntryTime = DateTime.Entry;

          Comment


            #6
            Hello Stefan,

            Thanks for your reply.

            Originally posted by sdauteuil View Post
            I added the 1 minute data series
            AddDataSeries(Data.BarsPeriodType.Minute, 1);

            I added the BarsSinceEntryExecution statement in the entry condition section. This works fine referencing the primary range bar series. A trade is taken if there has been no prior entries or it has be at least 30 bars since the first entry/

            // condition group 1
            && ((BarsSinceEntryExecution(0, @"Long Entry", 0) == -1)
            || (BarsSinceEntryExecution(0, @"Long Entry", 0) > 30)))

            How would I modify the BarsSinceEntryExecution code to reference the minute bar as the entry instead of the range bar?
            The only way that method (BarsSinceExitExecution or BarsSinceEntryExecution) would work would be if you submitted the orders on the 1 minute bars, if that were done then all you would do is change the methods barsInProgressIndex from 0 to 1 (1 being the added data series).
            References:
            https://ninjatrader.com/support/help...yexecution.htm
            https://ninjatrader.com/support/help...texecution.htm



            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hello Stefan,

              Thanks for your reply.

              Originally posted by sdauteuil View Post
              Using another method I would save the entry time as a variable when the entry conditions were met and on the next entry filter the current time to > 30 minutes.
              I am not sure what “type” to define the variable as.
              I have 2 snippets of code I picked up from the forum. Is DateTime a “type” – like a string or double?
              One sample has a question mark after the DateTime not sure what the purpose of that is.

              Basically what would be the best method to save the EntryTime as a variable

              //define variable to hold entry execution time
              private DateTime? EntryTime;
              //action when entry conditions met
              EnterLong();
              EntryTime = Time[0];


              //define variable to hold entry execution time
              private DateTime EntryTime;
              //action when entry conditions met
              EnterLong();
              EntryTime = DateTime.Entry;
              What I would suggest is something simpler. Just count the number of 1 minute bars. When you place the order, save the CurrentBars[1] (the [1] is the bar counter for the 1 minute added series) into an int variable (for example savedBar = CurrentBars[1]; //save current 1 minute bar number) then you can set the condition if (CurrentBars[1] - savedBar >=30) .

              In terms of manipulating date and time objects, please see our example indicator (which contains comments to explain the code): https://ninjatrader.com/support/help...me_objects.htm

              Paul H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by ct_fx, Today, 05:14 AM
              0 responses
              5 views
              0 likes
              Last Post ct_fx
              by ct_fx
               
              Started by Beauregard, Today, 04:36 AM
              0 responses
              5 views
              0 likes
              Last Post Beauregard  
              Started by fx.practic, Today, 04:34 AM
              0 responses
              6 views
              0 likes
              Last Post fx.practic  
              Started by thomaspartyof10, Today, 02:33 AM
              0 responses
              9 views
              0 likes
              Last Post thomaspartyof10  
              Started by ArmKnuckle, Today, 01:59 AM
              0 responses
              13 views
              0 likes
              Last Post ArmKnuckle  
              Working...
              X