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

Add stoploss to open position in strategy

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

    Add stoploss to open position in strategy

    In my strategy, I've coded custom buttons to open long/short positions successfully. I need help to add stop-loss to an open position with a button click. I've tried using EnterLongStopLimit and EnterShortStopLimit functions with no luck. Please help. Trying to add the normal stop-loss that I can drag up/down as needed that's withing the strategy scope. Thanks.

    Code:
            private void OnButtonClickAddStoploss(object sender, RoutedEventArgs rea)
            {
                System.Windows.Controls.Button button = sender as System.Windows.Controls.Button;
                TriggerCustomEvent(o =>
                {
                    EnterShortStopLimit(BarsInProgress, true, _posSize, Low[1] - (10 * TickSize), Low[1] - (10 * TickSize), ShortPos);
    
                }, null);
            }​
    Last edited by singjay; 10-05-2023, 10:52 AM.

    #2
    Hello singjay,

    When you say that you had no luck what specifically was the problem?

    Using a live until cancelled order like you have would be the correct way to submit targets after an entry had already made a position. You would need to make sure the signal name you are using is the same signal name that you gave to the entry order.



    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you Jesse for your quick reply. I get such error messages. See screenshot.
      Attached Files

      Comment


        #4
        Hello singjay,

        That means you are trying to use an invalid price for that type of order, the price you used was on the wrong side of the current market price. You need to change the price that you are using to be on the correct side of the market. The easiest way to make sure you have the right type of order for a position is to use the chart trader and manually enter a position and then right click on the chart. The right click menu will show you the types of orders that can be submitted based on where the mouse is in relation to the price.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Ok I see. I'll look more into the parameters that I'm passing in and retest things. Thanks for your help!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by TAJTrades, Today, 09:46 AM
          0 responses
          1 view
          0 likes
          Last Post TAJTrades  
          Started by rhyminkevin, Yesterday, 04:58 PM
          5 responses
          62 views
          0 likes
          Last Post dp8282
          by dp8282
           
          Started by realblubb, Today, 09:28 AM
          0 responses
          4 views
          0 likes
          Last Post realblubb  
          Started by AaronKoRn, Yesterday, 09:49 PM
          1 response
          19 views
          0 likes
          Last Post Rikazkhan007  
          Started by ageeholdings, Today, 07:43 AM
          0 responses
          12 views
          0 likes
          Last Post ageeholdings  
          Working...
          X