Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

"On" stop loss

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

    "On" stop loss

    I want my strategy not generating any new trade X minutes after a stop loss order,, How can I set a variable on a stop loss event? is there any ready method to handle this?

    #2
    Hi dafonseca,

    To detect a stop loss filling:

    Code:
    protected override void OnExecution(IExecution execution)
    {
    if (execution.Order.Name == "Stop loss")
    {
    // execute code
    }
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I see.
      One thing..

      Should I insert : protected override void OnExecution(IExecution execution)
      inside OnBarUpdate()?

      Comment


        #4
        Hello dafonseca,

        No, do not add the OnExecution method to the OnBarUpdate method.

        The OnExecution() method is a method just like OnBarUpdate. Put OnExecution below or above OnBarUpdate, but outside of it.

        Below is a link to the help guide on OnExecution().
        http://www.ninjatrader.com/support/h...nexecution.htm
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Something weird has happened, When I insert this part on my code, without change anything on OnBarUpdate, my backtesting results change radically.
          Any clue?
          protected override void OnExecution(IExecution execution)
          {
          if (execution.Order.Name == "Stop loss")
          {
          // execute code
          }
          }

          Comment


            #6
            Hi dafonseca,

            This code does not actually do anything.

            May I see your script to see how you have added this code?

            To export your script do the following:
            • Click File -> Utilities -> Export NinjaScript
            • Enter a unique name for the file in the value for 'File name:'
            • Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
            • Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


            By default your exported file will be in the following location:
            • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


            Below is a link to the help guide on Exporting NinjaScripts.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              To update other forum members, the issue was using the Order child object of the execution object. It is not always there.

              We changed:
              protected override void OnExecution(IExecution execution)
              {
              if (execution.Order.Name == "Stop loss")
              {
              // execute code
              }
              }

              To:
              protected override void OnExecution(IExecution execution)
              {
              if (execution.Name == "Stop loss")
              {
              // execute code
              }
              }

              And was able to correct the issue.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              649 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              370 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              109 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              574 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              576 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X