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

Problem with OnExecution multiple quantity order using EnterLong(quantity,signalName)

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

    Problem with OnExecution multiple quantity order using EnterLong(quantity,signalName)

    Hello Support,

    Strategy Objective:
    I'm hoping for some direction on how to properly track a filled and sold order that was placed using the EnterLong(int quantity, string signalName) within my strategies OnExecution Method. (note, this has multiple quantities and the example in your help guide does not handle multiple quantities).

    Problem:
    I'm using EnterLong(int quantity, string signalName) to track IOrders in the OnExecutionMethod, there seems to be an issue with multiple quantities.

    Failed Work Around:
    Within the OnExecution Method, comparing the IOrder.Token to the captured IOrder execution.order.token fails because they are different guids.

    Code:
    The following code from the OnExecution HelpGuide does not work for multiple contracts . From http://www.ninjatrader.com/support/h...nexecution.htm

    // Finding the executions of a particular IOrder object
    private IOrder entryOrder = null;
    private int entryQuantity = 8;

    protected override void OnBarUpdate()
    {
    if (entryOrder == null && Close[0] > Open[0])
    entryOrder = EnterLong(entryQuantity,"TestSignal");
    }

    protected override void OnExecution(IExecution execution)
    {
    if (entryOrder != null && entryOrder == execution.Order)
    Print(execution.ToString());
    }


    I would appreciate any direction that comes to mind,
    Thanks

    #2
    Hello FattMatt4088,

    Thanks for your post.

    You mention that there may be an issue with multiple quantities.

    What seems to be the issue with this?

    The code you have provided causes the following print to be generated:
    Execution='NT-00000' Instrument='CL 10-13' Account='Replay101' Name='TestSignal' Exchange=Default Price=106.7 Quantity=8 Market position=Long Commission=2.1 Order='NT-00000' Time='8/19/2013 4:40:00 PM'

    This order has a quantity of 8.

    Are you wanting to submit this order twice?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Does it still run when you add a Stop and Target? New code is below.
      (Thanks for the update)

      Code:
      The following code from the OnExecution HelpGuide does not work for multiple contracts . From http://www.ninjatrader.com/support/h...nexecution.htm

      // Finding the executions of a particular IOrder object
      private IOrder entryOrder = null;
      private int entryQuantity = 8;

      protected override void OnBarUpdate()
      {
      if (entryOrder == null && Close[0] > Open[0])
      {
      entryOrder = EnterLong(entryQuantity,"TestSignal");

      base.SetStopLoss(CalculationMode.Ticks, (double) 30);
      base.SetProfitTarget(CalculationMode.Ticks, (double) 30);
      }
      }

      protected override void OnExecution(IExecution execution)
      {
      if (entryOrder != null && entryOrder == execution.Order)
      Print(execution.ToString());
      }

      Comment


        #4
        Hello,

        I have modified the script and run this. I have found everything to be working correctly. The strategy entered a trade with a quantity of 8. A stop loss and profit target were placed to protect the order. Hours later the stop loss filled returning the position to flat.

        Below is the output of the of strategy from the Output window with TraceOrders = true.

        8/19/2013 4:39:00 PM Entered internal PlaceOrder() method at 8/19/2013 4:39:00 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=8 LimitPrice=0 StopPrice=0 SignalName='TestSignal' FromEntrySignal=''
        8/19/2013 4:39:00 PM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Ticks Value=30 Currency=0 Simulated=False
        8/19/2013 4:39:00 PM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='' Mode=Ticks Value=30 Currency=0 Simulated=False
        Execution='NT-00000' Instrument='CL 10-13' Account='Replay101' Name='TestSignal' Exchange=Default Price=106.7 Quantity=8 Market position=Long Commission=2.1 Order='NT-00000' Time='8/19/2013 4:40:00 PM'
        8/19/2013 11:10:00 PM Cancelled pending exit order, since associated position is closed: Order='NT-00002/Replay101' Name='Profit target' State=Working Instrument='CL 10-13' Action=Sell Limit price=107 Stop price=0 Quantity=8 Strategy='Multiple' Type=Limit Tif=Gtc Oco='NT-00000-445' Filled=0 Fill price=0 Token='3c94697188744340afb1d23f3730fc5e' Gtd='12/1/2099 12:00:00 AM'
        8/19/2013 11:10:00 PM Cancelled OCO paired order: BarsInProgress=0: Order='NT-00002/Replay101' Name='Profit target' State=Cancelled Instrument='CL 10-13' Action=Sell Limit price=107 Stop price=0 Quantity=8 Strategy='Multiple' Type=Limit Tif=Gtc Oco='NT-00000-445' Filled=0 Fill price=0 Token='3c94697188744340afb1d23f3730fc5e' Gtd='12/1/2099 12:00:00 AM'

        Attached is the strategy as I have it.

        Please let me know if you have questions about this.
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          ChelseaB, thank you for your help so far, you have been great.

          So SetTarget and SetStop don't add a stop or limit to the open order?

          Sorry but I'm confused at when the Stop or Target get hit. I was assuming they'd be in the same execution.order object but that isn't the case.

          Comment


            #6
            How do I get the SetProfitTarget or SetStopLoss order objects from the SetProfitTarget() or SetStopLoss() calls?

            Comment


              #7
              Hello FattMatt4088,

              In OnExecution try:

              if (execution.Order.Name == "Stop loss")
              {
              // execute code here
              }

              if (execution.Order.Name == "Profit target")
              {
              // execute code here
              }

              Below is a link to the help guide which describes the values in IExecution.
              http://www.ninjatrader.com/support/h...iexecution.htm
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Thanks again, you have been great. I now have a solution for trapping stops and targets. Thank you Chelsea

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by algospoke, Today, 06:40 PM
                0 responses
                10 views
                0 likes
                Last Post algospoke  
                Started by maybeimnotrader, Today, 05:46 PM
                0 responses
                7 views
                0 likes
                Last Post maybeimnotrader  
                Started by quantismo, Today, 05:13 PM
                0 responses
                7 views
                0 likes
                Last Post quantismo  
                Started by AttiM, 02-14-2024, 05:20 PM
                8 responses
                168 views
                0 likes
                Last Post jeronymite  
                Started by cre8able, Today, 04:22 PM
                0 responses
                10 views
                0 likes
                Last Post cre8able  
                Working...
                X