Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Actoin within a Given Period of Time

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

    Actoin within a Given Period of Time

    I am trying to develop a strategy to alert me when a condition happens within X seconds. How can I define X seconds within strategy builder? For Example:

    If Action happens within 10 seconds I want to buy.

    I don't know how to configure "within 10 seconds" in my Group condition. I have looked at Time series and Time values but they are defined with clock time and not within seconds.

    Any ideas how to create a condition based on that condition being triggered within 10 seconds (period of time repeats every 10 seconds)
    Last edited by w0lverine; 12-06-2019, 09:24 PM.

    #2
    Hi w0lverine, thanks for your post.

    This would require you to unlock the strategy and add a 10 second series to your script. The reason this can not be done in the builder is you need to access the 1 second series to count the seconds. e.g.

    Code:
    else if (State == State.Configure)
                {
                    AddDataSeries(BarsPeriodType.Second, 10);
                }
            }
    
            protected override void OnBarUpdate()
            {
                if(BarsInProgress == 1)
                {
                    Print("Ten Seconds has passed");
                }
            }

    Comment


      #3
      NinjaTrader_ChrisL Thank you for that!

      Comment


        #4
        Took your advice. I hope I interpreted it right (ignore action function)? Trying to perform the following pseudo code:

        If current time_frame has contracts_traded do <action>
        If within 10 seconds && 1000 contracts traded do <action>


        Code:
                    else if (State == State.Configure)
                    {
                        AddDataSeries(Data.BarsPeriodType.Volume, 1000);
                        AddDataSeries(Data.BarsPeriodType.Second, 10);
                    }
                }
        
                protected override void OnBarUpdate()
                {
                    if (BarsInProgress != 0)
                        return;
        
                    if (CurrentBars[0] < 0)
                        return;
        
                     // Set 1
                    if (
                         // Price Action
                        ((Volume[0] == Contract_traded)
                         && (Times[0][0].Date == Times[2][0].Date)))
                    {
                    }
        
                }
        Last edited by w0lverine; 12-07-2019, 06:25 PM.

        Comment


          #5
          Hi w0lverine, thanks for your reply.

          I attached an example you can use that adds a 1-second data series. It enters a position in the primary series and once 10 seconds has passed it closes the position. Add the attached file into Documents\NinjaTrader 8\bin\Custom\Strategies and compile to run it.

          I found this example on a fully-fledged timer example:



          Forwarning, this is on the advanced side of things programming-wise. In this example, the timer starts from the launch of the script and calls the TimerEventProcessor() method upon each tick (1000 miliseconds).
          Attached Files

          Comment


            #6
            Chris,

            Thank you. I will digest the information.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            50 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            126 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            69 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X