Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 RideMe, 04-07-2024, 04:54 PM
    6 responses
    31 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Started by tkaboris, Today, 05:13 PM
    0 responses
    2 views
    0 likes
    Last Post tkaboris  
    Started by GussJ, 03-04-2020, 03:11 PM
    16 responses
    3,281 views
    0 likes
    Last Post Leafcutter  
    Started by WHICKED, Today, 12:45 PM
    2 responses
    19 views
    0 likes
    Last Post WHICKED
    by WHICKED
     
    Started by Tim-c, Today, 02:10 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X