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

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.


    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."



        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 algospoke, Yesterday, 06:40 PM
        2 responses
        19 views
        0 likes
        Last Post algospoke  
        Started by ghoul, Today, 06:02 PM
        3 responses
        14 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        45 views
        0 likes
        Last Post jeronymite  
        Started by Barry Milan, Yesterday, 10:35 PM
        7 responses
        21 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by AttiM, 02-14-2024, 05:20 PM
        10 responses
        181 views
        0 likes
        Last Post jeronymite  
        Working...
        X