Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entering a trade on a different timeserie?

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

    Entering a trade on a different timeserie?

    Hello,

    I know this must be super basic, but I am not able to make it work.

    What I am trying to do is the following: On a daily chart, I want to enter a trade right after the opening for the given day if some condition is met in the past.
    I want to execute the trade as soon as the markets opens, but when I run my code it gets executed 1 minute before the market closes instead of 1 minute after the market opens.

    The idea would be to execute the code as soon as the markets opens and close it before the markets close for the day.


    Here is how I my code:
    Code:
    protected override void Initialize()
            {
                CalculateOnBarClose = true;
    			ExitOnClose = true;
    			Add(PeriodType.Minute, 1);
            }
    
    
            protected override void OnBarUpdate()
            {
               if (BarsInProgress == 0)
    			{
                if (something])
                {
    		EnterLong(1, 1, "Long: 1min");
                }
    
    			} 
    		else 
    		{
    			return;
    		}
    		}
    Any tip in the right direction will be much appreciated! Thanks

    #2
    If you want to enter on the 1min data series, you need to check that BarsInProgress == 1. As you have it set right now, you're checking your conditions on the primary data series, which is the daily.

    Comment


      #3
      Originally posted by coolmoss View Post
      If you want to enter on the 1min data series, you need to check that BarsInProgress == 1. As you have it set right now, you're checking your conditions on the primary data series, which is the daily.
      Thanks, I was studying from a code I found in the forum, I was not sure how BarsInProgress worked. So each time I add a new data series, I will call them like that, BarsInProgress==1..2..3? The order comes from the order in which the Add() method is called?

      Thanks a lot for your help!

      Comment


        #4
        Originally posted by yakito View Post
        Thanks, I was studying from a code I found in the forum, I was not sure how BarsInProgress worked. So each time I add a new data series, I will call them like that, BarsInProgress==1..2..3? The order comes from the order in which the Add() method is called?

        Thanks a lot for your help!
        Yes, and 0 is the primaryseries.

        Comment


          #5
          Hello, I been trying for the past hours with no success to achieve this. This time is strange because when I debug the code I see it "working" but on the strategy analyzer the trades are not there.

          I am backtesting on a 1 day data series, here is my code:
          Code:
          			if (BarsInProgress == 0){
          			
                      if (Condition) {
                          Variable0=1;
          		}
          			}
          			
          			if (BarsInProgress == 1) {
          				if (Variable0==1){
          					EnterLong("Long: 1min");
          					Variable0 =0;
          					Print("Buy Here");
          				}
          				
          			}
          I do see the "Buy Here" on the output window, but there are no trades executed on the strategy, does anyone has a clue why this might be happening?

          Again thanks a lot for any help

          Comment


            #6
            yakito, which instrument are you exactly working with here?

            Would a position be perhaps historically still open and no further position be allowed by your EntryHandling setting chosen?



            Also very helpful for further debugging would be adding the TraceOrders prints in - http://www.ninjatrader.com/support/f...ead.php?t=3627

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              yakito, which instrument are you exactly working with here?

              Would a position be perhaps historically still open and no further position be allowed by your EntryHandling setting chosen?



              Also very helpful for further debugging would be adding the TraceOrders prints in - http://www.ninjatrader.com/support/f...ead.php?t=3627
              Thanks a lot Bertrand, I will take a look at the EntryHandling method, although I have ExitOnClose = true; wouldn't that close all orders at the end of the day? If not what would be the correct way to exit the position right before the market closes?

              Thanks again!

              Comment


                #8
                TraceOrders helped a lot, I think I found the error, although I am not sure why it is working like that.

                The log shows:

                6/26/2013 5:00:00 PM Entered internal PlaceOrder() method at 6/26/2013 5:00:00 PM: BarsInProgress=1 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Long: 1min' FromEntrySignal=''

                That means that the order is executed at market close instead as soon as the market open like it was my intention.

                Shouldn't it be:

                DAY Time series (10:30)
                MINUTE Time series (10:30)
                MINUTE Time series (10:31)

                Till the end of the day?

                Any tip much appreciated!
                Thanks!

                Comment


                  #9
                  Hello yakito,

                  Which instrument are you testing out your code on?

                  I would expect this if you are testing this on for example the "ES 09-13" as the Session is going to Start at 5:00PM which is going to be the first bar.

                  If you would like to limit the trading hours of your strategy you may view the following reference for an example of this.
                  JCNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_JC View Post
                    Hello yakito,

                    Which instrument are you testing out your code on?

                    I would expect this if you are testing this on for example the "ES 09-13" as the Session is going to Start at 5:00PM which is going to be the first bar.

                    If you would like to limit the trading hours of your strategy you may view the following reference for an example of this.
                    http://www.ninjatrader.com/support/f...ead.php?t=3226
                    Hello, Thanks for your answer, I am testing it on AMZN, or any stock.

                    Comment


                      #11
                      Hello yakito,

                      I believe what is happening here is that at the Close of the Daily Bar it is setting your condition to be true and then it is processing your Minute bar (BarsInProgress == 1) which is entering you in a trade.

                      Using the Strategy Analyzer you shouldn't need to add the Minute Bars in as if you set your entry order in (BarsInProgress==0) it will fill your order at the next bar which is going to be the open for the new bar.

                      If you would like to keep this data series inside of your strategy you may want to add a Time filter so that it only enters your order in at the start of the Market Hours.

                      Let us know if this works for you.
                      JCNinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_JC View Post
                        Hello yakito,

                        I believe what is happening here is that at the Close of the Daily Bar it is setting your condition to be true and then it is processing your Minute bar (BarsInProgress == 1) which is entering you in a trade.

                        Using the Strategy Analyzer you shouldn't need to add the Minute Bars in as if you set your entry order in (BarsInProgress==0) it will fill your order at the next bar which is going to be the open for the new bar.

                        If you would like to keep this data series inside of your strategy you may want to add a Time filter so that it only enters your order in at the start of the Market Hours.

                        Let us know if this works for you.
                        Thanks again

                        The thing is that if I remove the Minutes Bars then it will run on the next day. I need it to run on the same day.

                        What I am trying to do is really simple: Check if a condition is met between todays opening and past bars, and if it does, then open a position at the opening of the market (today) and close it at the end of the day (today).

                        Any tip will be much appreciated.

                        Comment


                          #13
                          Hello yakito,

                          Are you using a time filter inside of your conditions?
                          JCNinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by NinjaTrader_JC View Post
                            Hello yakito,

                            Are you using a time filter inside of your conditions?
                            Hello, sorry for the delay.

                            Suppose I am just trying to set a trade on a Gap Up from the daily data series. (Open[0] > High[1])

                            The trade should be set on the first minute of the day, and closed, at the end of the day.

                            Shouldn't this code work?

                            Code:
                            protected override void Initialize()
                                    {
                                        CalculateOnBarClose = true;
                            			ExitOnClose = true;
                            			Add(PeriodType.Minute, 1);
                                    }
                            
                                    /// <summary>
                                    /// </summary>
                                    protected override void OnBarUpdate()
                                    {
                                       if (BarsInProgress == 0)
                            			{
                                        if (Open[0] > High[1])
                                        {	
                            				EnterLong(1, 1, "Long: 1min");
                                        }
                            
                            			} 
                            		else 
                            		{
                            			return;
                            		}
                            		}
                            Any help will be much appreciated!
                            Thanks

                            Comment


                              #15
                              Hello yakito,

                              Thank you for your response.

                              You can just use the CurrentDayOHL() and PriorDayOHLC() indicator methods here and ensure CalculateOnBarClose is set to false to process this condition on each incoming tick of the primary series, but set the Primary Series to 1 Minute instead of 1 Day:
                              Code:
                              			if(CurrentDayOHL().CurrentOpen[0] > PriorDayOHLC().PriorHigh[0])
                              			{
                              				//Your entry.
                              			}
                              For information on CurrentDayOHL() please visit the following link: http://www.ninjatrader.com/support/h...nt_day_ohl.htm

                              For information on PriorDayOHLC() please visit the following link: http://www.ninjatrader.com/support/h...r_day_ohlc.htm

                              Please let me know if I may be of further assistance.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              672 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              379 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              111 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              575 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              582 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X