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

using multiple time frame without affecting primary chart

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

    using multiple time frame without affecting primary chart

    I would like to reference an indicator based on a different time frame from the primary time frame of the chart. By 'reference', I mean a simple "If >=" or "true/false" condition using that indicator and time frame. If I simply add an additional series, it ruins the chart due to the spacing problem. Is there a way to calculate an indicator using a different time frame without plotting it or otherwise affecting the chart?

    Thanks.

    #2
    Hello billr,

    This would be possible by creating a new Indicator with some custom code. For example if you are using the SMA on the 5 minute chart you can start by creating a new indicator with the original code from another indicator. To do this go the Control Center -> Tools -> Edit NinjaScript -> Indicators. Then double left click on the indicator that you want to have the original code from for example the "SMA". It will then open up the source code for the indicator. Right click inside the window and select Save As. Type in a name of your choosing then press "Save". Press the "OK" button. Now you have a new indicator based off the system indicator code that you can modify to have a multi-time frame. For example to Add() a 1 minute time frame to a 5 minute chart:

    Code:
    protected override void Initialize()
    {
            // Add a 1 minute Bars object: BarsInProgress index = 1
            Add(PeriodType.Minute, 1);		
    }
    
    protected override void OnBarUpdate()
    {
             // 1 minute chart. 
             // Do something within the context of the 1 minute Bars here
    	if(BarsInProgress ==1 )
    	{
    		//do something
    	}
    }
    Here is a link to our Support Forums post that goes over a Data Series object with a secondary time frame.
    http://www.ninjatrader.com/support/f...ead.php?t=3572


    You may also read more on Multi-Time Frame and instruments on our online help guide at the following link.
    http://www.ninjatrader.com/support/h...nstruments.htm


    Please let me know if I can be of further assistance.
    Last edited by NinjaTrader_JC; 07-13-2012, 02:16 PM.
    JCNinjaTrader Customer Service

    Comment


      #3
      There is a sample indicator here that calculates the SMA from a different bars than the bars shown on the chart. The primary reason that I have coded it, is to avoid spoiling the chart via non-equidistant bar spacing.

      The indicator can be downloaded here (membership required):

      The best futures trading community on the planet: futures trading, market news, trading charts, trading platforms, trading strategies


      Or send me a private message with your e-mail and I will send it to you. It is not an easy piece of code and I have therefore locked the code. The indicator is available for free.

      Comment


        #4
        Thanks Harry. I will take a look. I'm sure it will be quite helpful.
        I am trying to do this for the same reasons you cite in your BMT post.
        I am a member of BMT, so I can access that section.
        Very kind of you to take the time to resond.
        Bill

        Comment


          #5
          Actually there are three different options to deal with the problem.

          (1) add a secondary bar series via indicator, calculate values from the secondary bars and display indicators on chart for primary bars

          (2) calculate synthetic higher timeframe bars from the lower time frame bars, in this case you would collect the open, high, low and close from N consecutive bars and store them in an array, and then access the array to calculate indicator values

          (3) skip step (2) by tweaking the indicator values directly without creating those synthetic bars, for example if you code an SMA you can simply increase the indicator period by a factor N, if you code an EMA you can replace the smoothing constant k = 1/(2n+1) with a new smoothing constant k' = 1 - Math.Power(1-k, 1/N) and you are done. Both values give an excellent approximation, and at the same time you will be able to solve the problem of the unstable period, which covers up to N bars with the solution 2, but only 1 bar when you tweak the indicators

          Send me a private message via BigMike's (or here), if you have any further questions.

          Harry

          Originally posted by billr View Post
          Thanks Harry. I will take a look. I'm sure it will be quite helpful.
          I am trying to do this for the same reasons you cite in your BMT post.
          I am a member of BMT, so I can access that section.
          Very kind of you to take the time to resond.
          Bill

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CortexZenUSA, Today, 12:53 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by CortexZenUSA, Today, 12:46 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by usazencortex, Today, 12:43 AM
          0 responses
          2 views
          0 likes
          Last Post usazencortex  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          168 responses
          2,263 views
          0 likes
          Last Post sidlercom80  
          Started by Barry Milan, Yesterday, 10:35 PM
          3 responses
          11 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X