Announcement

Collapse
No announcement yet.

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.

    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;
        }

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        65 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        139 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        75 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X