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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    90 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    137 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    120 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    72 views
    0 likes
    Last Post PaulMohn  
    Working...
    X