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

Little modification to Flash/Sound Bar Timer

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

    #16
    Hello Ludwik,

    While I cannot debug the script you provided I can provide a simplifed sample of how to execute code 30 seconds before the primary bar. I have attached a script that prints to the output window the times for the event. For example if you are using a 15 minute bar we may see a print like the following:

    Time of the primary last close bar is 11/7/2023 4:45:00 PM Time of the future primary bar is 11/7/2023 4:59:30 PM Time of the secondary series is 11/7/2023 4:59:30 PM


    The print happens when the time of the secondary series is greater or equal to the projected time. It resets for each new primary bar. You would need to use logic like this if you wanted to do something before the end of a primary bar. Please note that you will see varying times for the secondary series depending on how much volume the instrument in question has, if there is little volume it may wait some time which is why the secondary series timestamps may not be exactly at the projected time. It would be best to use 1 second or 1 tick granularity for the secondary series if you use a instrument that has times of low volume.
    Attached Files
    JesseNinjaTrader Customer Service

    Comment


      #17
      All working now. You made my day. Thank you so much Jesse.

      Only thing I needed to do is adding an alert, which is very easy thing to do.

      Thanks again

      Comment


        #18
        I'm trying to add a modification to the SampleProjectTime which would let me to take the data from the current timeframe on chart and make calculations without phyically adding data so the data is updated upon changing timeframe on the chart. Then have an alert 30 seconds before current timeframe bar is closed.
        Issue which I'm getting triggers an alert 30 seconds after current bar opens instead of 30 seconds before it closes.

        Here are the types of code which I tried.

        Code:
         DateTime newTime = Times[0][0].AddMinutes(BarsPeriod.Value).AddSeconds(-30);
        Code:
         DateTime newTime = Times[0][0].AddMinutes(BarsPeriod.Value).AddSeconds(-(BarsPeriod.Value - 30);
        Code:
         DateTime newTime = Times[0][0].AddMinutes(BarsPeriod.Value).AddSeconds(-((BarsPeriod.Value * 60) - 30);
        None of the above is working as expected

        Could you plesae point me in the direction of how to approach it?

        Comment


          #19
          Hello Ludwik,

          Have you tried using a Print to see what values you are working with when you calculate the time? To add a number of minutes and then subtract a number of seconds would look exactly like the sample that I provided or

          Code:
           DateTime newTime = Times[0][0].AddMinutes(number of minutes to be added).AddSeconds(- number of seconds to be subtracted);
          which looks like:
          Code:
           DateTime newTime = Times[0][0].AddMinutes(15).AddSeconds(-30);
          Keep in mind the secondary series needs to be a small timeframe like 1 second, you have to add the secondary series to be able to use this type of logic.
          JesseNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Haiasi, 04-25-2024, 06:53 PM
          2 responses
          17 views
          0 likes
          Last Post Massinisa  
          Started by Creamers, Today, 05:32 AM
          0 responses
          5 views
          0 likes
          Last Post Creamers  
          Started by Segwin, 05-07-2018, 02:15 PM
          12 responses
          1,786 views
          0 likes
          Last Post Leafcutter  
          Started by poplagelu, Today, 05:00 AM
          0 responses
          3 views
          0 likes
          Last Post poplagelu  
          Started by fx.practic, 10-15-2013, 12:53 AM
          5 responses
          5,407 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Working...
          X