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 CaptainJack, 05-29-2026, 05:09 AM
    0 responses
    173 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 05-29-2026, 12:02 AM
    0 responses
    91 views
    0 likes
    Last Post CaptainJack  
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    130 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    209 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    186 views
    0 likes
    Last Post CarlTrading  
    Working...
    X