NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM 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 > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 11-16-2009, 10:29 AM   #1
fle__
Member
 
Join Date: Sep 2008
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
Default Indicator changing value after F5

Hi,
I'm having trouble finding an error, I would appreciate if you could give me some hint, because currently I have no clue as to what is wrong :
so I developped this indicator
when I press F5, the indicator is reloaded and redraws,
but the recent values change. See the images attached.
I did not compile anything before pressing F5.

What could be wrong, any idea where to look ?

thanks for your help
Attached Images
File Type: jpg $AUDCHF 11_16_2009 (1 Min) BEFORE.jpg (66.3 KB, 16 views)
File Type: jpg $AUDCHF 11_16_2009 (1 Min) AFTER.jpg (65.8 KB, 14 views)
fle__ is offline  
Reply With Quote
Old 11-16-2009, 10:54 AM   #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

fle,

Indicator logic is highly dependent on the data it is processing. When you process in real-time with CalculateOnBarClose=false you can generate different results depending on your indicator logic. You will need to thoroughly debug with Print() statements tracking every part of your calculations to find the area of your code causing issues.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-16-2009, 11:10 AM   #3
fle__
Member
 
Join Date: Sep 2008
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
Default

thank you for your reply,

do you think it could help to try with CalculateOnBarClose=true ?
fle__ is offline  
Reply With Quote
Old 11-16-2009, 11:23 AM   #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

Believe you will have the same results with it set to true when you reload historical data.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-16-2009, 11:41 AM   #5
fle__
Member
 
Join Date: Sep 2008
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
Default

I've changed the CalculateOnBarClose to true,
and let it run for some time now, and it seems to be correct now : historical data reloaded match the real time data collected.

Thank you,
you have been very helpfull,
as usual.
fle__ is offline  
Reply With Quote
Old 11-17-2009, 05:00 AM   #6
fle__
Member
 
Join Date: Sep 2008
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
Default

Unfortunately, after longer testing, it appears that the problem is not solved.

I have both indicator and strategy set to CalculateOnBarClose=true.
I changed from Gain feed to IB.

Could it be a rounding number problem (the same indicators are running smoothly on TS) ?
Is this just the way NT works, and there is nothing to do about it ?

Thank you for your help.
fle__ is offline  
Reply With Quote
Old 11-17-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

Hi fle, jumping in here, however I remember an issue from the past we discussed - is the indicator plotted from a strategy via the StrategyPlot techniques?
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 11-17-2009, 06:24 AM   #8
fle__
Member
 
Join Date: Sep 2008
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi Bertrand,

You remember correctly, the strategy uses StrategyPlot to plot the indicator.

However, my problem here is not in the plot (I dumped my requirement of having the indicator ploted while backtesting, even if it is useful).
I can withness the problem in my strategy, and also when I plot the indicator in a graph.

What happen is that the indicator seems to be calculated on different datas, be it done in real time (tested using IB or Gain) or on historical data (after doing F5).

On real time data, the indicator makes steps, is not smooth.
As a result, I get fake signals, non valid entries or premature exits.

I don't understand if the problem comes from my coding, or if it it just the way NT works.
Any hint would be appreciated.
fle__ is offline  
Reply With Quote
Old 11-17-2009, 07:16 AM   #9
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

fle,

To understand where your calculations come from you would need to use Print() statements along every single step of the way so you can track it. Then you should compare it with calculations done by hand to find where the calculations differ before you can address any potential reasons for the differences.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-18-2009, 06:21 AM   #10
fle__
Member
 
Join Date: Sep 2008
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi again,
I followed you advise,
and printed the Time OHLC and indicator value
I started the strategy, let it run a few minutes and took a snapshot of the values
Then I pressed F5, waited for the strat to start again and took another snapshot
The result is in the file attached.

After pressing F5, past OHLC values are changed, hence the indicator as well.

This was done using Gain feed.
I tried the same with IB as datafeed, and with similar results.

What can I do to solve this problem ?
Attached Files
File Type: zip Indicator changing value after F5.zip (6.2 KB, 5 views)
fle__ is offline  
Reply With Quote
Old 11-18-2009, 08:08 AM   #11
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

