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

Decimal point Wrongfully placed when OnExecution's called

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

    Decimal point Wrongfully placed when OnExecution's called

    I had a weird yet dangerous experience this morning when my corn order's executed.

    I have stop loss placement when OnExecution's called for newly executed entry order:

    SetStopLoss(execution.Name, CalculationMode.Price, execution.Price + stoplossticks * TickSize, true);

    However, my entry order was immediately stopped after placement. After checking out the log, what happened was that the decimal point in execution was wrongfully placed

    How could this happen??? Please help!

    My broker is IB.

    Please see attached screenshot.
    Last edited by kelvin2088; 12-18-2013, 01:37 PM.

    #2
    Typically you won't want to use SetStopLoss() from within OnExecution. Otherwise you run the risk of the stop loss not yet being updated from the previous SetStopLoss amount.

    Please see this example here for how to properly structure your OnExecution using advanced order handling: http://www.ninjatrader.com/support/f...ead.php?t=7499

    For tips on debugging your code: http://www.ninjatrader.com/support/f...ead.php?t=3418

    Let me know if I can further assist.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Lance View Post
      Typically you won't want to use SetStopLoss() from within OnExecution. Otherwise you run the risk of the stop loss not yet being updated from the previous SetStopLoss amount.

      Please see this example here for how to properly structure your OnExecution using advanced order handling: http://www.ninjatrader.com/support/f...ead.php?t=7499

      For tips on debugging your code: http://www.ninjatrader.com/support/f...ead.php?t=3418

      Let me know if I can further assist.
      thnaks Lance for the reply.
      Stop loss price is updated with execution price when order's executed. However, for whatever reason the real time execution price came up to 4.285 instead of 428.5 so it messed up the stop loss price and profit target price.

      It's certainly not my programming error as I re-start the strategy and it worked fine and re-submitted the SL and TP orders based on historical fill price.

      Comment


        #4
        This still points back to the original issue of not wanting to use Set() methods inside OnExecution()

        When using SetStopLoss() it stores the value of this internally. Then when an enter method is placed that order will have the most recent SetStopLoss value attached to it. I would expect over historical data (as you pointed out here) the stop value would be correct. However in real time the previous stop value was used first before the new one could come in and take affect.

        You can either modify your OnExecution to use advanced order handling OR you can Call SetStopLoss() just before your enter method call inside of OnBarUpdate().

        Let me know if I can further assist.
        LanceNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Lance View Post
          This still points back to the original issue of not wanting to use Set() methods inside OnExecution()

          When using SetStopLoss() it stores the value of this internally. Then when an enter method is placed that order will have the most recent SetStopLoss value attached to it. I would expect over historical data (as you pointed out here) the stop value would be correct. However in real time the previous stop value was used first before the new one could come in and take affect.

          You can either modify your OnExecution to use advanced order handling OR you can Call SetStopLoss() just before your enter method call inside of OnBarUpdate().

          Let me know if I can further assist.
          ok. thanks Lance!
          it's still weird to me as the procedure i interpreted as following:

          1. entry order submitted

          2. entry order executed, OnExecution() get called by "execution order"

          3. SetStopLoss(execution.Name, CalculationMode.Price, execution.Price + stoplossticks * TickSize, true) got submitted with execution price.

          I'm just curious how NT handles setstoploss's stop loss value internally.

          I guess it would help if I replace execution.Price with Close[0] if under calculate on bar close mode. What do you think?

          Comment


            #6
            Originally posted by kelvin2088 View Post
            I guess it would help if I replace execution.Price with Close[0] if under calculate on bar close mode. What do you think?
            I think this would be the simplest solution.

            If you wanted it to then adjust to be based off of the position's fill price you could then do something like this in OnBarUpdate.

            if(Position.MarketPosition == MarketPosition.Long)
            {
            SetStopLoss("your signal", CalculationMode.Price, Position.AvgPrice, false);
            }

            This process would first use the closing price and then adjust it after the fill if the close price was different from fill price.

            This help guide article may help clarify SetStopLoss() as well: http://www.ninjatrader.com/support/h...etstoploss.htm

            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

            Let me know if I can further assist.
            LanceNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by judysamnt7, 03-13-2023, 09:11 AM
            4 responses
            59 views
            0 likes
            Last Post DynamicTest  
            Started by ScottWalsh, Today, 06:52 PM
            4 responses
            36 views
            0 likes
            Last Post ScottWalsh  
            Started by olisav57, Today, 07:39 PM
            0 responses
            7 views
            0 likes
            Last Post olisav57  
            Started by trilliantrader, Today, 03:01 PM
            2 responses
            21 views
            0 likes
            Last Post helpwanted  
            Started by cre8able, Today, 07:24 PM
            0 responses
            10 views
            0 likes
            Last Post cre8able  
            Working...
            X