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 DJ888, 04-16-2024, 06:09 PM
        4 responses
        12 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by terofs, Today, 04:18 PM
        0 responses
        11 views
        0 likes
        Last Post terofs
        by terofs
         
        Started by nandhumca, Today, 03:41 PM
        0 responses
        7 views
        0 likes
        Last Post nandhumca  
        Started by The_Sec, Today, 03:37 PM
        0 responses
        3 views
        0 likes
        Last Post The_Sec
        by The_Sec
         
        Started by GwFutures1988, Today, 02:48 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Working...
        X