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

How to delay or pause 30 seconds before executing an action?

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

    How to delay or pause 30 seconds before executing an action?

    If I want to delay 30 seconds to execute a buy order, what is the easiest way to do this?
    More specifically, I am using Data Series (Type = seconds, Value 3), so I can count 10 bars to reach 30 seconds, how do I do this? Do you have sample code for this?

    Thanks.


    If (Condition==True)
    Pause for 30 Seconds
    {
    EnterLong();
    }
    Last edited by localappleseed; 10-28-2020, 09:52 AM.

    #2
    Hello localappleseed,

    Thank you for the post.

    You would never want to pause the script in any way so waiting is generally accomplished by using a data series that matches that timeframe or Time comparisons.

    Do you happen to be using a 30 second series? If so you could just use a bool variable in that case to make it wait 1 bar, the CurrentBar index could also be used there.

    If you are using a different series that's less granular like 5 second, you could use Time and check if the current bars time is 30 seconds after a stored time.

    If you used a more granular like 1 minuted, a secondary series of 30 seconds could be added to execute logic at 30 second intervals.

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

    Comment


      #3
      Thank you for quick reply on this. Further questions on this:
      1) you suggested to use the bar Time, which is good idea.
      2) If I use 5 sec series chart, does this mean OnBarUpdate() will be called every 5 seconds? If this is the case, I can also count 6 times of calling OnBarUpdate()?

      Comment


        #4
        Helllo localappleseed,

        Thank you for the reply.

        If you use a 5 second chart then you could count or use time, either would work.

        You can make an int variable and then store the CurrentBar at the time of the condition. As a second condition you could check if(CurrentBar >= storedBar) to start the order. At that point you would want to reset the storedBar so its not going to become true until you wanted, you could reset it to something really high to avoid the CurrentBar being greater again.


        Code:
        if (Condition==True)
        {
            storedBar = CurrentBar + 6;
        }
        
        if(CurrentBar >= storedBar)
        {
           EnterLong();
            storedBar = 99999999;
        }
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by helpwanted, Today, 03:06 AM
        1 response
        11 views
        0 likes
        Last Post sarafuenonly123  
        Started by Brevo, Today, 01:45 AM
        0 responses
        9 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        5 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        242 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        387 views
        1 like
        Last Post Gavini
        by Gavini
         
        Working...
        X