Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

After OrderEntry...now what

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

    After OrderEntry...now what

    Friends,

    I am using this piece of code and it is working....
    Code:
    entryOrder = SubmitOrder(0, OrderAction.Sell,OrderType.Market,5,0,0,"","SellShort");
    And sure enough I have 5 contracts sold short at market.

    Now I am trying to set a profit target and stop loss, then modify each depending on market conditions. This is where my problems begin.... For example, I have tried to close the position once it is X number of ticks against me.

    Code:
    entryOrder = SubmitOrder(0, OrderAction.BuyToCover,OrderType.Market,5,0,0,"","SellShort");
    Nothing happens...

    Can someone point me in the correct direction. I have looked at the NT help screens and don't see (or have not found) enough examples to guide me. I tried ChangeOrder with no success.

    #2
    Hello sarasotavince,

    Thank you for your post.

    There should be no issue with the SumbitOrder() method you are using to exit.

    Are you receiving an error when the order is submitted? Please check you Log tab for any errors when the order should have been submitted.

    In addition, add a Print() that is sent when the order should be. This will allow you to track that the condition to exit is actually met. You can also add TraceOrders to track the orders in the Output window.

    For information on Print and TraceOrders please visit the following links:

    Comment


      #3
      Hey Patrick,

      Thanks for the super-fast reply...made a bone-head error that I caught after it going through the code line by line....but I do have a follow up question please...

      Once a stop (Buy to Cover) order is submitted, to change that order I need to use ChangeOrder script correct, not a new line of code starting with entryOrder = submitOrder with the "new" parameters...do I have this right?

      Is there an example zip file with similar code showing an order, then a modification of that order...

      Thanks so much!

      Comment


        #4
        Hello sarasotavince,

        Thank you for your response.
        Once a stop (Buy to Cover) order is submitted, to change that order I need to use ChangeOrder script correct, not a new line of code starting with entryOrder = submitOrder with the "new" parameters...do I have this right?
        That is correct.

        Comment


          #5
          I seem to be running in circles...I have no problem entering an order...but I can't seem to manage the stop or profit target. Can anyone provide simple code that would set a 10 tick stop loss and a ten tick profit target that would follow this line of code...I'll worry about the ChangeOrder later.

          Code:
          entryOrder = SubmitOrder(0,OrderAction.SellShort,OrderType.Market,3,0,0,"one","Order1");

          Comment


            #6
            Hello sarasotavince,

            Thank you for your response.

            You would need to set up two IOrder objects, one for Stop Loss and one for Profit Target. Then check when the entryOrder is filled and then set the Stop Loss and Profit Target with the same OCO ID.

            Use OnExecution to check for the fill of the entryOrder, and then use Position.AvgPrice to set the Stop Loss and Profit Target orders with the number of ticks needed.

            For example:
            Code:
            		protected override void OnExecution(IExecution e)
            		{
            			if(e.Order != null && e.Order == entryOrder && e.Order.OrderState == OrderState.Filled)
            			{
            				stopOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Stop, 1, 0, Position.AvgPrice - (10*TickSize), "StopTarget", "Stop Loss");
            				profitTarget = SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, Position.AvgPrice + (10*TickSize), 0, "StopTarget", "Profit Target");
            			}
            		}
            For information on OnExecution() please visit the following link: http://www.ninjatrader.com/support/h...nexecution.htm

            Please let me know if I may be of further assistance.

            Comment


              #7
              Thanks again Patrick.

              That last post advanced my understanding considerably...

              Watch out...moving on to change orders !!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by maybeimnotrader, Today, 05:46 PM
              0 responses
              6 views
              0 likes
              Last Post maybeimnotrader  
              Started by quantismo, Today, 05:13 PM
              0 responses
              6 views
              0 likes
              Last Post quantismo  
              Started by AttiM, 02-14-2024, 05:20 PM
              8 responses
              166 views
              0 likes
              Last Post jeronymite  
              Started by cre8able, Today, 04:22 PM
              0 responses
              8 views
              0 likes
              Last Post cre8able  
              Started by RichStudent, Today, 04:21 PM
              0 responses
              5 views
              0 likes
              Last Post RichStudent  
              Working...
              X