• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

On Execution issue

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

    On Execution issue

    Hello,

    for moving a stop of contract b with target of contract a I have in onExecution

    if(execution.Name=="Profit target" && execution.Order.FromEntrySignal=="La")
    SetStopLoss("Lb", CalculationMode.Price,Position.AvgPrice-2*TickSize, false);

    but immediately with entry the stop is set to Position.AvgPrice-2*TickSize.

    (For info I have in Initialize and onbarupdate
    SetStopLoss("La", CalculationMode.Ticks, 8, false);
    SetStopLoss("Lb", CalculationMode.Ticks, 8, false);

    Why does NT with entry not the "normal" SetStopLoss of 8 Ticks but immediately the new position that should be done only with target a?

    Thank you
    Tony

    #2
    Hello Tony,

    Thank you for writing in.

    What steps have you already done to debug your code?

    Testing on my end with only the information you have given me, the stop loss for "Lb" will not modify its price until the profit target for "La" is filled, as expected.

    Is your profit target immediately filling after entry?
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      thank you for your reply.

      I commented "//" the line in onExecution and then it works ok, when I remove "//" then the stop is again there at the wrong position immediately after the entry. The target is not filled (if it would be filled the logic would be OK, and it would be an error in coding for the target, thank you for the idea)

      Is there another possibility to test to have the stop changed with fill of other target? When I worked with exitlongstop I could code it in onorderupdate. But with SetStopLoss I dont know -can I grab the target and stop in onorderupdate as well? (I only have "profit target" and "stoploss" and not the accurate signal name in this case)

      Thank you
      Tony
      Last edited by tonynt; 03-15-2016, 08:30 AM. Reason: Clearifiying, typing error

      Comment


        #4
        Hello Tony,

        I am not able to reproduce this behavior on my end utilizing the logic you have provided in your original post. I have attached a simple strategy demonstrating this.

        To answer your questions:

        You would be able to access the stop loss and profit target orders from OnOrderUpdate(). Do remember that OnOrderUpdate() is called every time an order changes state.

        https://ninjatrader.com/support/help...rderupdate.htm

        Example:
        Code:
        protected override void OnOrderUpdate(IOrder o)
        {
             if (o.Name == "Profit target")
                  // do something
        
             if (o.Name == "Stop loss")
                  // do something
        }
        Following up from the above, you can access the from entry signal name by accessing the order's FromEntrySignal property:
        Code:
        o.FromEntrySignal;
        More information about IOrder objects can be found in the help guide here: https://ninjatrader.com/support/help...t7/?iorder.htm
        Attached Files
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Hello,

          thank you for your support and for the sample, this is how its coded. So its really strange that it does show the wrong stoploss.

          Might be the reason for the problem that in initialize and onbarupdate I have setstoploss(....Ticks...) but in onExecution I have (SetStopLoss.....Price...)? If so, how could I use this logic with "Ticks" in on Execution when I want to refer to the Entryprice with BE + x Ticks after fill of 1st target?)

          Thank you
          Tony

          Comment


            #6
            Hello Tony,

            You would be able to use CalculationMode.Price for your SetStopLoss() method in OnExecution() without issue despite initially setting the stop loss with CalculationMode.Ticks within Initialize().

            Please provide a simplified sample of your strategy demonstrating the issue that you are having so I may test on my end.

            To export your script do the following:
            1. Click File -> Utilities -> Export NinjaScript
            2. Enter a unique name for the file in the value for 'File name:'
            3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
            4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


            By default your exported file will be in the following location:
            • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


            Below is a link to the help guide on Exporting NinjaScripts.
            http://www.ninjatrader.com/support/h...nt7/export.htm
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Hello,

              thank you for your reply.

              I will reduce the strat to the very minimum so that I do not bother with additional lines and then send it.

              Best regards
              Tony

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by rontronimous, Today, 05:55 PM
              0 responses
              8 views
              0 likes
              Last Post rontronimous  
              Started by bcgeek, Today, 03:43 PM
              2 responses
              6 views
              0 likes
              Last Post bcgeek
              by bcgeek
               
              Started by Mberg, Today, 04:05 PM
              0 responses
              9 views
              0 likes
              Last Post Mberg
              by Mberg
               
              Started by dkbyond, Today, 03:52 PM
              0 responses
              5 views
              0 likes
              Last Post dkbyond
              by dkbyond
               
              Started by Newtrader101, Today, 03:09 PM
              2 responses
              7 views
              0 likes
              Last Post Newtrader101  
              Working...
              X