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

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.

    Does anybody know of an indicator that calculates the total time it takes a range bar to complete. I would like to use it as a volatility indicator - the


    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:





            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 DJ888, 04-16-2024, 06:09 PM
              6 responses
              18 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by Jon17, Today, 04:33 PM
              0 responses
              1 view
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              6 views
              0 likes
              Last Post Javierw.ok  
              Started by timmbbo, Today, 08:59 AM
              2 responses
              10 views
              0 likes
              Last Post bltdavid  
              Started by alifarahani, Today, 09:40 AM
              6 responses
              41 views
              0 likes
              Last Post alifarahani  
              Working...
              X