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

Enter on every Xth bar

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

    Enter on every Xth bar

    Hi

    again I need your help. The problem is quite simple. I want to enter, let's say, every 5 minutes. Probably the position is already closed after 1 minute. But even if the entry conditions are filled, it should only enter every 5 minutes, no matter when the position was closed. Is there any command for this?

    EDIT: I know, the BarsSinceEntry() command would work, but there isn't each 5 minutes a position. So it has to be independent from the last entry. So every 5 minutes shall the entry conditions be checked and opened a position if needed.

    Thanks in advance,

    Sepp

    #2
    Sepp,

    You can count the CurrentBar's and as 5 bars go buy, check conditions, place trade, reset counter. Another 5 bars, place new order.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Not quite understanding. How do I do this? Could you give me the code snippet?

      Thanks in advance,

      Sepp

      Comment


        #4
        Unfortunately I don't have a full sample for you, here's the basic concept to start -

        if (your condition)
        myCounter = CurrentBar;

        if (CurrentBar - myCounter == 5)
        EnterLong();
        BertrandNinjaTrader Customer Service

        Comment


          #5
          But this would only work if the condition wouldn't be filled between the first and the second code - otherwise the counter would be increased by 1 and there wouldn't ever be 5 between.
          Isn't there any possibility like:

          If (ToTime(0) == ToTime(XX,5/10/15/...,XX)
          buy;

          So that it's really independent from the rest of the strategy. Just every 5 minutes will be checked, if the entry condition is filled.

          Regards,

          Sepp

          Comment


            #6
            Hello,

            I'm jumping in here but take a look at this link for help on this:
            DenNinjaTrader Customer Service

            Comment


              #7
              I know how the ToTime() command works, but is there another possibility to get the condition check every 5 minutes? As far as I know, I'd have to type each 5 minute with the ToTime() command. This would look like this:

              If(ToTime(0) == ToTime(10,00,00)
              check conditions,
              If(ToTime(0) == ToTime(10,05,00)
              check conditions,
              If(ToTime(0) == ToTime(10,10,00)
              check conditions,
              If(ToTime(0) == ToTime(10,15,00)
              check conditions,
              ...

              This would be very much work to do.... that's why I'm asking if there isn't another possibility to get the same result.

              Regards,

              Sepp

              Comment


                #8
                Assuming ToTime(0) returns an integer representing seconds, and 300 is the correct equivalent for 5min, then you could try the following:

                if (ToTime(0) % 300 == 0) ...

                Regards
                Ralph

                Comment


                  #9
                  Dear Ralph,

                  could you explain me what this command does? I've never seen this before. Additionally, it doesn't work right. I see that it DOES anything, but I don't see WHAT it does.

                  Regards,

                  Sepp

                  Comment


                    #10
                    Watch the result in the output window with:
                    Print(ToTime(0) % 300 );
                    Since you are don't use simple data types, that is the save way to control the real behaviour.
                    The %-operator returns the fraction of a /-operation. While (int / int) returns the integer result (5 / 2 = 2), (int % int) returns the remainder (5 % 2 = 1).

                    In your case you are looking for a fraction of zero, therfore the comparison ( == 0).

                    Regards
                    Ralph

                    Comment


                      #11
                      It works! For your own information: the time isn't saved in seconds but just as a number. 13:45:00 is equal to the number 134500. So I had to take the code: ToTime(0) % 500 == 0, because this is for every 5 minutes.
                      Thank you so much for helping me with this problem!

                      Regards,

                      Sepp

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by ScottWalsh, Today, 06:52 PM
                      1 response
                      6 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by ScottW, Today, 06:09 PM
                      1 response
                      4 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by ftsc2022, 10-25-2022, 12:03 PM
                      5 responses
                      256 views
                      0 likes
                      Last Post KeyonMatthews  
                      Started by Board game geek, 10-29-2023, 12:00 PM
                      14 responses
                      244 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Started by Waxavi, 04-19-2024, 02:10 AM
                      4 responses
                      56 views
                      0 likes
                      Last Post sonia0101  
                      Working...
                      X