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

Close By Stop Loss

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

    Close By Stop Loss

    How can I know if my position was closed by a stop loss (in case I used the SetStopLoss method)?

    Thanks

    #2
    Hello kiss987,

    Thank you for writing in. You can know how a position was closed by checking the Name column and the Filled column of the orders tab of either the control center or the strategy analyzer (depending on how you are running your strategy). You will see "Stop loss" as the name, and an amount greater than 0 in the "Filled" column indijcating that a position was exited through the SetStopLoss() method.

    More information on the SetStopLoss() method can be found in our help guide here: http://ninjatrader.com/support/helpG...ub=setstoploss

    If you need to know if your position was closed by the order placed from the SetStopLoss() method in code, it could look something like this:
    Code:
    protected override void OnExecution(IExecution e)
    {
    	if(e.Order != null && e.Order.OrderState == OrderState.Filled && e.Order.Name.ToString() == "Stop loss")
    	{
    		//Do something
    	}
    }
    The code above is called on an incoming execution. It checks if the execution's order exists, if the order state is now filled, and if the order is a stop loss order.

    More information on the OnExecution() method can be found in our help guide here: http://ninjatrader.com/support/helpG...ub=onexecution

    Please let us know if we may be of further assistance.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      To my understanding, the stop loss order has a default name of "Stop loss".
      Do the orders which are called by EnterLong, ExitLong and SetProfitTarget also have default names?
      Thanks

      Comment


        #4
        Hello,
        When using SetProfitTarget() it will have a default name of ProfitTarget.
        EnterLong and ExitLong do not have default names but you can name them by entering a string in between the parantheses.
        Code:
        EnterLong("My Long Order" + CurrentBar);
        This example would enter a name of My Long order and then the current bar when the order is placed.

        If we can be of any other assistance please let us know.
        Cody B.NinjaTrader Customer Service

        Comment


          #5
          Can you please give an example on how to use the ExitLong method? I am not sure I understand how to use the fromEntrySignal parameter.

          Comment


            #6
            Hello,
            Please see the following example below using ExitLong.
            Code:
            ExitLong("My Long Order" + CurrentBar);
            The fromEntrySignalName is a string that you can use to associate a specific exit order with an entry name.

            If we can be of any other assistance please let us know.
            Cody B.NinjaTrader Customer Service

            Comment


              #7
              Does the fromEntrySignalName has to be identical to the value I provided on the EnterLong?
              For example, if I entered the position using EnterLong("A"), can I exit it using ExitLong("B")?

              Comment


                #8
                Hello,
                The fromEntrySignalName would need to be identical to the value that you use in EnterLong().
                If you do not it would end up with exiting by submitting long market orders until your position is flat.
                I recommend reviewing the Tips subsection for this on ExitLong() in our hlep guide. http://ninjatrader.com/support/helpG...7/exitlong.htm

                If we can be of any other assistance please let us know.
                Cody B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Jon17, Today, 04:33 PM
                0 responses
                1 view
                0 likes
                Last Post Jon17
                by Jon17
                 
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                4 views
                0 likes
                Last Post Javierw.ok  
                Started by timmbbo, Today, 08:59 AM
                2 responses
                10 views
                0 likes
                Last Post bltdavid  
                Started by alifarahani, Today, 09:40 AM
                6 responses
                41 views
                0 likes
                Last Post alifarahani  
                Started by Waxavi, Today, 02:10 AM
                1 response
                19 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Working...
                X