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

How do you reset the stoploss price/offset value?

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

    How do you reset the stoploss price/offset value?

    In the help it says

    "Should you call this method to dynamically change the stop loss price in the strategy OnBarUpdate() method, you should always reset the stop loss price/offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your stop loss order on your next open position"

    How does one reset the value?

    thanks

    #2
    Ninjamouse,

    For example, before you open a new order you would use SetStopLoss(default).

    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Hi

      Thanks for replying to me, you see I have this code:

      protectedoverridevoid Initialize()
      {
      SetProfitTarget(
      "", CalculationMode.Ticks, 5);
      CalculateOnBarClose = true;
      }
      ///<summary>
      /// Called on each bar update event (incoming tick)
      ///</summary>
      protectedoverridevoid OnBarUpdate()
      {
      if (Position.MarketPosition == MarketPosition.Flat)
      {

      SetStopLoss(CalculationMode.Ticks,
      1);

      if (Open[3] == High[3] && enterShort == false)
      {
      SetStopLoss(CalculationMode.Ticks, High[
      0]);
      EnterShortLimit(DefaultQuantity, Open[0], "");
      enterShort = true;
      enterLong =
      false;
      }
      if (Close[3] == High[3] && enterLong == false)
      {
      SetStopLoss(CalculationMode.Ticks, Low[
      0]);
      EnterLongLimit(DefaultQuantity, Open[0], "");
      enterShort = false;
      enterLong =
      true;
      }
      }

      my stoploss never gets hit instead I get a HUGE stop loss. Would you know whats wrong?

      thanks

      Comment


        #4
        Ninjamouse,

        I see nothing wrong immediately with this. What sort of large stop loss are you getting?
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by ninjamouse View Post
          Hi

          Thanks for replying to me, you see I have this code:

          protectedoverridevoid Initialize()
          {
          SetProfitTarget(
          "", CalculationMode.Ticks, 5);
          CalculateOnBarClose = true;
          }
          ///<summary>
          /// Called on each bar update event (incoming tick)
          ///</summary>
          protectedoverridevoid OnBarUpdate()
          {
          if (Position.MarketPosition == MarketPosition.Flat)
          {

          SetStopLoss(CalculationMode.Ticks,
          1);

          if (Open[3] == High[3] && enterShort == false)
          {
          SetStopLoss(CalculationMode.Ticks, High[
          0]);
          EnterShortLimit(DefaultQuantity, Open[0], "");
          enterShort = true;
          enterLong =
          false;
          }
          ...
          }

          my stoploss never gets hit instead I get a HUGE stop loss. Would you know whats wrong?

          thanks
          Emphasis mine. Let us assume that you are using /ES and the price High[0] is 1257. Your coding is asking for a StopLoss of 1257 ticks! Whew! If you want to use a price as a StopLoss, then you should code using the CalculateMode.Price syntax. A price is a price; a tick is a tick,

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by zstheorist, Today, 07:52 PM
          0 responses
          3 views
          0 likes
          Last Post zstheorist  
          Started by pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          149 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Started by mattbsea, Today, 05:44 PM
          0 responses
          5 views
          0 likes
          Last Post mattbsea  
          Started by RideMe, 04-07-2024, 04:54 PM
          6 responses
          33 views
          0 likes
          Last Post RideMe
          by RideMe
           
          Started by tkaboris, Today, 05:13 PM
          0 responses
          5 views
          0 likes
          Last Post tkaboris  
          Working...
          X