Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

2 second delay between events.

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

    2 second delay between events.




    people with nt,




    regards.



    i need a 2 second delay for some of the events that take place inside an indicator i have been developing, and i really have been having a torrid time trying to code this in nt.



    i have an indicator that creates text files that serve as log entries. i share a file of an indicator as an attachment that uses streamwriter to create text files as log entries. i run it on 4 second bars and it generates alternating text files according to odd or even bar numbers.



    there are four different file types, two of which i want to be created only after a 2 second delay. on a 4 second chart this means that the events without any delays should generate text files on the index 0 and the two types that should be delayed should generate text files right in the middle of this 4 second interval on the index 1.


    it took me several days to code this and now the indicator as i share it does generate text files of 4 different types, however, i don't think the delay is being observed as the files appear two by two on the folder where they are created to. ¿is there any way to ensure a 2 second delay for the events i'm interested in?



    this has the utmost importance for me so i think i would even pay for assistance if i'm unable to code this myself. hopefully i should be able to code this myself to perform as intended as i think i'm not far away from the intended objective.



    very well, regards.
    Attached Files

    #2
    Hello rtwave,

    Thank you for your post.

    If you are adding a more granular series within the script like 1 second, you could use a CurrentBars check to see if at least 2 bars have elapsed in the 1 second series.



    Code:
    int mySavedBar;
    
    if(<your condition here>)
    mySavedBar = CurrentBars[1];
    
    if(CurrentBars[1] - mySavedBar == 2)
    //2 bars have elapsed
    Other than that, in real-time you could use a C# timer to delay actions, but this will not work in historical data.




    If you would like assistance from a NinjaScript consultant to code this, you can search our extensive library of NinjaScript consultants through the link below. Simply enter a consultant name or search by using our filter categories. Once you have identified your consultants of choice, please visit each consultant's site for more information or contact them directly to learn more:

    https://ninjatraderecosystem.com/sea...mming-services

    You can locate the contact information for the consultants on their direct websites for any additional questions you may have. Since these consultants are third-party services for NinjaTrader, all pricing and support information will need to be obtained through the consultant.

    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The companies and services listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem, LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

    Let me know if I may be of further assistance.

    Comment


      #3




      people with nt,



      i haven't been able to make much progress on this functionality i have been working on.


      i have created a version of the indicator with a 1 or 2 seconds secondary series and tried to use variables on that secondary series to create a delay between a condition and a text file being created. seemingly this does not work as i have observed that the file is not created after a delay which the entire purpose here.


      i have now been studying c# and ns timers and is always the case, the documentation that nt makes available is so minimal that it is unusable.


      if i understand correctly, the structure that i should follow should be something along these lines:


      if(<conditions observed>)
      start ' timer method ';

      once ' timer method ' completes
      start streamwriter method;



      i am attaching a sample file that nt makes available. i can't find any command to start a ' timer method ' anywhere. ¿can nt include the necessary commands so that a 2 second timer will start on every bar with an odd bar number and a print with the current time and bar number every time the ' timer method ' completes?

      Attached Files

      Comment


        #4
        Hello rtwave,

        If you want to count something from every single bar, it would be more feasible to use an added 1 second series for a timer instead of using TriggerCustomEvent.

        Please see the attached sample script. When the condition to start the timer becomes true, we take that bars close time and add two seconds and save that time to a variable. Then on the secondary series, we check if the time is equal to that variable.
        Attached Files

        Comment


          #5




          people with nt,





          i have been having a horrible time with this objective. and it has been a similar situation with all the most important developments i have coded in ninjascript. it is inconceivably difficult to program most ideas one could have on nt.




          in this case, it has taken me weeks and, unbelievably, it was the prints that were generating errors and idiocy. nt's customary response is to tell everyone to use prints, ¿but what if it is the prints that defeat everything?


          ¿can nt explain what is the problem with this print below on a 2 second chart with a secondary 1 second series? this fragment can be enabled on the sample file i share and it will generate object reference errors.


          Print("t0 " + Times[0][0] + " - t1 " + Times[1][0] + " - CurrentBars[0] " + CurrentBars[0] + " - CurrentBars[1] " + CurrentBars[1] );





          and, i now have an indicator that will compile, will plot and will generate text files. if i use 2 second and 1 second series, the entire purpose of all the work is to have the files generated one by one, first type a, a second later type b, then type c, and type d. however, when running the indicator on 1 minute and 30 second series the results are a mess:


          t0 11-Sep-24 22:55:00 - t1 11-Sep-24 22:55:30
          c:\ntlogs\orders 20240911 225614 a 2105 sqqqtests.txt
          type a.
          c:\ntlogs\orders 20240911 225614 b 2105 sqqqtests.txt
          type b.
          t0 11-Sep-24 22:56:00 - t1 11-Sep-24 22:56:00
          c:\ntlogs\orders 20240911 225642 b 2104.9 sqqqtests.txt
          type b.
          t0 11-Sep-24 22:56:00 - t1 11-Sep-24 22:56:30
          c:\ntlogs\orders 20240911 225706 d 2105 tqqqtests.txt
          type d.
          c:\ntlogs\orders 20240911 225706 c 2105 tqqqtests.txt
          type c.
          t0 11-Sep-24 22:57:00 - t1 11-Sep-24 22:57:00
          c:\ntlogs\orders 20240911 225751 d 2105.3 tqqqtests.txt
          type d.
          t0 11-Sep-24 22:57:00 - t1 11-Sep-24 22:57:30
          c:\ntlogs\orders 20240911 225844 a 2105.3 sqqqtests.txt
          type a.
          c:\ntlogs\orders 20240911 225844 b 2105.3 sqqqtests.txt
          type b.
          t0 11-Sep-24 22:58:00 - t1 11-Sep-24 22:58:00
          c:\ntlogs\orders 20240911 225922 d 2105.5 tqqqtests.txt
          type d.
          c:\ntlogs\orders 20240911 225922 c 2105.5 tqqqtests.txt
          type c.
          t0 11-Sep-24 22:59:00 - t1 11-Sep-24 22:59:00
          c:\ntlogs\orders 20240911 225943 d 2105.5 tqqqtests.txt
          type d.​


          we see files generated in pairs and out of order, and also some repeat files when nothing in the code should allow for that: and for some reason the nt platform will not create prints for the Times[0][0] series but only for the Times[1][0] series. i had created indicators that used these prints previously and there had not been any problems.


          if (CurrentBars[0] % 2 == 0)
          {
          casetyp = "d";

          teuptr = string.Format(@"type {0}.", casetyp[0]);
          reevuptr(teuptr);
          Print(teuptr);

          crbadotr = CurrentBars[1] ;

          }

          if( ( CurrentBars[1] - crbadotr ) == Convert.ToInt32(Bade) )
          {
          casetyp = "a";
          Draw.TriangleDown(this, @"jump in down", true, 0, ( High[0] + ( ( ar[0] ) * ( Om ) ) ), Brushes.DarkRed);

          tedotr = string.Format(@"type {0}.", casetyp[0]);
          reevdotr(tedotr);
          Print(tedotr);

          }​


          i created a post on upwork asking for assistance but the project has not been taken as i have only a very modest budget. it has been weeks that i have been working on this initiative and i just can't make it work satisfactorily.

          Comment


            #6
            Hello rtwave,

            Using my sample script, I am not getting any object reference errors when printing out anything from the Times series or CurrentBars values.

            Can you post a reduced sample script that demonstrates this issue? Remove all code that is not necessary for reproducing this behavior.

            Comment


              #7



              people with nt,


              i share a sample file. the only thing of relevance it should do should be the alternating prints - text files.


              on 2 and 1 second series it seems as if the files are created one by one. if one uses 1 minute and 30 second series everything becomes a mess.


              and, as i mentioned previously, the biggest problem is with the lines for prints inside the barsinprogress 1 section.
              Attached Files
              Last edited by rtwave; 09-12-2024, 11:55 AM.

              Comment


                #8
                When I test this script out I am not getting any object reference errors, the script is printing out the Times values without issue.
                Attached Files

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                576 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                334 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                101 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                553 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                551 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X