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 burtoninlondon, Today, 12:38 AM
    0 responses
    10 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    14 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Yesterday, 08:42 PM
    0 responses
    11 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Yesterday, 07:51 PM
    0 responses
    14 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,983 views
    3 likes
    Last Post jhudas88  
    Working...
    X