Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitShortStopMarket/ExitShortLimit Not working

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

    ExitShortStopMarket/ExitShortLimit Not working

    Hi,

    I am placing a ExitShortStopMarket and ExitShortLimit, after the order is executed.

    The below Code is called in the OnExecutionUpdate after the Short position is created. I can see the entry for the message written to log, however the exit orders are not placed.
    This is done for Historical data.


    dShortStopPrice = dEntryPrice + (StopTargetTicks/ Instrument.MasterInstrument.PointValue);
    WriteToLog(" Setting Short Stop Price at " + dShortStopPrice);
    ExitShortStopMarket(dShortStopPrice,ShortStop,Sell Short);

    dShortTargetPrice = dEntryPrice - (ProfitTargetTicks/ Instrument.MasterInstrument.PointValue);
    WriteToLog(" Setting Short Target Price at " + dShortTargetPrice);
    ExitShortLimit(dShortTargetPrice,CoverShort,SellSh ort);




    #2
    Hi btsgrand, thanks for your post.

    The order will be canceled after every bar, so you need to re-submit resting orders on every bar. You can avoid this by using the order overload that takes a isLiveUntilCancelled bool. With this set to true you can keep the order alive.
    https://ninjatrader.com/support/help...tstoplimit.htm

    e.g. ExitShortStopLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, double stopPrice, string signalName, string fromEntrySignal)

    Please also see this related example:
    https://ninjatrader.com/support/help...and_onexec.htm

    Please let me know if I can assist any further.
    Last edited by NinjaTrader_ChrisL; 03-08-2020, 04:13 PM.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris

      I am back working on the stop order for my strategy.
      On follow up will the ExitShortStopLimit work on historical orders (reloading strategy).

      This was what i am trying to achieve, however the stopOrder object is always null when trying to reuse and i believe ExitShortStopLimit order expires after that bar.

      class strategy
      {
      Order orstopOrder = null;

      Private override void OnExecutionUpdate()
      {

      if(Long position Opened)
      SetInitialStopOrder()

      }

      private void SetIntialStopOrder()
      {
      orstopOrder = ExitLongStopLimit(0, true, 1, InitialStopLimitprice, 0, StopSignalName, EntrySignalName)
      }

      private void Override OnBarUpdate()
      {

      if(Position == MarketPosition.Long)
      {
      if(StopPrice has to be Changed)
      {
      NewStopPrice = CalculateStopPrice
      ChangeOrder(orstopOrder, 1, NewStopPrice,0) // orstopOrder is null and does not have detils set in SetIntialStopOrder

      }
      }

      }

      private double CalculateStopPrice()
      {
      }

      }​​​
      Last edited by btsgrand; 09-11-2020, 12:01 AM.

      Comment


        #4
        Hello btsgrand,

        The variable will be null if the order object is not assigned in OnOrderUpdate().

        From the help guide:
        "OnOrderUpdate() will run inside of order methods such as EnterLong() or SubmitOrderUnmanaged(), therefore attempting to assign an order object outside of OnOrderUpdate() may not return as soon as expected. If your strategy is dependent on tracking the order object from the very first update, you should try to match your order objects by the order.Name (signal name) from during the OnOrderUpdate() as the order is first updated."

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

        The help guide also shows an example of properly assigning an order object from OnOrderUpdate().
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by JuanPabloQuevedo, Yesterday, 05:27 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by StevenNelson, Yesterday, 03:24 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by my-trade, Yesterday, 10:45 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by s.kinra, Yesterday, 11:36 PM
        0 responses
        6 views
        0 likes
        Last Post s.kinra
        by s.kinra
         
        Started by oz187, Yesterday, 11:31 PM
        0 responses
        7 views
        0 likes
        Last Post oz187
        by oz187
         
        Working...
        X