Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

stop loss = done for session

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

    stop loss = done for session

    having trouble finding the right syntax for this. i have now

    Code:
            protected override void Initialize()
            {
               
                SetStopLoss("Long", CalculationMode.Ticks, 40, true);
                SetStopLoss("Short", CalculationMode.Ticks, 40, true);
            }
    and then this

    Code:
            protected override void OnOrderUpdate(IOrder order)
            {
                if (order.OrderState == OrderState.PendingSubmit)
                
                {
                    if (order.Name == "Stop loss")
                    doneForSession = true;
                }
    then i have a little" if done for session" thing to take trades. but once order is generated doneForSession becomes true even when stop loss gets canceled

    do i have this wrong? i mean of course i do as it is not working, what do i have wrong?

    #2
    Hello JimPunkrockford,

    Thanks for opening the thread.

    It is a little unclear for me what you are trying to do and what is going wrong. Could you provide more detail as to what you are trying to accomplish exactly so we can give further advise?

    I'm happy to be of further assistance.

    Comment


      #3
      so i want "done for session" to be true if i have had a stop loss at some point in the day.

      but i have it being true if any trades get taken, if they are a stop loss or not.

      Comment


        #4
        also this seems to work during the day but not in market replay or strategy analyzer

        Comment


          #5
          Originally posted by JimPunkrockford View Post
          but i have it being true if any trades get taken, if they are a stop loss or not.
          Rather than using SetStopLoss, investigate using ExitLongStop and ExitShortStop, saving the result as StopOrder, so that you can then do this,

          Code:
          if (order == StopOrder && order.OrderState == OrderState.PendingSubmit)

          Comment


            #6
            Hello JimPunkrockford,

            Thanks for the replies.

            so i want "done for session" to be true if i have had a stop loss at some point in the day.

            but i have it being true if any trades get taken, if they are a stop loss or not.
            I would agree with bltdavid's advise to use Exit methods for your stop loss. SetStopLoss() will prep NinjaTrader so whenever an order sent from the strategy with an Enter method gets filled, a stop loss will be fired.

            The SampleOnOrderUpdate strategy provides a good framework to demonstrate using OnOrderUpdate(), OnExecutionUpdate(), and Order objects as well as creating your own profit target and stop loss.

            SampleOnOrderUpdate - https://ninjatrader.com/support/foru...ead.php?t=7499

            Please let us know if you have any questions.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            639 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            366 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            107 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            569 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            572 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X