Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding this exit criteria prevents me from being able to run any further backtests

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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:

    Code:
    //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");
                    }
                    
                }​
    Any thoughts on what could be the cause?

    #2
    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>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    127 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X