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

Stop Loss Not Executing

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

    Stop Loss Not Executing

    Hello NT,

    I'm running a strategy where my average losing trade is double what my stop loss is set at. The log is showing the following error:

    "Stop/target handling set to 'By strategy position' since currency"

    I'm using the following code to enter the trade:

    Code:
    EnterLong(Convert.ToInt32(DefaultQuantity), @"Entry08Long");
    and the following for a stop loss:

    Code:
    SetStopLoss(@"Entry81Long", CalculationMode.Currency, Stop, false);
    What am I doing wrong?

    #2
    Hello harr5754,

    Thank you for your post.

    The example code you provided would not set a stop loss for that entry - it would be looking for an entry with the name "Entry81Long" and the entry code you've provided states an entry name of "Entry08Long". Could you provide a larger code sample so we may best understand how the strategy is set up and why you're seeing larger than expected average losses?

    Also, keep in mind that SetStopLoss uses Stop Market orders for the stop loss, which are vulnerable to slippage and may not fill at the amount they are set at in a volatile market, so slippage may be a factor depending on how large the stop loss is.

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thanks, Kate.

      The "Entry81Long" was indeed a typo and should have been "Entry08Long". The stop loss is executing now. However, I still am getting an error message in the log saying,

      ""Stop/target handling set to 'By strategy position' since currency"

      Here is the code I am running:

      Code:
       entry8_len = 5;
      Target = 1000;
      Stop = 1000;
      
      }
      else if (State == State.Configure)
      {
      SetProfitTarget(@"Entry08Long", CalculationMode.Currency, Target);
      SetStopLoss(@"Entry08Long", CalculationMode.Currency, Stop, false);
      SetProfitTarget(@"Entry08Short", CalculationMode.Currency, Target);
      SetStopLoss(@"Entry08Short", CalculationMode.Currency, Stop, false);
      }
      }
      [NinjaScriptProperty]
      [Description("entry8_len")]
      [Category("Parameters")]
      public int entry8_len
      { get; set; }
      
      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="Target", Description="Target Price", Order=1, GroupName="Parameters")]
      public int Target
      { get; set; }
      
      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="Stop", Description="Stop Price", Order=2, GroupName="Parameters")]
      public int Stop
      { get; set; }
      
      protected override void OnBarUpdate()
      {
      if (CurrentBar < BarsRequiredToTrade)
      return;
      
      // Input Variables
      int entry8_len = 5;
      
      if (Volume[0] < SMA(Volume, 5)[0])
      {
      if (Close[0] == Close[LowestBar(Close, entry8_len)])
      EnterLong(Convert.ToInt32(DefaultQuantity), @"Entry08Long");
      if (Close[0] == Close[HighestBar(Close, entry8_len)])
      EnterShort(Convert.ToInt32(DefaultQuantity), @"Entry08Short");
      Thanks,
      Ben

      Comment


        #4
        Hello harr5754,

        That's not an error, it's basically just informational.

        What this means is that the strategy's StopTargetHandling, which is labeled Stop & Target Submission, is set to "Per Entry Execution", but this cannot be used when using Currency as the Calculation mode for your stops and targets. It's basically just telling you it's going to use the correct mode for that stop/target type.

        By Strategy Position just means that for a given position, only one stop loss, trail stop and/or profit target order is submitted. As entry executions come in, the order size is amended. The downside of this approach is that if you receive partial fills, the orders are re-inserted into the exchange order queue. The upside is that if you broker charges you commission per order (not per quantity), you will not incur additional commission expenses.

        In your case, if you're only submitting orders of 1 quantity, you're not going to run into a partial fill scenario, so you're likely not going to run into those issues I mentioned there. If you don't want this message to appear, change the StopTargetHandling line in State.SetDefaults to StopTargetHandling.ByStrategyPosition.

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Thank you for your explanation, Kate.

          There is one other thing that puzzles me for target and stop orders. If I set a target of $1000 and a stop of $1000 on a strategy, I would expect a backtest on the Strategy Analyzer to come up with and average winning trade of $1000 and an average losing trade of $1000 since I am not including slippage and commission. Yet, when I run the code I posted above on various instruments I get averages as low as $783 and largest losing trades as large as $1375.

          I wondering why this would be.

          Regards,
          Ben

          Comment


            #6
            Hello harr5754,

            Thank you for your reply.

            Do you have Exit on Session Close checked when running the strategy? That may be cutting trades off at a different point and could compound if you're not at a flat position at the end of each day and it closes that position out. I'd advise checking that and also taking a look at how NinjaTrader calculates your average winning and losing trades in our help guide here:



            If you calculate that out from your results and aren't getting the same average, please let us know.
            Kate W.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ageeholdings, Today, 07:43 AM
            0 responses
            7 views
            0 likes
            Last Post ageeholdings  
            Started by pibrew, Today, 06:37 AM
            0 responses
            4 views
            0 likes
            Last Post pibrew
            by pibrew
             
            Started by rbeckmann05, Yesterday, 06:48 PM
            1 response
            14 views
            0 likes
            Last Post bltdavid  
            Started by llanqui, Today, 03:53 AM
            0 responses
            6 views
            0 likes
            Last Post llanqui
            by llanqui
             
            Started by burtoninlondon, Today, 12:38 AM
            0 responses
            12 views
            0 likes
            Last Post burtoninlondon  
            Working...
            X