//exit long if crosses below 200 for more than 2 bars
if (GetCurrentBid(0) < SMA1[0])
{
int barsBelowSMA = 0;
for (int i =0; i < 3; i++)
{
if (GetCurrentBid(i) < SMA1.GetValueAt(i))
barsBelowSMA++;
}
if (barsBelowSMA >= 3)
{
ExitLong(Convert.ToInt32(DefaultQuantity), "ExitLong", @"GoLong");
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Adding this exit criteria prevents me from being able to run any further backtests
Collapse
X
-
Adding this exit criteria prevents me from being able to run any further backtests
When I add this exit criteria regarding exiting when longs fall below the SMA for more than 2 bars, I can no longer backtest my script. My script worked fine backtesting before this so I am sure it is from this addition:
Any thoughts on what could be the cause?Code:Tags: None
-
Hello agclub,
Thanks for your post.
If the script is not behaving as expected after making changes to the script, debugging prints would need to be added to the strategy to understand exactly how the logic is behaving.
To understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.
In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.
Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).
Below is a link to a forum post that demonstrates how to use prints to understand behavior.
<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>
- Likes 1
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 05-11-2026, 05:56 AM
|
0 responses
58 views
0 likes
|
Last Post
by CarlTrading
05-11-2026, 05:56 AM
|
||
|
Started by CarlTrading, 05-10-2026, 08:12 PM
|
0 responses
34 views
0 likes
|
Last Post
by CarlTrading
05-10-2026, 08:12 PM
|
||
|
Started by Hwop38, 05-04-2026, 07:02 PM
|
0 responses
195 views
0 likes
|
Last Post
by Hwop38
05-04-2026, 07:02 PM
|
||
|
Started by CaptainJack, 04-24-2026, 11:07 PM
|
0 responses
361 views
0 likes
|
Last Post
by CaptainJack
04-24-2026, 11:07 PM
|
||
|
Started by Mindset, 04-21-2026, 06:46 AM
|
0 responses
281 views
0 likes
|
Last Post
by Mindset
04-21-2026, 06:46 AM
|

Comment