Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

exitlong = movestoploss

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

    exitlong = movestoploss

    Hello,

    I have one question more for finishing my strategies. In my scripts I want to move the initial stoploss to breakeven when 1st of 3 contracts is exited with exitlong. (not moving the stoploss with certain pips in direction - only when the exit is realized)

    I have no idea now how to do this.

    Thank you in advance.

    Best regards
    Tony

    #2
    tonynt,

    Here is a reference sample on modifying existing stop losses : http://www.ninjatrader.com/support/f...ead.php?t=3222

    You would just need to modify it to be at the breakeven level, and that reference sample should help you get started.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Adam,

      this sample I started with 1 year ago. This is clear of course - and not the question or not the answer to my question, sorry.

      The question is how the stoploss can be moved when - and only - a certain exit (eg the first exit of several contracts) is done. Also I dont mean to move the stoploss when the conditions are filled - the same condition as for exitlong. As there could be a discrepancy because of price, bid, ask this would not necessarily mean that both are executed.

      Therefore the question is to move stoploss at same time when the 1st of several exits is realized.

      Best regards
      Tony

      Comment


        #4
        tonynt,

        The reference sample shows how you can modify the stop loss price. So if you have some condition or set of conditions you know ahead of time you can use them to set the stop by replacing the relevant if statement in the reference sample.

        What conditions do you have here that need clarification?

        if ( my_exit_condition )
        {
        ExitLong(1); //Exit 1 contract
        SetStopLoss(CalculationMode.Ticks, Position.AvgPrice); //Set the stop loss to break even
        }

        If you need to make sure the 1 contract is closed, you can use OnExecution() to make sure the order is filled first. Please find a reference sample to using this below.

        The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Adam,

          What condtions.......? As you write it down here. The exit by conditions shows that not 100% of exits and stoplosses are matching for some reasons.

          With OnExecution I will get it.

          Thank you

          Comment


            #6
            tony,

            If you could post your OnBarUpdate() code or a sample of what you are doing I think it will help our communication better. I am not sure how you are handling your exit conditions nor if you have entry signals, etc.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Adam,

              thank you for your reply and offering posting what to do. With conditions in OnOrderUpdate I do for months in strategies, but it is more accurate to have it in OnExecution (but this I dont know now how to do there)

              protected override void OnExecution(IExecution execution)
              {
              in words: " if (ExitLong(1000,"xL1","L1") "

              {SetStopLoss("L2",CalculationMode.Price, Position.AvgPrice,false);
              SetStopLoss("L3",CalculationMode.Price, Position.AvgPrice,false);

              }
              }

              Thanks
              Tony

              Comment


                #8
                Hello,

                You would actually need to do this in OnOrderUpdate().

                The reason why is you only want to do this if a certain order is filled, not just any execution. The only way to know what execution is for what is to track the order with an iOrder object. This way you can take some specific action when a specific order gets filled.

                protected override void OnBarUpdate()
                {
                iOrder exitLongxLT1 = ExitLong(1000,"xL1","L1") ;
                }

                private override void OnOrderUpdate(iOrder Order)
                {
                if (exitLongxLT1 == Order)
                {
                //My exit go filled
                //Now I need to modify my stop loss value
                }
                }


                Hopefully this code sample I quickly put together would demonstrate one way to do this.

                -Brett

                Comment


                  #9
                  Thank you!

                  Great support of you all there with NinjaTrader.

                  Best software out there and best support.

                  Thanks
                  Tony

                  Originally posted by NinjaTrader_Brett View Post
                  Hello,

                  You would actually need to do this in OnOrderUpdate().

                  The reason why is you only want to do this if a certain order is filled, not just any execution. The only way to know what execution is for what is to track the order with an iOrder object. This way you can take some specific action when a specific order gets filled.

                  protected override void OnBarUpdate()
                  {
                  iOrder exitLongxLT1 = ExitLong(1000,"xL1","L1") ;
                  }

                  private override void OnOrderUpdate(iOrder Order)
                  {
                  if (exitLongxLT1 == Order)
                  {
                  //My exit go filled
                  //Now I need to modify my stop loss value
                  }
                  }


                  Hopefully this code sample I quickly put together would demonstrate one way to do this.

                  -Brett

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by AttiM, 02-14-2024, 05:20 PM
                  10 responses
                  179 views
                  0 likes
                  Last Post jeronymite  
                  Started by ghoul, Today, 06:02 PM
                  0 responses
                  9 views
                  0 likes
                  Last Post ghoul
                  by ghoul
                   
                  Started by Barry Milan, Yesterday, 10:35 PM
                  6 responses
                  19 views
                  0 likes
                  Last Post Barry Milan  
                  Started by DanielSanMartin, Yesterday, 02:37 PM
                  2 responses
                  13 views
                  0 likes
                  Last Post DanielSanMartin  
                  Started by DJ888, 04-16-2024, 06:09 PM
                  4 responses
                  13 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Working...
                  X