![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Sep 2008
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Sep 2008
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
|
thank you for your reply,
do you think it could help to try with CalculateOnBarClose=true ? |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Believe you will have the same results with it set to true when you reload historical data.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Sep 2008
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#6 |
|
Member
Join Date: Sep 2008
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#7 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
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?
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Member
Join Date: Sep 2008
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#9 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Member
Join Date: Sep 2008
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
|
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 ? |
|
|
|
|
|
#11 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#12 |
|
Member
Join Date: Sep 2008
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#13 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#14 |
|
Member
Join Date: Sep 2008
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
|
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());
}
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 |
|
|
|
|
|
#15 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |