Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Indicator Development

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

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 02-02-2017, 11:18 PM   #1
ds1111
Senior Member
 
Join Date: Sep 2011
Location: Chicago
Posts: 107
Thanks: 17
Thanked 11 times in 11 posts
Default Draw.TextFixed in indicator not diplayed by strategy

Ok, another code migration from NT 7 and NT 8 and difference in behavior.

In my NT 7 indicator code I had the following code to display the 'settings' in the Bottom Left of the chart:
protected override void OnStartUp()
{
infoText = " indicators settings list"
DrawTextFixed("IndicatorParameters", infoText, TextPosition.BottomLeft, Color.Gray, new Font("Arial",8,FontStyle.Bold), Color.Black, Color.Black, 15);

}

when I called the indicator from the strategy I had the settings always displayed in the charts so I always know which settings are being used by the strategy.

In my NT 8 indicator code I have the following:

... else if (State == State.DataLoaded)
{
infoText = " indicators settings list"
Draw.TextFixed(this, "IndicatorParameters", infoText, TextPosition.BottomLeft);
}


What is happening is that now the strategy calling the code above is not displaying the settings (infoText) in the chart anymore. The indicator shows infoText, but the strategy calling the indicator does not. The strategy is calling the indicator correctly and working correctly, but the 'infoText" is not being displayed anymore.
Can you let me know what am I doing wrong?

Thanks!
ds1111 is offline  
Reply With Quote
Old 02-03-2017, 12:25 AM   #2
sledge
Senior Member
 
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 4,501
Thanks: 1,690
Thanked 1,099 times in 942 posts
Default

Where did you add the strategy? The chart or control center?
sledge is offline  
Reply With Quote
Old 02-03-2017, 12:27 AM   #3
ds1111
Senior Member
 
Join Date: Sep 2011
Location: Chicago
Posts: 107
Thanks: 17
Thanked 11 times in 11 posts
Default

The chart.
ds1111 is offline  
Reply With Quote
Old 02-03-2017, 06:44 AM   #4
NinjaTrader_Paul
NinjaTrader Customer Service
 
NinjaTrader_Paul's Avatar
 
Join Date: May 2014
Posts: 4,057
Thanks: 425
Thanked 1,056 times in 1,013 posts
Default

Hello ds1111,

Thanks for your post.

Try moving the Draw.Text() to the OnBarUpdate() method.

Something like:

