NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Sunday May 26th at 12PM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

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

Reply
 
Thread Tools Display Modes
Old 06-17-2009, 02:36 AM   #1
saltminer
Senior Member
 
Join Date: Apr 2008
Posts: 164
Thanks: 2
Thanked 3 times in 3 posts
Default BUG, replicatable, in attached Indicator

Hi Ninja guys,
I have a bug for you. It was driving me absolutely nuts in developing an indicator, until I realised it was a bug and not my coding.
I have written a simplified indicator which does nothing other than demonstrate the bug (attached).
I have also pasted the code below for a quick look-see while you read this post.
The bug is that when writing a value to a plot intra-bar, on the next tick of the same bar the data has been thrown away. Instead of the data, the Plot1[0] now contains the latest closing price of the instrument, and Plot1.ContainsValue(0) shows as FALSE.
In the attached indicator, you will see I write to the indicator's plot with
Plot1.Set(...value...)
Then I Print() to the Output Window the value I just wrote (by reading it back from Plot1[0]) and also Print() Plot1.ContainsValue(0). Results are as they should be; I get the correct value back and a boolean value of TRUE.
NEXT TICK, though, the value is corrupted and the boolean value is FALSE.

Please tell me if you can replicate the bug at your end.
I re-installed NinjaTrader this afternoon, deleting my user's data folder as well. I re-installed .Net only a fortnight ago. I am on Vista, fully up to date.
saltminer.

protected override void OnBarUpdate()
{

if (Close[0] != LastPrice)
{ // this is just a simple technique to occasionally write a value to a plot intra-bar
LastPrice = Close[0];
PriceChangeCount++;
if (PriceChangeCount <10)
return;

PlotSomeValue(); // write to the plot in a Method
PriceChangeCount = 0;

}

// each tick, display what is in the plot
Print("At bar "+CurrentBar+", Tick by tick check: Value is "+Plot1[0]+" and ContainsValue is "+Plot1.ContainsValue(0));
}

private void PlotSomeValue()
{
Plot1.Set(CurrentBar); // just put some value in here
// prove its in by reading the value back
Print("At bar "+CurrentBar+", Value of "+CurrentBar+" written to Plot1... Reading back, value is "+Plot1[0]+" and ContainsValue is "+Plot1.ContainsValue(0));

Plot2.Set(SMA(Plot1,20)[0]); // and generate a second plot that is a moving average of the first
}
Attached Files
File Type: zip JRIndicatorBugTest.zip (3.7 KB, 3 views)
saltminer is offline  
Reply With Quote
Old 06-17-2009, 06:53 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

saltminer, thanks for this detailed posting, we'll look into it and get back to you.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 06-17-2009, 09:31 AM   #3
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

saltminer, please don't do the plotting in your own functions, use the OnBarUpdate() directly please and retry.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 06-17-2009, 07:14 PM   #4
saltminer
Senior Member
 
Join Date: Apr 2008
Posts: 164
Thanks: 2
Thanked 3 times in 3 posts
Default

Hello,
ok, I've changed the plotting function to be inside of the OnBarUpdate() method. I can't see what difference that should make - are we really not allowed to access plot data in a custom Method called from OnBarUpdate? Is that in the manual?
Anyway, it made no difference. The bug still stands.
I have attached the revised indicator for your testing. Code is pasted below, and also the print from my Output Window which shows intra-bar on bar 14299 that
(1) the value written to the Plot disappears and is replaced by the latest price of the instrument.
(2) Plot1.ContainsValue() changes from TRUE to FALSE

saltminer.


At bar 14299, Tick by tick check: Value is 944.75 and ContainsValue is False
At bar 14299, Value of 14299 written to Plot1... Reading back, value is 14299 and ContainsValue is True
At bar 14299, Tick by tick check: Value is 14299 and ContainsValue is True
At bar 14299, Tick by tick check: Value is 944.75 and ContainsValue is False
At bar 14299, Tick by tick check: Value is 944.75 and ContainsValue is False
At bar 14299, Tick by tick check: Value is 944.5 and ContainsValue is False


protected override void OnBarUpdate()
{

if (Close[0] != LastPrice)
{ // this is just a simple technique to occasionally write a value to a plot intra-bar
LastPrice = Close[0];
PriceChangeCount++;
if (PriceChangeCount <10)
return;

Plot1.Set(CurrentBar); // just put some value in here
// prove its in by reading the value back
Print("At bar "+CurrentBar+", Value of "+CurrentBar+" written to Plot1... Reading back, value is "+Plot1[0]+" and ContainsValue is "+Plot1.ContainsValue(0));

Plot2.Set(SMA(Plot1,20)[0]); // and generate a second plot that is a moving average of the first

PriceChangeCount = 0; // reset count
}

// each tick, display what is in the plot
Print("At bar "+CurrentBar+", Tick by tick check: Value is "+Plot1[0]+" and ContainsValue is "+Plot1.ContainsValue(0));
}
Attached Files
File Type: zip JRIndicatorBugTestRevised.zip (3.7 KB, 4 views)
saltminer is offline  
Reply With Quote
Old 06-18-2009, 09:47 AM   #5
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

saltminer, thanks for the detailed post, could not reproduce this on my end, please check this simple sample, intrabar plotted values will stick even if conditions are not true anymore.
Attached Files
File Type: zip testDataSeriesValueSticks.zip (1.7 KB, 2 views)
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 06-18-2009, 08:16 PM   #6
saltminer
Senior Member
 
