• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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, 08: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");
                }
            }
    Chris L.NinjaTrader Customer Service

    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, 05: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:

          https://ninjatrader.com/support/foru...ta-book?t=5965

          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
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Chris,

            Thank you. I will digest the information.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by EnveousColnago, Today, 05:43 PM
            0 responses
            4 views
            0 likes
            Last Post EnveousColnago  
            Started by Zigfried, Today, 02:30 PM
            2 responses
            8 views
            0 likes
            Last Post Zigfried  
            Started by lunardiplomacy, Today, 11:35 AM
            4 responses
            13 views
            0 likes
            Last Post lunardiplomacy  
            Started by silverm3170, Today, 11:24 AM
            3 responses
            10 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by mefTrader, 01-21-2020, 01:07 PM
            2 responses
            12 views
            0 likes
            Last Post mefTrader  
            Working...
            X