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 = 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.
    JimNinjaTrader Customer Service

    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.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by rtwave, 04-12-2024, 09:30 AM
            2 responses
            20 views
            0 likes
            Last Post rtwave
            by rtwave
             
            Started by tsantospinto, 04-12-2024, 07:04 PM
            5 responses
            67 views
            0 likes
            Last Post tsantospinto  
            Started by cre8able, Today, 03:20 PM
            0 responses
            6 views
            0 likes
            Last Post cre8able  
            Started by Fran888, 02-16-2024, 10:48 AM
            3 responses
            49 views
            0 likes
            Last Post Sam2515
            by Sam2515
             
            Started by martin70, 03-24-2023, 04:58 AM
            15 responses
            115 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X