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 geddyisodin, 04-25-2024, 05:20 AM
    8 responses
    58 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by jxs_xrj, 01-12-2020, 09:49 AM
    4 responses
    3,285 views
    1 like
    Last Post jgualdronc  
    Started by Option Whisperer, Today, 09:55 AM
    0 responses
    5 views
    0 likes
    Last Post Option Whisperer  
    Started by halgo_boulder, 04-20-2024, 08:44 AM
    2 responses
    22 views
    0 likes
    Last Post halgo_boulder  
    Started by mishhh, 05-25-2010, 08:54 AM
    19 responses
    6,189 views
    0 likes
    Last Post rene69851  
    Working...
    X