• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Close Open Position created with a Limit when entering New Order

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

  • NinjaTrader_ChelseaB
    replied
    Hello Capablanca,

    A strategy only has one position. It cannot be long and short at the same time.

    Placing an EnterShort() and an EnterLong() at the same time will conflict with each other. Most likely one of the orders will be cancelled or there will be an overfill.

    No, the Position.AvgPrice will not give each orders .AverageFillPrice independently.
    You will need to get the .AverageFillPrice from each order.
    https://ninjatrader.com/support/help...n-us/order.htm

    Leave a comment:


  • Capablanca
    replied
    Thank you Chelsea,

    I had tried the ExitLong() but it was in the wrong part of the code. It's working now.

    In my code I am entering two positions:
    EnterShort(0,c1,"Pos1");
    EnterLong(1,c2,"Pos2");

    Can I use the Position.AvgPrice to find the entry price of "Pos1" and "Pos2" independently?
    What would be the correct approach? Because if I save the current price when my orders are submitted it isn't guaranteed it will fill my orders at that exact price.

    I am trying to determine the moment when both positions are positive.


    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello Capablanca,

    To close a long position with a market order in the managed approach call ExitLong(). To close a short position call ExitShort().

    Below are links to the help guide.
    https://ninjatrader.com/support/help...s/exitlong.htm

    If you want to reverse your position, do not call the exit order first. NinjaTrader will automatically close the open position and open a new position when calling an entry order in the opposite direction of the position.

    Also, below is a link to a forum post with helpful information about getting started with NinjaScript.
    https://ninjatrader.com/support/foru...040#post786040

    Leave a comment:


  • Close Open Position created with a Limit when entering New Order

    I need to close an open position that was created using a EnterShortLimit() or EnterLongLimit() in order to enter a new position.
    When I use the EnterLong() / EnterShort() when an position is open, it closes the position and opens a new one.

    Is there a simple way to achieve this, without the unmanaged approach?

    I downloaded the example code for the unmanaged approach from: https://ninjatrader.com/support/foru...ry-orders-help
    but I don't now how to use it, because when I code in the OnBarUpdate() method the following:
    if(<condition>)
    SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, Close[0], 0, ocoString, "ShortPosition");

    it doesn't work and a get a blank chart and no messages in the log. (see attached UnmanagedOCOBracketExample.cs)

    I am attaching a strategy (ZL Cross.cs) to test the cancellation of the positions created with limits.

    Thanks!
    Attached Files

Latest Posts

Collapse

Topics Statistics Last Post
Started by DieSlower, Yesterday, 09:46 PM
1 response
17 views
0 likes
Last Post NinjaTrader_PaulH  
Started by orenytz, Today, 06:10 AM
0 responses
3 views
0 likes
Last Post orenytz
by orenytz
 
Started by ATMtrader0001, Today, 05:05 AM
0 responses
4 views
0 likes
Last Post ATMtrader0001  
Started by webus, Today, 02:03 AM
0 responses
10 views
0 likes
Last Post webus
by webus
 
Started by momchi, Yesterday, 07:12 PM
2 responses
16 views
0 likes
Last Post ATMtrader0001  
Working...
X