fle,

Please debug the calculations within your indicator one by one. Remember, when you are processing data in real-time with CalculateOnBarClose = false you will get a lot more whiplashing price action which depending on how your code calculates can influence the final outcome of your indicator. Unfortunately we cannot go through the code line by line this for you, but if you take literally print out every single step of the calculations and run it by hand on the side you will be able to find where in your code it is doing what it is doing. Good luck.

Also note that reloading historical data can create different data sets which cause different prices.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-18-2009, 08:31 AM   #12
fle__
Member
 
Join Date: Sep 2008
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
Default

hi Josh,
thank you for your answer.

Indicator + strategy are CalculateOnBarClose = true
The problem is not in the indicator.
As you can see from my attachement, the data OHLC are not the same in realtime or reloaded.

From your comment I understand it is a normal behavior of NT, some sort of filtering being applied on backfilled data.
(of course this is not what I expected, because it spoils the validity of backtesting)

Thank you for you inputs.
fle__ is offline  
Reply With Quote
Old 11-18-2009, 09:22 AM   #13
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

fle,

When it comes to data, what you see is what is coming through from your data provider. You could try a different data feed to see if you get better results with a different one.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-23-2009, 11:01 AM   #14
fle__
Member
 
Join Date: Sep 2008
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi again,
after deep investigation, I think the problem is due to the multiple instruments not being in sync.
As a result, when OnBarUpdate fires on my first dataserie, I might not have the latest value for the other dataseries, and it creates this jitter on the chart (and trading signals calculation)

I have tried to wait for having all data up to date before doing my main calculation, with the following code :
Code:
            //ignore data other than EURUSD, unless we are waiting for completion of incoming data from various feeds
            if ((BarsInProgress != 0 && !WaitFlag) || ErrorFlag )
            {
                return;    
            }

            DateTime current = DateTime.Now;
            for (int index = 0; index < maxDatafeedNb; index++) 
                {
                    if ((ToTime(Times[0][0]) != ToTime(Times[pairDatafeed[index].BarsArrayNb][0])) && pairDatafeed[index].tradePosition!=0)
                    {
                        WaitFlag = true;
                        Print(current.ToString() + ": wait "+ToTime(Times[pairDatafeed[index].BarsArrayNb][0]).ToString() + " "+ pairDatafeed[index].plotName + " barNb " + CurrentBar );
                        return;
                    }                        
                }
            WaitFlag=false;
            for (int index = 0; index < maxDatafeedNb; index++) 
            {
                if (!Historical )                
                        Print(current.ToString() + ": "+ToTime(Times[pairDatafeed[index].BarsArrayNb][0]).ToString() + " "+ pairDatafeed[index].plotName + " barNb " + CurrentBar + " barRX "+barsReceived.ToString());
            }
using the Print() loop, I can see that all my dataseries have now the same time when they enter in the main calculation block of code.

However, a collateral damage is that now the indicators do not plot on my chart.
I can see in the log and w/ a Print() that the main calculation code is executed. But nothing is printed (via StrategyPlot).

I suppose its because now StrategyPlot is not called from the primary dataserie. I saw a post on that.
I work with CalculateOnBarClose=true, and would like to avoir COBC=false, because then I bump into other problems.

But then, how to do this sync ? any suggestion would be welcomed
fle__ is offline  
Reply With Quote
Old 11-23-2009, 11:08 AM   #15
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

fle__,

Unfortunately that is a limitation for StrategyPlot.

You are correct in that each bar series is not necessarily in time with each other. They update whenever their particular series updates. Unfortunately there is no easy workaround except plot it back in BIP=0 once everything is calculated.
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
Function key F5 gartonrd Miscellaneous Support 7 02-17-2011 10:03 AM
CCI (or any indicator) with changing color Jibu V Indicator Development 10 09-24-2010 07:07 AM
Changing indicator name, label edsfreedom Indicator Development 1 06-05-2009 09:38 AM
Refresh (F5) mydet General Programming 3 07-24-2008 04:48 AM
F5 key (Compile) cls71 Miscellaneous Support 9 06-22-2008 05:02 AM


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