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 Waxavi, Today, 02:10 AM
            0 responses
            4 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by TradeForge, Today, 02:09 AM
            0 responses
            9 views
            0 likes
            Last Post TradeForge  
            Started by Waxavi, Today, 02:00 AM
            0 responses
            2 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by elirion, Today, 01:36 AM
            0 responses
            4 views
            0 likes
            Last Post elirion
            by elirion
             
            Started by gentlebenthebear, Today, 01:30 AM
            0 responses
            4 views
            0 likes
            Last Post gentlebenthebear  
            Working...
            X