Go Back   NinjaTrader Support Forum > NinjaTrader 7 > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 01-12-2017, 01:48 AM   #1
poseidon_sthlm
Senior Member
 
Join Date: Aug 2009
Posts: 188
Thanks: 25
Thanked 8 times in 7 posts
Default MTF indicator calc. not in sync. with the right end of a chart?

Hello!
I have coded a multi TF indicator with a primary 5 min TF and a secondary 1 min TF. When I attach the indicator to a chart, the draw objects as well as print statments are drawn and printed at once for the entire data period until the end, before I begin scrolling the chart to the right. The same happens again if I "Reload NinjaScript". This is not the case for a single TF indicator. How can I make the MTF indicator calcuations in sync with the right end of the chart?

Best Regards,
Poseidon_Sthlm
Last edited by poseidon_sthlm; 01-12-2017 at 02:03 AM.
poseidon_sthlm is offline  
Reply With Quote
Old 01-12-2017, 07:18 AM   #2
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 10,119
Thanks: 736
Thanked 1,712 times in 1,648 posts
Default

Hello poseidon_sthlm,

Thank you for your post.

I am not sure I follow on what you are detailing. Could you provide a screenshot of this behavior?
To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.

Click here for instructions

Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

Click here for detailed instruction

I look forward to your response.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 01-12-2017, 08:00 AM   #3
poseidon_sthlm
Senior Member
 
Join Date: Aug 2009
Posts: 188
Thanks: 25
Thanked 8 times in 7 posts
Default

My question is very basic, but I can not catch this situation on a screenshot. The question is why NT does load the enitre historical data at once for a chart when adding a MTF indicator opposed to a single TF indicator and how can I prevent this?

Assume I open a 5 min chart with 100 days of historical data and scroll the chart to the very left so that only 1 day of data is visible on my chart. I then attach an (single TF) indicator with some draw objects and some print statments. The drawobjects will be drawn on the chart and the print statments will be printed in the output window for the first day that is displayed on my chart, but not for any of the next days. As I scroll my chart to the right, new draw objects and print statments will be added "in sync" with the timestamp for the right most bar on the chart, (until I have scrolled to end of the100 days of historical data).

BUT if I add an MTF indicator, then all draw objects and print statments for the 100 days of historical data will be added to the chart at once. Thus my scrolling will not trigger any new drawobjects or prints, since all possible drawobjects and prints already were drawn and printed from the start.

So how can I make the MTF indicator draw and print in sync with the right end of the chart when I scroll?
Last edited by poseidon_sthlm; 01-12-2017 at 10:01 AM.
poseidon_sthlm is offline  
Reply With Quote
Old 01-13-2017, 08:24 AM   #4
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 3,503
Thanks: 28
Thanked 914 times in 853 posts
Default

Hello poseidon_sthlm,

This sounds like a difference in how the indicators are programmed. By nature a indicator should load all data and the run from bar 0 to the total count of bars on the chart and then transition into realtime. The outcome of your single TF indicator sounds like a custom way of processing. To know why they perform differently you would need to look at the code and determine why they are different.

You could also make a duplicate of the indicator that works how you want, and then further modify the duplicate to maintain whatever structure is needed for the action you want.



I look forward to being of further assistance.
NinjaTrader_Jesse is offline  
Reply With Quote
Old 01-13-2017, 12:48 PM   #5
poseidon_sthlm
Senior Member
 
Join Date: Aug 2009
Posts: 188
Thanks: 25
Thanked 8 times in 7 posts
Default

Hello!
I have coded a simple as possible indicator to illustrate my issue . The indicator is attached below. If you add this indi to a 5 min chart and switch the parameter 'add1MinTF' between true/false you can se what I try to describe, both on the chart and in the output window.

How would I code this indicator to draw and print in sync with the right end of the chart when I scroll, in the same way that it does in 'single TF mode'?



