Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Trading One Candle Late
Collapse
X
-
Trading One Candle Late
I have a strategy that trades when price close crosses above the ATR Trailing Stop. In real time it keeps trading on the second candle pass the break. I want it to trade on first candle crossing the ATR Trailing Stop. The backtest makes it look perfect, but, live trading does not trade on the first candle. Does anyone know a command to get it to trade on the first candle. I have tried price closed > price open 1 bar ago, already. Here's an example of what the machine gives a perfect trade.
Tags: None
-
Hello ReginaldS8,
Thanks for your post.
If your strategy is set to run in the mode of Calculate.OnBarClose which means that the strategy code executes once at the end of each bar and will perform calculations on completed bars. If your strategy determines to enter an order, the order would be placed on the next bar. In this mode, your strategy will operate the same historically as it does when connected to real-time (or replay) data.
Using the calculate mode of Calculate.OnPriceChange, or Calculate.OnEachTick, will allow the strategy to be executed intrabar with greater frequency which means your code will be executed on each tick or each change in price. Depending on the bar size and market volatility this can be a significant number of times per bar. You would be working with data that could change and your strategy conditions could change from one tick to the next. Entry orders would be executed intrabar instead of waiting until the next bar.
Calculate: https://ninjatrader.com/support/help.../calculate.htm<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
-
I checked the code in NinjaScript and it shows that it is "Calculate.OnEachTick". Also, when I set a strategy on a chart I make sure I have chosen "On each tick". I see in your instruction: 1.Calculating indicators or systems for each incoming tick can be CPU intensive. Could it be because my computer is reacting slower because of the on each tick setting?
Comment
-
Hello ReginaldS8,
Thanks for your note.
What is the 'look-back period' of your CrossAbove condition set to? Is the 'look-back period' set to 1 or is it set to 0?-
If the CrossAbove condition is set to have a look-back period of 1, this will check if the crossover occurs on the previous bar and then an order would be placed on the currently forming bar.
See this help guide page for information about CrossAbove(): https://ninjatrader.com/support/help...crossabove.htm<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
-
Okay thank you. I will test to see if I can use 0 or a -. I must have to change this in the NinjaScript because I attempted to make 1 cross above to 0 in the Strategy Builder and it would change right back to 1 automatically when I clicked apply.
Comment
-
Hello ReginaldS8,
Thanks for your post.
After further research, I see the CrossAbove lookback period is set to 1 by default and changes to 1 if you try to set it to 0.
I have created an example script you could view demonstrating setting the lookback period of CrossAbove to 1 and when a crossover occurs on the current bar in realtime when using Calculate.OnEachTick, a line is drawn on the chart.
Here is a demonstration video showing the attached crossover condition in the script working OnEachTick when lookback period is set to 1: https://brandonh-ninjatrader.tinytak...M18yMTU1Njc2NQ
Please test reproducing the behavior on the Playback connection with your strategy set to Calculate.OnEachTick. After reproducing the behavior, attach an exported copy of the script and the exact settings and steps to reproduce the behavior so I may look into this further.
To export a strategy, go to Tools > Export > NinjaScript AddOn.Attached Files<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
44 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
126 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
65 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment