Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entering a trade in the last minute of a 3 minute-bar

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

    Entering a trade in the last minute of a 3 minute-bar

    I am building a strategy base in some rules but with the condition that only make a trade if we are in the last minute of the current bar. Is there any way of doing this in ninjascript?.

    Thanks in advance for your help

    #2
    Sangui,

    I am happy to assist you.

    This is definitely possible. You can use the following reference samples to get where you are going.







    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Hi Adam,

      Yes please I would need further explanation about the specific result I am looking for. That is, imaging that we are working with a 3 minute chart and our strategy enters long if MACD indicator goes above ZERO but only when the bar is in the third minute. Could you send me the code or another similar please?

      Thanks and regards,

      Comment


        #4
        Or maybe I can use BARTIMER indicator to do so?

        Comment


          #5
          Sangui,

          Something like this should work :

          Code:
           protected override void OnBarUpdate()
           {
          	if(BarsInProgress == 0)
          	{
          		three_minute_timestamp = Times[0][0];
          	}
          	else if(BarsInProgress == 1)
          	{
                      	if(       ToTime(Times[1][0]) >= ToTime(three_minute_timestamp.AddMinutes(2)) 
          		    && ToTime(Times[1][0]) <= ToTime(three_minute_timestamp.AddMinutes(3)) 
                          )
                      	{
          					Print("Order Entered - 3-minute time : "+Times[0][0]+"   Order entry time : "+Times[1][0]);
                          	EnterLong(DefaultQuantity, "");
                      	}
          
          	}
          }
          An example of the printed output :

          Order Entered - 3-minute time : 4/18/2012 7:24:00 AM Order entry time : 4/18/2012 7:26:00 AM

          The 7:24 is the 3 minute time stamp, and the 3 minute bar would be made up of data from 7:24 through 7:27.

          Please let me know if I may assist further.
          Last edited by NinjaTrader_AdamP; 04-18-2012, 07:31 AM.
          Adam P.NinjaTrader Customer Service

          Comment


            #6
            OK. Thanks. I think it may work. I will let you know .

            Comment


              #7
              Sangui,

              Yes, please let me know if you have any other questions after you implement it.
              Adam P.NinjaTrader Customer Service

              Comment


                #8
                Hi Again,

                I was testing this code but this in not exactly what I am looking for. I would need something like the following:

                In a 3-minute chart, as soon as a new bar begins (FirstTickOfBar), the count of the time must start then print an alert when we are in the third minute of the bar.

                For example: A new bar starts, so the time is 0:00 (minutes:Seconds). Then when the time of the bar is greater than 2:00 an alert is print. With this code I think I can work because I will use as a filter in my strategy.

                I don't know If I am explain the situation properly, please let me know...

                Thanks again

                Comment


                  #9
                  Sangui,

                  What doesn't work about this? Are you noticing some behavior that isn't what you want?
                  Adam P.NinjaTrader Customer Service

                  Comment


                    #10
                    The thing is that I need to know exactly when the bar is in its third minute. But using only on chart of 3 minutes. This is why I was thinking in using the Bartimer indicator when the "Time remaining" is >=00:02:01. Do you understand me know?. Sorry about my english...

                    Regards,

                    Comment


                      #11
                      Sangui,

                      Thanks for your note.

                      Do you want the indicator to work on historical bars? Or do you only want it to let you know from the time you attach it to a chart and forward? BarTimer in this case only works from the most current bar forward.

                      Your English is great! I just needed some clarification because there are a couple ways to do this.
                      Adam P.NinjaTrader Customer Service

                      Comment


                        #12
                        I don't want to use it with historical bar only in realtime chart. But I am not able to make the proper code that let me know when the time is in the 3rd minute of the bar...

                        Thanks again for your patience.

                        Comment


                          #13
                          Sangui,

                          Please find something attached that works sort of like what you want. It works tick by tick instead of the BarTimer way since its a bit more complicated to do it that way. You can modify it to make alerts, or anything else. Currently it just displays text on your chart.
                          Attached Files
                          Last edited by NinjaTrader_AdamP; 04-18-2012, 11:51 AM.
                          Adam P.NinjaTrader Customer Service

                          Comment


                            #14
                            OK, now I think this is what I was looking for . I will keep you posted.

                            Thanks about your fast and good support

                            Regards

                            Comment


                              #15
                              Sangui,

                              No problem. Yes, take a look and let me know. This runs tick by tick, but should be pretty close to what you want. BarTimer is a bit more complicated to edit for the purposes you need it for.
                              Adam P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              648 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              369 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              108 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              572 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              574 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X