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

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:



          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 wzgy0920, 04-20-2024, 06:09 PM
            2 responses
            26 views
            0 likes
            Last Post wzgy0920  
            Started by wzgy0920, 02-22-2024, 01:11 AM
            5 responses
            32 views
            0 likes
            Last Post wzgy0920  
            Started by wzgy0920, Yesterday, 09:53 PM
            2 responses
            49 views
            0 likes
            Last Post wzgy0920  
            Started by Kensonprib, 04-28-2021, 10:11 AM
            5 responses
            192 views
            0 likes
            Last Post Hasadafa  
            Started by GussJ, 03-04-2020, 03:11 PM
            11 responses
            3,235 views
            0 likes
            Last Post xiinteractive  
            Working...
            X