![]() |
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
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Apr 2008
Posts: 164
Thanks: 2
Thanked 3 times in 3 posts
|
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 } |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
saltminer, thanks for this detailed posting, we'll look into it and get back to you.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
saltminer, please don't do the plotting in your own functions, use the OnBarUpdate() directly please and retry.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Apr 2008
Posts: 164
Thanks: 2
Thanked 3 times in 3 posts
|
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)); } |
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Apr 2008
Posts: 164
Thanks: 2
Thanked 3 times in 3 posts
|
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 |
|
|
|
|
|
#7 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
Thanks Saltminer, I'll give it a go and check on my end.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Apr 2008
Posts: 164
Thanks: 2
Thanked 3 times in 3 posts
|
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 |
|
|
|
|
|
#10 | |
|
NinjaTrader Customer Service
Join Date: Feb 2009
Location: Denver, CO
Posts: 3,815
Thanks: 32
Thanked 135 times in 135 posts
|
Quote:
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!
Christopher
NinjaTrader Customer Service |
|
|
|
|
|
|
#11 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Senior Member
Join Date: Apr 2008
Posts: 164
Thanks: 2
Thanked 3 times in 3 posts
|
Hi Bertrand,
thanks for that info. I'd like to comment, politely, that the current design is poor. saltminer |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |