Go Back   NinjaTrader Support Forum > NinjaTrader 7 > Indicator Development

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

Thread Tools Display Modes
Old 05-07-2018, 08:27 AM   #1
Junior Member
Join Date: Apr 2011
Posts: 10
Thanks: 2
Thanked 0 times in 0 posts
Default MAcrossover plots wrong

I have developed a dashboard that looks at SMAs on upper timeframes (minute charts) to see trend of SMAs but when I plot the current chart SMAs (10 sec. in this case), it does not plot correctly. As a standalone indicator it works fine but I wanted to combine it into one indicator to also show the 3 higher timeframes. What am I missing??

Code for Panel 3 indicator which works fine:
if ((SMA(5)[0]>=SMA(15)[0]) && (SMA(15)[0]>=SMA(50)[0]))
BackColor = Color.Lime;
if ((SMA(5)[0]<SMA(15)[0]) && (SMA(15)[0]<SMA(50)[0]))
BackColor = Color.Red;

Code for Panel 2 indicator does not plot correctly as shown in pic:
protected override void Initialize()
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Block, "tF0"));
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Block, "uTF1"));
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Block, "uTF2"));
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Block, "uTF3"));
Add(PeriodType.Minute, timePeriod);
Add(PeriodType.Minute, timePeriod2);
Add(PeriodType.Minute, timePeriod3);
Plots[0].Pen.Width = 3;
Plots[1].Pen.Width = 3;
Plots[2].Pen.Width = 3;
Plots[3].Pen.Width = 3;
Overlay = false;
PaintPriceMarkers = false;

protected override void OnBarUpdate()
if (CurrentBar<200)

if ((SMA(BarsArray[1],5)[0])>=(SMA(BarsArray[1],15)[0]) &&
PlotColors[0][0] = upColor;
else if ((SMA(BarsArray[1],5)[0])<(SMA(BarsArray[1],15)[0]) &&
PlotColors[0][0] = downColor;

if ((SMA(BarsArray[2],5)[0])>=(SMA(BarsArray[2],15)[0]) &&
PlotColors[1][0] = upColor;
else if ((SMA(BarsArray[2],5)[0])<(SMA(BarsArray[2],15)[0]) &&
PlotColors[1][0] = downColor;

if ((SMA(BarsArray[3],5)[0])>=(SMA(BarsArray[3],15)[0]) &&
PlotColors[2][0] = upColor;
else if ((SMA(BarsArray[3],5)[0])<(SMA(BarsArray[3],15)[0]) &&
PlotColors[2][0] = downColor;

if ((SMA(5)[0])>=(SMA(15)[0]) && (SMA(15)[0])>=(SMA(50)[0]))
PlotColors[3][0] = upColor;
else if ((SMA(5)[0])<(SMA(15)[0]) && (SMA(15)[0])<(SMA(50)[0]))
PlotColors[3][0] = downColor;

tF0.Set(3); //plots on top
uTF3.Set(0); //plots on bottom
Attached Images
File Type: png MAcrossoverDashboard.png (86.5 KB, 4 views)
MBAGearhead is offline  
Reply With Quote
Old 05-07-2018, 08:54 AM   #2
NinjaTrader Customer Service
NinjaTrader_Jesse's Avatar
Join Date: Mar 2014
Location: Denver, CO
Posts: 5,064
Thanks: 30
Thanked 1,291 times in 1,209 posts


Thank you for the post.

In this case, this would likely not be enough information to know what specifically is different that is causing the "noise". However, I can say that adding more series will alter the way OnBarUpdate is called which could potentially be related to what you are seeing. For this question, you would likely need to use prints to see if the logic is still being executed the same as your original indicator.

One possiblilty would be surrounding your syntax in a BarsInProgress check for the primary series:

if(BarsInProgress == 0)
//insert existing logic here

If the original indicator and this indicator work on the same primary series, this may be the difference you are seeing or that the added second series are also calling OnBarUpdate which the original would not have had occurred.

I would likely suggest reducing the chart data to a small number of bars, but enough for the indicator to produce values. After doing this, add Prints into OnBarUpdate in both the original indicator and the new indicator. Then run each in a test and take the output from each and compare it. This can tell you if your values are the same and also if the script is logically working the same.

I look forward to being of further assistance.
NinjaTrader_Jesse is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Jesse for this post:
Old 05-07-2018, 09:09 AM   #3
Junior Member
Join Date: Apr 2011
Posts: 10
Thanks: 2
Thanked 0 times in 0 posts
Thumbs up

Thanks Jesse!!
Figured it was something simple.
Sure enough adding the below check did the trick!!

if(BarsInProgress == 0)
//insert existing logic here
MBAGearhead is offline  
Reply With Quote

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
NT8 plots more thick than NT7 plots fx.practic Version 8 Beta 2 08-23-2016 07:32 AM
MACrossOver using EntryLimit Orders, Targets and Stops kenb2004 Strategy Development 18 06-27-2011 12:52 PM
sample MAcrossover strategy have it turn 10am? mitwave00 Strategy Development 3 06-13-2011 10:56 AM
Hiding plots from Plots section eDanny Indicator Development 4 04-15-2009 12:14 PM
Plots[?].Min & Plots[?].Max Don't work AlohaBob Indicator Development 6 01-06-2007 09:31 PM

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