Code:
 public class TestDrawMTF : Indicator
    {
       	/// Varaibles
		private bool add1MinTF			= false;			/// Parameter
		private double barCount			= 0.0;
		
		
        protected override void Initialize()
        {
			Overlay					= true;
			DrawOnPricePanel 		= false;
			CalculateOnBarClose 	= true;
			
			
			/// Add 1 min TF
			if (add1MinTF)
			{
				Add(PeriodType.Minute, 1);
			}
        }

		
        protected override void OnBarUpdate()
        {
			if (Bars == null) {return;}
			
			if ( BarsInProgress == 0 )
			{
				if ( CurrentBars[0] < 1 ) {return;}
				
				if ( !add1MinTF) {barCount += 1.0;}
				
				Print(CurrentBar + " | " + Time[0] + " | " + barCount);
				
				/// Since drawing methods are called for the entire historical data for MTF indicator, ....
				/// ...all drawobjects will be removed when the secondary 1 min TF is added (add1MinTF = true)
				if (Bars.FirstBarOfSession){RemoveDrawObjects();} 
				
				DrawText("BarCount" + CurrentBar, barCount.ToString(), 0, High[0] + TickSize, Color.Lime);	
			}
			else if ( BarsInProgress == 1 ) 
			{
				if ( CurrentBars[0] < 1 || CurrentBars[1] < 1 ) {return;}
				
				barCount += 1.0;
			}
        }

		
        /// Properties
        [Description("Add a secondary 1 min bar series")]
        [GridCategory("Parameters")]
        public bool Add1MinTF
        {
            get { return add1MinTF; }
            set { add1MinTF = value; }
        }
    }
Attached Files
File Type: zip TestDrawMTF.zip (1.9 KB, 1 views)
poseidon_sthlm is offline  
Reply With Quote
Old 01-13-2017, 03:20 PM   #6
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 3,503
Thanks: 28
Thanked 914 times in 853 posts
Default

Hello,

Thank you for the reply.

I am not certain what to tell you in regard to what needs to be changed, you would need to review the indicator that does the action you want to replicate that type of logic in your script. I really couldn't say what would be required as I am unsure what specific syntax was used in the indicator you are trying to copy.

Is the indicator you are trying to duplicate an open source indicator meaning you can view its code? If so you could just review its logic to duplicate it. If not, you would likely need to contact the developer of that item to see if they can explain what would be required to duplicate the existing system.

An indicator by default should run from bar 0 to the count of the chart and also process all historical data for added series as well. If you are trying to do a different action, you would need to create logic that does that action for you. It is possible the other item uses the Plot override as this would see the start and end index's of the bars on the chart, but this would just be a guess.

Additionally using dynamic secondary series as you have shown is not suggested as this is known to not work correctly.

if (add1MinTF)
{
Add(PeriodType.Minute, 1);
}

Items in initialize may not be refreshed unless you specifically remove and re add the script, pressing F5 or reloading the chart will likely not reload the data correctly while using this approach.

Instead you would need to just Add the secondary series, and in OnBarUpdate delegate which BarsInProgress is used depending on add1MinTF.


Please let me know if I may be of further assistance.
NinjaTrader_Jesse is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
NT 8.0.0.8 MTF AddChartIndicator does not show on chart correctly using MTF Timeframe rayko Version 8 Beta 4 01-20-2016 03:38 PM
Isolate beginning and ending time for indicator calc calhawk01 Indicator Development 8 09-03-2014 02:06 AM
Referenced MTF Indicator not Uppdated when Scrolling a Chart poseidon_sthlm Indicator Development 9 11-28-2012 12:33 PM
Converted indicator not working right with Calc on Bar Close set to False TheEminiTrader Indicator Development 1 04-13-2011 06:15 PM
Entry calc @ bar close trailing stop calc intrabar abarb26 Platform Technical Support 3 10-26-2009 04:26 AM


All times are GMT -6. The time now is 06:58 PM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content. Visit the CFTC resources for education regarding the industry and signs of fraud.