![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Jun 2012
Posts: 44
Thanks: 18
Thanked 1 time in 1 post
|
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. |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Jun 2012
Posts: 44
Thanks: 18
Thanked 1 time in 1 post
|
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. |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Jun 2012
Posts: 44
Thanks: 18
Thanked 1 time in 1 post
|
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. |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
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...
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Member
Join Date: Jun 2012
Posts: 44
Thanks: 18
Thanked 1 time in 1 post
|
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. |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Member
Join Date: Jun 2012
Posts: 44
Thanks: 18
Thanked 1 time in 1 post
|
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 |
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Member
Join Date: Jun 2012
Posts: 44
Thanks: 18
Thanked 1 time in 1 post
|
How do you mean I should print this value?
|
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Member
Join Date: Jun 2012
Posts: 44
Thanks: 18
Thanked 1 time in 1 post
|
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. |
|
|
|
|
|
#14 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
If you tested on the simulated account, what datafeed was the data taken from? IB as well?
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#15 |
|
Member
Join Date: Jun 2012
Posts: 44
Thanks: 18
Thanked 1 time in 1 post
|
Yes IB as well.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |