![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
NT Support:
I am currently running a test using the sample SMA Strategy with CalculateOnBarClose set to False. It seems to work as expected, but I noticed something was not consisent with the expected behavior. A CrossBelow was fire, and the system went short. This was expected. Then after a few bars, the current bar with the issue spiked up thus causing a CrossAbove and getting Long, but then after the bar closed, you can see that it did not really CrossAbove (the sma) and it left the trade Long when it should clearly be straight. Only after a stop loss did it get out of the trade. So again, position was Short. Some bars go by and the SMA is slowly creeping up with the fast catching up to the slow. A during one of the later bars, a spike up happened, firing a CrossAbove IntraBar and the Closed Current Position, and put the system Long 1. (all fine up until this point). Now intrabar we also didn't hold that spike and the downtrend continued, the SMA is clearly inversed to the downside and we did not get put back short again, instead it left us long even though it clearly crossed back below intrabar (fast cut down through the slow). Could you elaborate in regards to how this might occur and propose a solution to preventing it other than COBC = True? Thank you in advance, |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
The condition was evaluated to true and so it placed a trade, just because the condition is no longer true does not mean it will close that trade. Works as expected. There is no logic saying if the condition is all of a sudden not true to place a closing trade.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Quote:
I understand. But I do not believe your answer applies to my question per se. If we fired a crossAbove intrabar during an up spike, then it should put us long, got that. Likewise, when the spike dies and then reverses, the SMA is now inverted with fast back below the slow (short), but it DIDN'T FIRE a trade reflecting that. I checked the logs and orders. Something doesn't make sense here. I believe there is a logical explanation, but the one you are giving me I don't believe applies here :-( |
|
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
r2kTrader,
CrossAbove/Below conditions are determined based on the lookback period set and the latest tick information. It does not compare latest tick versus previous tick. You are likely looking at the previous bar's close versus the current tick. If it crosses above then it is true, if it falls back down on the same bar, the cross below is still NOT true because there was no cross below based on the previous bar. As such, no short trade will be placed.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 | |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Josh,
This was helpful. So I want to be sure I get this correct. Note: Calc On Bar Close = False Based on the fact the COBC = false, why would it be looking at the prior bar? My lookback is the default, which is 1 bar I assume. I am not saying if price Crosses above, I am saying if SMA value crosses, so if it crossed above, didn't it cross below when it resumed going lower? I kind of understand what you are saying, but I don't see how we can crossabove, and then not cross back below. Your logic makes sense to me with COBC = true, because we crossed above, but didn't close above, etc. Bear in mind, as I look at the chart, the final plot showed that the fast did not "close" above the slow, rather the price action visited above on that spike and retraced. Thanks Quote:
|
|
|
|
|
|
|
#6 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
r2kTrader,
CrossAbove/Below does not look at the last tick versus the prior tick. It looks at last tick versus prior bar. This is the way it has always worked. You are checking for a condition to cross above condition to be true on a bar. If it moved above on that bar it is true. If it now moves back down it is now back to false. Becoming false again does not trigger a cross below logic. This is what it is designed to do and it behaves as expected. If you want some more logic in there you need to self program it.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#7 | |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Quote:
SMA fast = 400 SMA slow = 390 Current bar has 3 minutes left on 5m bar. Currently Fast is above Slow and we are long 1 car. during the bar, we get a pullback to say 380, this would fire a CrossBelow? But if it reverts back to say 405, it won't fire a CrossAbove? hmm, yeah, that makes perfect sense to the layman, lol. I hear what you are saying. If I am understanding this correctly, as per the example, we started out with a CrossAbove under our best, hence crossAbove was true and put us in trade. But when we intrabar crossedBelow firing a false, it doesn't "undo" the CrossAbove, that value is still essentially true ? I hope you can see how this might be a bit confusing. I am sure with COBC=on, it's a little more black and white. At least it is behaving as expected, thanks for the time to explain this to me and I hope it helps someone else. |
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
r2kTrader, you're correct in understanding CrossAbove and CrossBelow are not connected in their outcomes, hence this can lead to whipsaws if you run this to update on every tick or CalculateOnBarClose = false. This is expected and you would need to add custom logic helping preventing your condition becoming true / false intrabar too many times.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Support,
Which takes precedence as I just noticed/realized that the SMA has a General Property for COBC. If Strategy has COBC = false, but SMA Indicator has General Property set to COBC=True, will the SMA be aligned and subjected to its own property, or does the Strategy Property take precedence? Thank you, r2kTrader |
|
|
|
|
|
#10 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
r2kTrader,
Your indicators should not have any COBC line. There is a bug with it so please do not use any COBC lines except in the overarching script. If IndicA calls IndicB, only IndicA should have a COBC line if at all. If Strategy calls IndicA, only Strategy should have a COBC line if at all.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#11 | |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Quote:
|
|
|
|
|
|
|
#12 |
|
Junior Member
Join Date: Jan 2010
Posts: 19
Thanks: 0
Thanked 0 times in 0 posts
|
Hi,
To my relief I just stumbled upon this thread and this seems to explain my NT 6.5 strategy's eratic behavior. Does anyone know of a work around for this without resorting to the (un-backtestable) OnMarketData() method? My strategy needs COBC = false but the custom indicator that drives most of it needs COBC = true Thank you in advance, Stevo |
|
|
|
|
|
#13 |
|
Senior Member
Join Date: Dec 2008
Posts: 338
Thanks: 0
Thanked 0 times in 0 posts
|
I have noticed this in an indicator ... should it be commented out when used in a strategy??
indicator.CalculateOnBarClose = CalculateOnBarClose; |
|
|
|
|
|
#14 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
Jon, this should be commented out if you plan on calling the indicator programmatically.
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| "Calculate on Bar Close" | John833 | General Programming | 8 | 07-21-2009 05:13 AM |
| Calculate on bar close | unclelou | Charting | 1 | 03-25-2009 05:43 PM |
| Calculate on Bar Close or not? | Hugo1 | Strategy Development | 3 | 03-09-2009 07:53 AM |
| Unexpected results from script | suedeuno | Indicator Development | 3 | 02-17-2009 04:38 AM |
| Question about Calculate on Bar close | slowhand | Strategy Development | 8 | 02-13-2009 11:24 AM |