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 07-12-2012, 02:27 AM   #1
Ironman9973
Member
 
Join Date: Jun 2012
Posts: 44
Thanks: 18
Thanked 1 time in 1 post
Default Different results in simulated account and in real account.

I have a strategy running, that buys with a limit order, if the RSI (3,1)[0] is under 10 and sells if the RSI(3,1)[0] is over 90. If I simulate this on a NT chart it works execatly how I like.

But if I run it via Interactive Brokers I get sometimes other executions. It buys sometimes if the RSI is by 12 or sells if the RSI is by 80. The thing is it works not exactly how it should.
Ironman9973 is offline  
Reply With Quote
Old 07-12-2012, 02:33 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

Welcome to our forums - how do you determine the different RSI values used in realtime in the strategy logic? It would use what you programmed in to use, it's a logical condition it would evaluate that could be either returning true or false, there's no ambiguity here. Please add a visual confirmation to your script on the bar before the order would be placed, so you can exactly check off the RSI values here.

Another common issues seen is different parameters being used and another CalculateOnBarClose setting in realtime runs compared to backtest. Please check off those items as well.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-12-2012, 02:50 AM   #3
Ironman9973
Member
 
Join Date: Jun 2012
Posts: 44
Thanks: 18
Thanked 1 time in 1 post
Default

if (Low[0] > SMA(200)[0] && ((RSI(3, 1)[0] + RSI (3, 1)[1]) <= 20))// Einstieg Long
{
EnterLongLimit(DefaultQuantity, Close[0], "EinstiegLong");
double value = MAX(ATR(20), 900)[0];
value = Close [0] - (value * 5);
SetStopLoss("EinstiegLong", CalculationMode.Price, value, false);

Thats the code for the entry. It should buy only, if the cumulativ Rsi is under 20. But that is not the case on the chart.
Attached Images
File Type: jpg $USDCHF (5 Min) 11_07_2012.jpg (74.9 KB, 7 views)
Ironman9973 is offline  
Reply With Quote
Old 07-12-2012, 02:52 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

How do you determine that it's not the case? Your lower line is not right on the 20 in case you compare to it for debugging.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-12-2012, 03:00 AM   #5
Ironman9973
Member
 
Join Date: Jun 2012
Posts: 44
Thanks: 18
Thanked 1 time in 1 post
Default

Ok, my strategy is a little different. I wanted to make it easier. Sorry for that.

I want a buy, if the cumulativ RSI from the last two bars, is under 20. Thats the code I posted. And on the chart you can see I got a buy, and the cumulativ RSI is higher than 20. I set the line to 10 that you can see, the cumulativ Rsi from the last two bars is not under 20.
Ironman9973 is offline  
Reply With Quote
Old 07-12-2012, 03:04 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

How do you determine the cumulative value is not <= 20?

Please print the value you calculate in the strategy to doublecheck it's not just a precision issue for example. Visually you can run into conditions that appear to be true / false but when examining the underlying values there's a slight differences that would have not been spotted just by eyesight...
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-12-2012, 03:15 AM   #7
Ironman9973
Member
 
Join Date: Jun 2012
Posts: 44
Thanks: 18
Thanked 1 time in 1 post
Default

The Rsi value from the entry bar is 14,07.
The Rsi value from the bar before the entry bar is 22,47.
The strategy runs on CalculateOnBarClose = true

The sum of this bars is greater than 20. But I get an execution.
Ironman9973 is offline  
Reply With Quote
Old 07-12-2012, 03:18 AM   #8
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

You would need to sum the 2 bars before the entry is shown on the chart. Since the bar before the entry shows is the bar you submit the order on.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-12-2012, 03:31 AM   #9
Ironman9973
Member
 
Join Date: Jun 2012
Posts: 44
Thanks: 18
Thanked 1 time in 1 post
Default

Yes I know that, but if one bar is over 20 the sum of two bars cannot be under 20.
Rsi from the first bar before the entry bar = 22,47
Rsi from the second bar before the entry bar = 28,05
Ironman9973 is offline  
Reply With Quote
Old 07-12-2012, 03:39 AM   #10
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

You would really need to print this value from your strategy to determine then why the rule does trigger when you don't expect it. Comparing this to charted values will only go this far, the rule triggers as programmed in, you would need to debug why it does trigger at the point indicated.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-12-2012, 03:43 AM   #11
Ironman9973
Member
 
Join Date: Jun 2012
Posts: 44
Thanks: 18
Thanked 1 time in 1 post
Default

How do you mean I should print this value?
Ironman9973 is offline  
Reply With Quote
Old 07-12-2012, 03:56 AM   #12
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

Please see this tip here - http://www.ninjatrader.com/support/f...ead.php?t=3418

With the Print() command you can print to the output window for doublechecking of calcuated value and / or the flow / event sequence of your script.

For example best approach would be storing the cumulative RSI to a variable and then printing / using the double or float variable in your condition, this will simplify the debug process for you.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-12-2012, 04:10 AM   #13
Ironman9973
Member
 
Join Date: Jun 2012
Posts: 44
Thanks: 18
Thanked 1 time in 1 post
Default

I think that is not my problem. I tested the strategy, and it works fine on a simulated account. If I test the strategy and put it on a chart everything is correct.

The thing what is confusing me is, if I let the strategy run on an account from IB, and check it after on the chart, the values from the chart are not matching the values from my strategy. Like on the chart that I posted.
Ironman9973 is offline  
Reply With Quote
Old 07-12-2012, 04:19 AM   #14
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

If you tested on the simulated account, what datafeed was the data taken from? IB as well?
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-12-2012, 04:24 AM   #15
Ironman9973
Member
 
Join Date: Jun 2012
Posts: 44
Thanks: 18
Thanked 1 time in 1 post
Default

Yes IB as well.
Ironman9973 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
Simulated account connection problem dvercher Connecting 3 01-19-2012 02:39 PM
Simulated account cash balance? ju1234 Installation and Licensing 1 08-20-2009 08:10 AM
IB Simulated Account? tradinginzen Connecting 3 02-16-2009 09:54 AM
Backtesting with a simulated account? NinjaTrader_Josh Strategy Analyzer 1 05-23-2007 06:57 AM
More than 1 Simulated Account naked Miscellaneous Support 5 02-01-2006 02:34 PM


All times are GMT -6. The time now is 06:42 AM.