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

Multi TimeFrame Help Needed!

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

    Multi TimeFrame Help Needed!

    Hello,

    I have a stategy that uses multi timeframe of 1 Tick and 15 mins. I want the strategy to place a long order inside of the 15 min candle stick (Hence the need for Tick Chart). But it seems like it is waiting for the 15 min stick to close before placing the order. I did some digging into it to find out why it was not doing what I wanted it to do by using arrows and noticed something weird happening

    - The Arrow location is not the same as the Open[0] price on a 1 Tick Chart.For some reason it is 10s of pips below the Open. I have made some screen captures for you to see. The first picture shows the correct Open[0] for both time frames where the cross-hair is located but notice the arrow is way down below.
    Secondly, even if I move my cross hair upto the arrow, it is near the middle of 15 min candle stick.I think this is the reason my Strategy is not placing the order like I want because I am using Open price of 15 min chart as a guide.

    Any help would be much appreciated

    Code:
     protected override void Initialize()
            {
                CalculateOnBarClose = false;
    			Add(PeriodType.Minute,15);
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    			if(Open[0]==Opens[1][0])
    			{
    				DrawArrowUp("Arrow" +counter,0,Open[0],Color.Green);
    				counter=counter+1;
    			}
    			
            }
    Attached Files

    #2
    Hello MyFirstMillion,

    Thank you for your note.

    A NinjaScript representative will review your inquiry tomorrow morning and follow up with you on their findings.

    Comment


      #3
      Hello MyFirstMillion, and thank you for your questions. I noticed a couple of unusual things about your strategy's code. First, I noticed there is no BarsInProgress checking. This means that your OnBarUpdate code is the same for your primary series and your 15 minute series, which is probably not what you intended. You can structure your code like this to keep things separated.

      Code:
      [FONT=Courier New]protected override void OnBarUpdate()
      {
          switch(BarsInProgress)
          {
      
              case 0 :[/FONT][FONT=Courier New][FONT=Courier New]
                  // process primary bars here
      [/FONT]            break;
      
              case 1 :[/FONT][FONT=Courier New][FONT=Courier New]
                  // process 15 minute bars here
      [/FONT]            break;
      
          }
      }[/FONT]
      Second, I would like to mention that the code you posted does not contain your entry order logic. If you would like your Entry orders to be placed on your primary bars, you will need to send in a 0 as your Entry Order's BarsInProgress index, and if you want them placed on your 15 minute bars, you will need to use a 1. Here's an example that places orders on your primary bars

      Code:
      [FONT=Courier New]
      EnterLong(0, DefaultQuantity, "");[/FONT]
      Please let us know if there are any other ways we can help.
      Jessica P.NinjaTrader Customer Service

      Comment


        #4
        Thank you for the reply . I changed the code and I am getting the following error "Control case cannot fall from one case label to another"


        protected override void OnBarUpdate()
        {
        switch(BarsInProgress)
        {
        case 0:
        if(Open[0]==minopen)
        {

        EnterLong(0,2500,"");
        DrawArrowUp("Arrow" +counter,0,Open[0],Color.Green);
        counter=counter+1;
        break;
        }
        case 1:
        minopen=Opens[1][0];
        break;
        }

        Comment


          #5
          Never mind, I realized my misplacement of 'break' tag. I will run some tests and let you know what comes out.
          Thanks

          Comment


            #6
            Hello,
            the strategy seems to be working better now but I have run into another related issue. I am trying to get the Open for 15 min candle stick by using Opens[0][0]. But it seems like the information is not updated till after bar close. So instead I am having to use the previous bar close valvue as current candle sticks open value.
            Is there a way to get current sticks Open value before the bar closes?
            Thanks

            Comment


              #7
              If you had, for example, a 1 tick series, and you peeked at your 15 minute bars from within this 1 tick series, you should be able to see the building bars OHL and last traded price. Since you mentioned this is your primary bars series, you can also use CalculateOnBarClose == false.
              Jessica P.NinjaTrader Customer Service

              Comment


                #8
                Thank you for the reply. Calculateonbarclose does not work during backtest. all calculations are done on bar close during the backtest. What would be the code for the barOHL to get Open Price of 15 min candle?

                Thank You

                Comment


                  #9
                  You are correct with regard to backtesting. Could you send us a sample of the code that replaces the boldface code below in your script, to help us investigate further?

                  Code:
                  [FONT=Courier New]protected override void OnBarUpdate()
                  {
                      switch(BarsInProgress)
                      {
                  
                          case 0 :
                              // process primary bars here
                              break;
                  
                          case 1 :
                              // process 15 minute bars here
                              break;
                  
                          case 2 :
                  [SIZE=4][B]            // process 1 tick bars here[/B][/SIZE]
                              break;
                  
                      }
                  }[/FONT]
                  Could you also send us a copy of the code you are using to create data series?
                  Jessica P.NinjaTrader Customer Service

                  Comment


                    #10
                    I understand your time is valuable. The code in the bolded line should look like the below code. Please let us know if there are any other ways we can help.

                    Code:
                    [FONT=Courier New]
                    Print("The most recent price is " + Closes[2][0] + " and the last 15 minute bar's close price is " + Closes[0][0]);[/FONT]
                    Jessica P.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello,

                      my code looks something like.

                      protected override void OnBarUpdate()
                      {
                      switch(BarsInProgress)
                      {

                      case 0 :
                      // process primary bars here
                      break;

                      case 1 :
                      if(Opens[1][0]>Fib382 & Opens[0][0]<fib236)
                      {
                      EnterLong(1,25000,"MyOrder");
                      }

                      }
                      }
                      The issue is, I am not able to get the Open price of the 15 min bar. Primary tf=15 min. It returns the Open price of the previous candle because the current bar has not closed yet. While this may work live, it is failing miserably during backtest. Thanks

                      Comment


                        #12
                        Thank you MyFirstMillion. You are correct that Opens[1][0] will show the most recent bar's open price, rather than the building bar's. To get the building bar's price you will need to add a Tick series as discussed earlier, and take Opens[2][0] .
                        Jessica P.NinjaTrader Customer Service

                        Comment


                          #13
                          I have done exactly that. I have a tick series in my strategy but I do I figure out which Tick Open is the Open for 15 min bar?

                          Comment


                            #14
                            The building bar will open at the previous bar's close. The building bar's current close value will be identical to the 1-tick series close value. To get the high value of the building bar, assuming your tick series is at BarsArray == 2, you can use MAX(BarsArray[2], Bars.GetBar(Times[1][0]))[0]. You can use MIN in a similar way for the Low of the building bar.
                            Last edited by NinjaTrader_JessicaP; 02-28-2017, 01:31 PM.
                            Jessica P.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by usazencort, Today, 01:16 AM
                            0 responses
                            1 view
                            0 likes
                            Last Post usazencort  
                            Started by kaywai, 09-01-2023, 08:44 PM
                            5 responses
                            603 views
                            0 likes
                            Last Post NinjaTrader_Jason  
                            Started by xiinteractive, 04-09-2024, 08:08 AM
                            6 responses
                            22 views
                            0 likes
                            Last Post xiinteractive  
                            Started by Pattontje, Yesterday, 02:10 PM
                            2 responses
                            21 views
                            0 likes
                            Last Post Pattontje  
                            Started by flybuzz, 04-21-2024, 04:07 PM
                            17 responses
                            230 views
                            0 likes
                            Last Post TradingLoss  
                            Working...
                            X