if (CurrentBar == 0)
{
Draw.Text(....
}
NinjaTrader_Paul is offline  
Reply With Quote
Old 02-03-2017, 04:34 PM   #5
ds1111
Senior Member
 
Join Date: Sep 2011
Location: Chicago
Posts: 107
Thanks: 17
Thanked 11 times in 11 posts
Default

I moved the 'infotext' code to the "OnBarUpdate" method of the indicator using the CurrentBar == 0 as you described.

The strategy still doesn't display 'infotext'.

I still don't like this approach (besides not working) because I like to avoid unnecessary checks under OnBarUpdate as I run most strategies on each tick.

What is the equivalent of OnStartUp() on NT 8?
When the strategy calls the indicator (and of course I added the indicator in the strategy using AddChartIndicator) isn't the (State == State.DataLoaded) structure in the indicator called?
In NT 7 when I called my indicator from the strategy, OnStartUp() was executed and infoText was displayed.
I'm trying to understand why the same behavior is not seen on NT 8.
ds1111 is offline  
Reply With Quote
Old 02-06-2017, 07:34 AM   #6
NinjaTrader_Paul
NinjaTrader Customer Service
 
NinjaTrader_Paul's Avatar
 
Join Date: May 2014
Posts: 4,057
Thanks: 425
Thanked 1,056 times in 1,013 posts
Default

Hello ds1111,

Thanks for your reply.

What version of NinjaTrader8 are you using? (found in Help>about)

If you run the indicator standalone, does it display infotext as expected?

Do you see any error messages in the NinjaTrader control center's "Log" tab related to the strategy or indicator?
NinjaTrader_Paul is offline  
Reply With Quote
Old 02-06-2017, 08:47 PM   #7
ds1111
Senior Member
 
Join Date: Sep 2011
Location: Chicago
Posts: 107
Thanks: 17
Thanked 11 times in 11 posts
Default

This is the version: 8.0.4.0 64-bit

And yes, it displays infotext when using the indicator alone. When I add the indicator in the strategy as I used to do in NT 7 it doesn't display anymore.

There are no errors on the log. As I said, the strategy works as expected.

What is the equivalent of "OnStartUp" on NT 8?

Thanks.
ds1111 is offline  
Reply With Quote
Old 02-07-2017, 09:59 AM   #8
NinjaTrader_Paul
NinjaTrader Customer Service
 
NinjaTrader_Paul's Avatar
 
Join Date: May 2014
Posts: 4,057
Thanks: 425
Thanked 1,056 times in 1,013 posts
Default

Hello ds1111,

Thanks for your reply.

Yes, NT7s OnStartUp() would be State.DataLoded in NT8. Please see: http://ninjatrader.com/support/helpG..._practices.htm

Can you provide a small example of the code you are using that is not providing the information you are looking to display?

Alternatively, if you would prefer, feel free to write into PlatformSupport[at]Ninjatrader[dot]com with your source files and mark the e-mail atten:Paul and a link to this thread.
NinjaTrader_Paul is offline  
Reply With Quote
Old 02-07-2017, 10:25 PM   #9
ds1111
Senior Member
 
Join Date: Sep 2011
Location: Chicago
Posts: 107
Thanks: 17
Thanked 11 times in 11 posts
Default

The code in the indicator is in my first post.

The code in the strategy is as follows:
-----------------------------
... else if (State == State.DataLoaded) // add indicators
{

PivotIndicatorC = PivotC(indicator_setting_1, indicator_setting_2, etc);
AddChartIndicator(PivotIndicatorC);


}
-----------------------------


The indicator is receiving the correct setting list to be displayed in infotext, because the strategy works fine. It seems that "Draw.TextFixed(this, "IndicatorParameters", infoText, TextPosition.BottomLeft); " in the indicator fails when called from the strategy for some reason. Could it be because of the owner "this"?

Any suggestion? Again, this code worked perfectly on NT 7.

An easy way to reproduce would be to create an indicator called mySMA, code Draw.TextFixed to print the period, and then code a strategy to call mySMA and see if Draw.TextFixed would print the period on the chart. I didn't have time to do that, but I may do that tomorrow if you don't have any suggestions meanwhile. It seems to be a bug with Draw.TextFixed rendering.
ds1111 is offline  
Reply With Quote
Old 02-08-2017, 10:39 AM   #10
NinjaTrader_Paul
NinjaTrader Customer Service
 
NinjaTrader_Paul's Avatar
 
Join Date: May 2014
Posts: 4,057
Thanks: 425
Thanked 1,056 times in 1,013 posts
Default

Hello ds1111,

Thanks for your reply.

I followed your directions and repeated the results you have observed where DrawTextFixed does not display. However, if you move the DrawTextFixed() in the indicator into the OnbarUpdate() section it will work.

Indicator code:
Code:
			else if (State == State.Configure)
			{
				priorSum	= 0;
				sum			= 0;
			}
//			else if (State == State.DataLoaded)
//			{
//				infoText = Period.ToString();
//				Draw.TextFixed(this, "IndicatorParameters", "Test: "+infoText, TextPosition.BottomLeft);							
//			}

		}

		protected override void OnBarUpdate()
		{
			if (CurrentBar == 0)
			{
				infoText = Period.ToString();
				Draw.TextFixed(this, "IndicatorParameters", "Test: "+infoText, TextPosition.BottomLeft);							
			}

Strategy code:

Code:
			else if (State == State.Configure)
			{
				testSMA = mySMA(21);
			}
			else if (State == State.DataLoaded)
			{
				AddChartIndicator(testSMA);
			}
			
		}

		protected override void OnBarUpdate()
		{
Attached Images
File Type: png ds1111-1.PNG (18.2 KB, 3 views)
NinjaTrader_Paul is offline  
Reply With Quote
Old 02-08-2017, 01:02 PM   #11
ds1111
Senior Member
 
Join Date: Sep 2011
Location: Chicago
Posts: 107
Thanks: 17
Thanked 11 times in 11 posts
Default

Thanks for doing this, I really appreciate.

I find this odd and inefficient. I need this check just at start up, I don't need it for every tick doing it at OnBarUpdate.

Is there another way to do this? maybe on state=historical? That also seems to imply that DataLoaded is not the same as "OnStartup" on NT 7. Can you check with your engineers?

In the end I'm finding the new state implementation much harder than the simple NT 7 implementation using Initialize, etc. In all the upgrades of code that's where I'm finding the most problems. I hope a great guideline comes out comparing both architectures (NT 7 and NT 8).

Thanks again.
ds1111 is offline  
Reply With Quote
Old 02-08-2017, 02:10 PM   #12
NinjaTrader_Paul
NinjaTrader Customer Service
 
NinjaTrader_Paul's Avatar
 
Join Date: May 2014
Posts: 4,057
Thanks: 425
Thanked 1,056 times in 1,013 posts
Default

Hello,

Thanks for your reply.

While I used if(CurrentBar==0) you do not have to use that as what is important for you is that when your strategy starts that your indicator information appear. You might look at other areas of your code where you are already performing a check of some type and add in your drawtext statement. For example does your code do a minimum current bars check? If so, you can easily add your statement there.

If you like I could write up a feature request to add the ability to use DrawText from OnStateChange().

If you haven't already reviewed, here are a few links that may help on NT8:
http://ninjatrader.com/support/helpG...tatechange.htm
http://ninjatrader.com/support/helpG...fecycle_of.htm
http://ninjatrader.com/support/helpG...ng_changes.htm
NinjaTrader_Paul is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Paul for this post:
Old 07-20-2018, 06:44 AM   #13
JMont1
Member
 
Join Date: Jun 2011
Location: Long Island, NY
Posts: 52
Thanks: 24
Thanked 5 times in 5 posts
Default DrawTextFixed in Strategy kills Strategy Analyzer

@NinjaTrader_Paul ,

Trying to do a simple Drawtextfixed in STRATEGY AND have Strategy Analyzer backtest.

Draw works fine in the if(currentbar==0) for printing on chart.


BUT Strategy Analyzer fails doing the back testing. I had also been successful putting the DrawTextFixed in various other place like onbarupdate. Unfortunately even placing there kills the strategy analyzer.

When code is in the strategy - no backtest works, comment the line and the analyzer works.

It seems to be such as minor item to do a draw text in a strategy -- can you help?


UPDATE UPDATE UPDATE:

My final effort is looking to place the Draw.Text within if statements BUT for now I just want Draw.Text to work and not kill the strategy Analyzer. So only using this basic line of code:

Draw.TextFixed(this, "strategyAccountName", "" + Account.Name + " IS SIM" + ".", TextPosition.Center, ChartControl.Properties.ChartText, myFont, Brushes.Blue, Brushes.Transparent, 0); // S/A NOT WORKING

Went back through this thread and again tried placing it:

if (State == State.SetDefaults)
if (State == State.Configure)
if( State == State.DataLoaded ) WHERE SUGGESTED IN THREAD
if (State == State.Historical)
protected override void OnBarUpdate()
protected override void OnMarketData(MarketDataEventArgs e)


Strategy Analyzer woks if placed here But then the Draw.Text is not drawn
if (State == State.Terminated)


Once I find a place to do a Draw.TextFixed AND Strategy Analyzer works the actual code I hope to use which includes a bool:

#region Acct Posting

if ((ACCTnamed == true) || (Account.Name == "Sim101"))
{
Draw.TextFixed(this, "strategyAccountName", "" + Account.Name + " IS SIM" + ".", TextPosition.Center, ChartControl.Properties.ChartText, myFont, Brushes.Blue, Brushes.Transparent, 0);
}

else
if (ACCTnamed == true)
{
Draw.TextFixed(this, "strategyAccountName", "" + Account.Name + ".", TextPosition.Center, ChartControl.Properties.ChartText, myFont, Brushes.Blue, Brushes.Transparent, 0);
}

#endregion


Thank you for your assistance.
Last edited by JMont1; 07-21-2018 at 12:01 PM.
JMont1 is offline  
Reply With Quote
Old 07-23-2018, 07:29 AM   #14
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,943
Thanks: 30
Thanked 1,263 times in 1,181 posts
Default

Hello JMont1,

Thank you for the reply.

The problem here is that you are referencing properties of the chart when it is not present and creating an error situation which stops the analyzer. If you plan to use the ChartControl you need to ensure to check if it is null or not, I do not see you have done this in the sample you provided.

Code:
ChartControl.Properties.ChartText
ChartControl is null when you run the backtest, and is only available when a regular chart tab is opened and the script is processed. To avoid the problem, you should either check if ChartControl == null to use a backup brush, or just avoid using ChartControl and use defined brushes or input brushes.

Code:
Brush chartText = Brushes.Red;
if (ChartControl != null)
{ 
    chartText = ChartControl.Properties.ChartText; 
}
Draw.TextFixed(this, "strategyAccountName", "" + Account.Name + ".", TextPosition.Center, chartText, new SimpleFont(), Brushes.Blue, Brushes.Transparent, 0);
I look forward to being of further assistance.
Last edited by NinjaTrader_Jesse; 07-23-2018 at 07:31 AM.
NinjaTrader_Jesse is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Jesse for this post:
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
Draw.TextFixed Question CriticalTrader Version 8 Beta 11 06-01-2016 07:26 AM
Draw.TextFixed()... funk101 Version 8 Beta 1 04-21-2016 07:04 AM
Draw.TextFixed, TextAlignment TheBarChartist Version 8 Beta 2 10-27-2015 08:10 AM
Draw.TextFixed() Issue Omega Version 8 Beta 17 08-25-2015 01:51 PM
Draw.TextFixed when Enabled from Strategy Grid wuileng Version 8 Beta 9 05-28-2015 07:36 AM


All times are GMT -6. The time now is 01:32 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.