Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ignoring stops and profit targets?

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

    Ignoring stops and profit targets?

    As I attempt to backtest my strats, I notice that stops and profit targets are being ignored.

    Obviously I need to resolve this before I go into production.

    I have added a simple piece of code below that, surprisingly, will not adhere to my predefined limits.

    Regards.

    Also: DayRelChangeFromOpen = % change between Close[0] and opening print, so 2 = 2%
    __________________________________________________ _____________


    #namespace NinjaTrader.Strategy
    {

    Description("Enter the description of your strategy here")]
    publicclass tester : Strategy
    {
    #region Variables
    #endregion
    protectedoverridevoid Initialize()
    {
    SetStopLoss(
    "", CalculationMode.Percent, 1, false);
    SetProfitTarget(
    "", CalculationMode.Percent, 1);
    CalculateOnBarClose =
    true;
    }

    protectedoverridevoid OnBarUpdate()
    {
    if (DayRelChangeFromOpen()[0] >= 2)
    {
    EnterLong(
    100, "");
    }

    if (DayRelChangeFromOpen()[0] <= -2)
    {
    EnterShort(
    100, "");
    }
    }
    #region Properties
    #endregion
    }
    }

    #2
    Hello,

    If you are wanting to use CalculationMode.Percent, you should use the decimal equivalent to the value you are using. Your current setup is indicating to set the stop/target at 100%. If you are looking for 1% of the value, you would use 0.01:

    Code:
    SetStopLoss("", CalculationMode.Percent, .01, false);
    SetProfitTarget("", CalculationMode.Percent, .01);
    If you see further issues, I'd suggest running TraceOrders = true to obtain more information as to why these are being ignored:

    MatthewNinjaTrader Product Management

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    32 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    12 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    18 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    20 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X