//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 NullPointStrategies, Today, 05:17 AM
|
0 responses
52 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
130 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
70 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
44 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
48 views
0 likes
|
Last Post
|

Comment