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

SetStopLoss() resetting

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

    SetStopLoss() resetting

    Hi, I need some help
    In my strategy to set the stop, I use the SetStopLoss() method. In the refernce book there is a suggestion, to reset the stop loss price, when the strategy is flat, otherwise the last stop price value will be used to generate the stop loss order on the next open position.
    I thought, that I wright to the OnPositionUpdate:
    if(position.MarketPosition == MarketPosition.Flat)
    // resetting the stop loss

    But how can I do the reset?

    And is this method the best place to do it?

    Thank you for advance

    Kind regards

    Akos

    #2
    Hello,

    You have the condition right, but I recommend placing it in OnBarUpdate() rather than OnPositionUpdate(). Below is a sample that will show how to reset the stop loss to its original values, assuming that stoplossticks is an int variable holding the original value:

    Code:
    if (Position.MarketPosition == MarketPosition.Flat)
    			{
    				SetStopLoss(CalculationMode.Ticks, stoplossticks);
    			}
    We have a reference sample that shows this in action, which you can see at the link below:

    http://www.ninjatrader.com/support/f...ead.php?t=3222
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Hi Dave
      Thank you for your help, but a have had a question yet. The first position closed, and in the second a don't want use stop loss. So I need to "switch off" the stop loss, like it had never been before. Is there any solution for this?
      Kind regards
      Akos

      Comment


        #4
        Hello,

        There is not a way to cancel an order placed by SetStopLoss(), but you do have a few options available to accomplish the same goal. One option is to set the stop loss to a value so far away from the price that it will never be filled (such as 100 ticks away).

        Alternatively, you could use ExitLongStop(), ExitShortLimit(), etc., assign it to an IOrder object, then call CancelOrder() on those orders. For more information about using IOrder objects and CancelOrder(), please see the links below:

        http://www.ninjatrader.com/support/h...ancelorder.htm

        http://www.ninjatrader.com/support/h...tml?iorder.htm
        Dave I.NinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,605 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        8 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        4 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        13 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X