NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 01-23-2009, 12:10 PM   #1
rurimoon
Junior Member
 
Join Date: Nov 2008
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
Default DrawDot

How to make DrawDot works with CalculateOnBarClose=false ?

Let say I add these 2 line at the end of MACD code in OnBarUpdate()

if (Diff[0] > 0) DrawDot("dot" + CurrentBar, false, 0, 0, Color.Blue);
else if (Diff[0] < 0) DrawDot("dot" + CurrentBar, false, 0, 0, Color.Red);

It just draw a blue/red dot on the zeroline when cross. It works fine with CalculateOnBarClose=True, but everything stop working when set to false. I think it is because it try to redraw the dot on the same place that is causing the problem. How do I fix it.
rurimoon is offline  
Reply With Quote
Old 01-23-2009, 12:32 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Please elaborate more on what you mean by "stop working".

Your code does not generate unique string IDs for your objects when you have CalculateOnBarClose = false. It will just keep moving the original dot around. Only at the beginning of a new bar will a new dot be drawn.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-23-2009, 12:55 PM   #3
rurimoon
Junior Member
 
Join Date: Nov 2008
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
Default

Here is the image. I use ZeroLagMACD instead since I don't want to mess around with @MACD indicator. But they are basically same thing. I only add 3 lines of code.

Inside Initialize()
DrawOnPricePanel = false;

Inside OnBarUpdate()
if (Diff[0] > 0) DrawDot("dot" + CurrentBar, false, 0, 0, Color.Blue);
else if (Diff[0] < 0) DrawDot("dot" + CurrentBar, false, 0, 0, Color.Red);

Notice the top MACD has CalculateOnBarClose set to false at 1:44pm


rurimoon is offline  
Reply With Quote
Old 01-23-2009, 01:18 PM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

It suggests to me your code is not working anymore. Please take a look at the MACD lines. They flat line. This looks like a potential bug on your ZeroLagMACD as a whole. You will want to check the Control Center logs for errors and will have to debug the ZeroLagMACD as it uses CalculateOnBarClose = false settings.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-23-2009, 05:06 PM   #5
rurimoon
Junior Member
 
Join Date: Nov 2008
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
Default

Great! It took me an hour to find out that the DrawDot is not casuing the problem. Then another hour to find out that the ZeroLagMACD is not the problem neither and it is actually ZeroLagEMA that cause the problem. Then it took me another hour to find out what's wrong with ZeroLagEMA. And it was merely this statement: CalculateOnBarClose = true;

Yes, ZeroLagEMA hardcoded the default to true. It has to do with nesting I guess. Calling indicator of an indicator while one is set to true while one is set to false produced wired result. My problem go away when I deleted this line from ZerolagEMA.

I think this bug need to be fix. The CalculateOnBarClose setting for the calling indicator should override the setting for the called indicator.
rurimoon is offline  
Reply With Quote
Old 01-24-2009, 08:35 AM   #6
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Right. It is a known bug with nested CalculateOnBarCloses.
NinjaTrader_Josh 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
DrawDot() NinjaTrader_Josh Indicator Development 9 03-26-2008 07:51 AM
DrawDot Or DrawTriangleUp etc... only outputting on last bar scriabinop23 Indicator Development 2 01-22-2008 03:52 PM


All times are GMT -6. The time now is 09:27 PM.