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 Time Frame referencing.....

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

    Multi Time Frame referencing.....

    Howdy.

    I have downloaded and used the sample from THIS example.

    What I have is essentially a range chart, and this is my primary dataSeries. I have also added a 60 minute dataSeries, and synced it via sma.

    Then what I did, was take the Open from the 60 min dataSeries, and then plotted it on the chart to show that I am tracking it. You can see that in the pic below. The red horizontals lines show the Open from the secondary 60min chart.


    I will have other questions, but my first question is, how do you reference when a new secondary bar starts? I.e. each time a NEW hourly open starts, how do you say, "If secondary series starts again.....?" Here is a visual.


    Here is my basic script so far based on the example link I posted above:
    Code:
            #region Variables
    		private DataSeries secondaryOpen;
            #endregion
    
    
            protected override void Initialize()
            {
    			Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Dot, "Anchor"));
    			
    			Add(PeriodType.Minute, 60);
    			
                Overlay				= true;
    			CalculateOnBarClose = true;
            }
    
    
            protected override void OnBarUpdate()
            {
    			if (secondaryOpen == null)
    			{
    				/* Syncs another DataSeries object to the secondary bar object.
    				We use an arbitrary indicator overloaded with an IDataSeries input to achieve the sync.
    				The indicator can be any indicator. The DataSeries will be synced to whatever the
    				BarsArray[] is provided.*/
    				secondaryOpen = new DataSeries(SMA(BarsArray[1], 50));
    			}
    			
    			// Executed on secondary bar updates only
    			if (BarsInProgress == 1)
    			{
    				// Set the DataSeries object to store the trading range of the secondary bar
    				secondaryOpen.Set(Open[0]);
    			}			
    			
    			AnchorLine.Set(secondaryOpen[0]);
            }
    Attached Files

    #2
    I think I see how to get at the beginning of that. Posted in some arrows just to be sure that it is in fact printing at the beginning of the secondary series update. Placed the arrow in:

    Code:
    			if (BarsInProgress == 1)
    			{
    				// Set the DataSeries object to store the trading range of the secondary bar
    				secondaryOpen.Set(Open[0]);
    				DrawArrowUp("arrow"+CurrentBar, true, 0, Low[0]-12*TickSize, Color.Green);
    			}
    Attached Files

    Comment


      #3
      I am having a small problem now. I am simply trying to plot the OPEN of the secondary data series to my indicator.

      The problem I am seeing is that it is printing the open late, you can see in the picture it is printing way off to the right, where price isn't.

      Code:
              protected override void Initialize()
              {
      			Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Dot, "Anchor"));
      			
      			Add(PeriodType.Minute, 60);
      			
                  Overlay				= true;
      			CalculateOnBarClose = true;
              }
      
      
              protected override void OnBarUpdate()
              {	
      
      			
      			if (secondaryOpen == null)
      			{
      				secondaryOpen = new DataSeries(SMA(BarsArray[1], 50));
      			}
      
      			// Executed on secondary bar updates only
      			if (BarsInProgress == 1)
      			{
      				// Set the DataSeries object to store the trading range of the secondary bar
      				secondaryOpen.Set(Open[0]);
      				//DrawArrowUp("arrow"+CurrentBar, true, 0, Low[0]-12*TickSize, Color.Green);
      				//newHour = true;
      			}			
      			// Executed on primary bar updates only
      			if (BarsInProgress == 0)
      			{	
      				// Set DataSeries object to store the trading range of the primary bar
      			}				
      
      			AnchorLine.Set(secondaryOpen[0]);
      			
              }
      Attached Files

      Comment


        #4
        Looks like setting the bar index of the secondary series to "-1" may have given me the result I want? Even though it doesn't really make sense.


        Code:
                protected override void Initialize()
                {
        			Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Dot, "Anchor"));
        			
        			Add(PeriodType.Minute, 60);
        			
                    Overlay				= true;
        			CalculateOnBarClose = true;
                }
        
        
                protected override void OnBarUpdate()
                {	
        
        			
        			if (secondaryOpen == null)
        			{
        				secondaryOpen = new DataSeries(SMA(BarsArray[1], 50));
        			}
        
        			// Executed on secondary bar updates only
        			if (BarsInProgress == 1)
        			{
        				// Set the DataSeries object to store the trading range of the secondary bar
        				[COLOR="Red"]secondaryOpen.Set(Open[-1]);[/COLOR]
        				//DrawArrowUp("arrow"+CurrentBar, true, 0, Low[0]-12*TickSize, Color.Green);
        				//newHour = true;
        			}			
        			// Executed on primary bar updates only
        			if (BarsInProgress == 0)
        			{	
        				// Set DataSeries object to store the trading range of the primary bar
        			}				
        
        			AnchorLine.Set(secondaryOpen[0]);
        			
                }
        Attached Files

        Comment


          #5
          Forrestang,

          I am happy to assist.

          Negative indexing is not advised. I suspect allowing negative indices is a holdover from C/C++ for compatibility reasons. In C/C++ using negative indices is not advised as it can have unexpected results. Basically, in C/C++ you would actually be looking outside the array in memory, possibly grabbing any random number from a different process or application. I suspect its the same in C#.
          Last edited by NinjaTrader_AdamP; 10-17-2011, 07:12 AM.
          Adam P.NinjaTrader Customer Service

          Comment


            #6
            Adam,

            When using the Kinetick Free EOD data for stocks this is the only way I was able to get the data to correctly plot. On a daily chart using the monthly as a secondary series, I have to use [-1] on the monthly indicator to get the same indicator value that is displayed on monthly chart.

            Is there a better way?

            Comment


              #7
              Originally posted by TAJTrades View Post
              Adam,

              When using the Kinetick Free EOD data for stocks this is the only way I was able to get the data to correctly plot. On a daily chart using the monthly as a secondary series, I have to use [-1] on the monthly indicator to get the same indicator value that is displayed on monthly chart.

              Is there a better way?
              Thanks for posting your observation. I am experiencing something similar as described above. Not sure why it does this? I'm sure I am syncing the secondary series properly. But maybe there is another way to get the dataSeries working in sync.

              Comment


                #8
                Forrestang,

                I have been told by a colleague that negative indexing offers a way to "see into the future", and is unfortunately unsupported since it can cause unexpected issues. Obviously if the information doesn't exist you won't be able to access it, so its not really seeing into the future.

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

                Comment


                  #9
                  Thanks Adam.

                  That leaves me a bit confused?

                  If one wants to reference a different bar series added into a script, how would you go about doing it so that you can get at the correct sequence?

                  For example, in the example I posted, I added a hourly DataSeries to the study. Then initialized it in the onBarUpdate() with an SMA as in the example posted in the resource section.

                  At that point, when I go to reference the OPEN of the secondary 60Minute Series I added, it happens a full hour late. I am not sure why that occurs, or why my negative indexing seems to have fixed the problem?

                  It seems that say you have your secondary series that has an OPEN @ 0300 hours. Then say in onBarUpdate(), you simply print a line at the OPEN price you captured..... for some reason the actual secondary OPEN doesn't start printing for a full hour later.

                  In the attached picture, you can see this happening. The OPEN where I drew the orange arrow, the actual open of that 60 minute bar occurred an hour earlier than where it actually started.

                  Comment


                    #10
                    Forrestang,

                    I am not sure whats happening there since it looks a bit funny with range bars. However, if you look at minute bars it looks correct to me. I used your code without any negative indices. Let me look into these range bars further and Ill see if I can see what you mean on Kinetick and Kinetick EOD.
                    Attached Files
                    Adam P.NinjaTrader Customer Service

                    Comment


                      #11
                      It's a bit hard to explain, but that chart is off as well, so its not the range bars.

                      Essentially, the script is printing the opening price a full hour late. It should start printing that price as soon as the 60 minute bar opens, until it closes. But it actually doesn't begin printing that price until the bar closes.

                      I am sure there is a logical explanation for this, I'm just not seeing it.
                      Attached Files

                      Comment


                        #12
                        forrestang,

                        Ah-a! I see what you want now. Yes, I believe I can help.

                        The reason the -1 index worked is that it looked into the future for each hour and plotted the open backward in time so to speak. It only worked because a new hour bar was being generated and had a value for open. A graphic on how bars are constructed for multi-timeframe series is below.



                        Why not use :

                        Code:
                        if(BarsInProgress == 1)
                        {
                        	secondaryOpen.Set(Closes[0][0]);
                        }
                        Please let me know if I can assist further.
                        Last edited by NinjaTrader_AdamP; 10-17-2011, 11:49 AM.
                        Adam P.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_AdamP View Post

                          Why not use :

                          Code:
                          if(BarsInProgress == 1)
                          {
                          	secondaryOpen.Set(Closes[0][0]);
                          }
                          Please let me know if I can assist further.
                          Ah... Thank you sir! That was exactly the problem. I see there is an 'Opens', 'Highs' and 'Lows' as well!

                          Woot!

                          Comment


                            #14
                            Hmmmm.... Still having a few problems.

                            Ok, the first issue is just me wanting to plot the OPEN of the SECONDARY series on my chart.

                            It's plotting something, but it is never the open exactly, it's always off by a few pips for some reason?

                            Here is my onBarUpdate(), and also above of course I have added a second DataSeries of the secondary chart I am using.

                            Code:
                                    protected override void OnBarUpdate()
                                    {	
                            			
                            			if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired )
                                    		return;
                            
                            			
                            			if (secondaryOpen == null)
                            			{
                            				secondaryOpen = new DataSeries(SMA(BarsArray[1], 50));
                            
                            			}
                            			
                            			// Executed on secondary bar updates only
                            			if (BarsInProgress == 1)
                            			{
                            				secondaryOpen.Set(Opens[1][0]);		//To Line bars up using -1 not 0?
                            				//return;
                            			}	
                            			
                            			// Executed on primary bar updates only
                            			if (BarsInProgress == 0)
                            			{
                            				
                            			}
                            			AnchorLine.Set(secondaryOpen[0]);
                            
                                    }
                            Attached Files
                            Last edited by forrestang; 10-18-2011, 03:11 PM.

                            Comment


                              #15
                              Forrestang,

                              I would just use Closes[0][0] as the assignment.

                              Code:
                              if (BarsInProgress == 1)
                              {
                              	secondaryOpen.Set(Closes[0][0]);
                              }
                              It seems to be working for me, please see the attached image.
                              Attached Files
                              Adam P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by rocketman7, Today, 01:00 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post rocketman7  
                              Started by wzgy0920, 04-20-2024, 06:09 PM
                              2 responses
                              27 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, 04-23-2024, 09:53 PM
                              2 responses
                              74 views
                              0 likes
                              Last Post wzgy0920  
                              Started by Kensonprib, 04-28-2021, 10:11 AM
                              5 responses
                              193 views
                              0 likes
                              Last Post Hasadafa  
                              Working...
                              X