• 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, 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");
                }
            }
    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, 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:

          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 mr_trade, Today, 01:32 PM
            0 responses
            2 views
            0 likes
            Last Post mr_trade  
            Started by sgordet, Today, 10:44 AM
            1 response
            6 views
            0 likes
            Last Post bltdavid  
            Started by Parmenides48, Today, 08:37 AM
            2 responses
            14 views
            0 likes
            Last Post Parmenides48  
            Started by EnveousColnago, 08-06-2020, 08:31 AM
            8 responses
            47 views
            0 likes
            Last Post Emma1
            by Emma1
             
            Started by dieci, Today, 08:50 AM
            0 responses
            5 views
            0 likes
            Last Post dieci
            by dieci
             
            Working...
            X