Join Date: Apr 2008
Posts: 164
Thanks: 2
Thanked 3 times in 3 posts
Default

Hi Bertrand,
unfortunately your indicator script is not valid to test this bug.
Once a condition on a bar becomes true (High[0] > High[1]) it will remain true for the rest of the bar, so data will be written to the DataSeries every tick until the end of the bar.
You are not testing what happens on subsequent ticks on the same bar when data is NOT re-written to the DataSeries.
I have amended your indicator to use Close[0] > High[1], and Close[0] < Low[1]. This creates the opportunity for the bug to arise, which indeed it still does on my machine.
Here is a copy/paste from my Output Window
555 -1 True
555 -1 True
555 -1 True
555 941.25 False

Same bar, yet the value reverts to the closing price of the instrument and ContainsValue changes back to false.
Please import my revision to your indicator (or change your own) and retry.
Thanks,
saltminer
Attached Files
File Type: zip TestDataSeriesValueSticksRevised.zip (1.7 KB, 4 views)
saltminer is offline  
Reply With Quote
Old 06-19-2009, 05:59 AM   #7
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

Thanks Saltminer, I'll give it a go and check on my end.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 06-19-2009, 06:09 AM   #8
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

Saltminer, unfortunately I can't reproduce this here on a 49 tick chart of the September ES - Plot contains and stores the dataseries value until the new bar forms which is the expected outcome. If the condition is false you see the dummy value in the print out until the conditions hits again.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 06-19-2009, 06:50 PM   #9
saltminer
Senior Member
 
Join Date: Apr 2008
Posts: 164
Thanks: 2
Thanked 3 times in 3 posts
Default

Hi Bertrand,
after your last post I began to wonder if it was something strange in my system. So I tried it on a different machine, this time running XP (my primary machine runs Vista).
Different Ninja install, obviously, and it has no fancy custom assemblies or anything on it. Everything is pretty much fresh-as-a-daisy.

I still see the bug occuring.

I have modified the indicator for you, to further help illustrate the bug.
First of all, please set your chart's timeframe to something longer than 49 tick. What you need to see using this indicator is a bar that achieves a higher high or lower low then retraces back inside the prior bar's range. Give it some time to do that, eg use a 610 tick.
Note that it must be in realtime, not Historical data.
The new version of the indicator keeps a record if it has written a value to the plot on this bar. If it has, and ContainsValue() returns false, it will write a very visible message to the OutputWindow and color the bar Pink on the chart. You can't miss it.

Please check it out one more time.
Thanks,
saltminer
Attached Files
File Type: zip TestDataSeriesValueSticksVer3.zip (1.9 KB, 5 views)
saltminer is offline  
Reply With Quote
Old 06-20-2009, 05:59 PM   #10
NinjaTrader_ChristopherJ
NinjaTrader Customer Service
 
NinjaTrader_ChristopherJ's Avatar
 
Join Date: Feb 2009
Location: Denver, CO
Posts: 3,815
Thanks: 32
Thanked 135 times in 135 posts
Default

Quote:
Originally Posted by saltminer View Post
Hi Bertrand,
after your last post I began to wonder if it was something strange in my system. So I tried it on a different machine, this time running XP (my primary machine runs Vista).
Different Ninja install, obviously, and it has no fancy custom assemblies or anything on it. Everything is pretty much fresh-as-a-daisy.

I still see the bug occuring.

I have modified the indicator for you, to further help illustrate the bug.
First of all, please set your chart's timeframe to something longer than 49 tick. What you need to see using this indicator is a bar that achieves a higher high or lower low then retraces back inside the prior bar's range. Give it some time to do that, eg use a 610 tick.
Note that it must be in realtime, not Historical data.
The new version of the indicator keeps a record if it has written a value to the plot on this bar. If it has, and ContainsValue() returns false, it will write a very visible message to the OutputWindow and color the bar Pink on the chart. You can't miss it.

Please check it out one more time.
Thanks,
saltminer
Hello saltminer,


I am forwarding your reply to NinjaTrader_Bertrand and you will receive a response prior to the market open on Monday.

Thank you for your patience and have a great weekend!
NinjaTrader_ChristopherJ is offline  
Reply With Quote
Old 06-22-2009, 07:47 AM   #11
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

saltminer thanks for the amended code, I'll recheck on a bigger timeframe chart on a different PC and let you know what I find, thanks for your efforts.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 06-22-2009, 12:15 PM   #12
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

saltminer, I could reproduce this as you state and checked with development: this behavior is unfortunately expected, as the default 'dummy' value needs to be overwritten on each tick. Thanks for your patience on this one.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 06-23-2009, 10:56 PM   #13
saltminer
Senior Member
 
Join Date: Apr 2008
Posts: 164
Thanks: 2
Thanked 3 times in 3 posts
Default

Hi Bertrand,
thanks for that info.
I'd like to comment, politely, that the current design is poor.
saltminer
saltminer 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
Price Alerts attached instrument dcobbold123 Miscellaneous Support 4 08-20-2010 05:47 AM
Mkt order w/ attached stop rightcoast General Programming 19 02-03-2009 11:42 AM
importing historical data...(screenie attached) Jugador Miscellaneous Support 4 11-24-2008 03:45 PM
NT has stopped working, log attached Kevin21 Connecting 12 08-13-2007 10:51 AM
output window attached to chart? funk101 Suggestions And Feedback 1 04-28-2007 10:32 AM


All times are GMT -6. The time now is 07:53 PM.