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

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.

    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 pechtri, 06-22-2023, 02:31 AM
10 responses
124 views
0 likes
Last Post Leeroy_Jenkins  
Started by judysamnt7, 03-13-2023, 09:11 AM
4 responses
59 views
0 likes
Last Post DynamicTest  
Started by ScottWalsh, Yesterday, 06:52 PM
4 responses
36 views
0 likes
Last Post ScottWalsh  
Started by olisav57, Yesterday, 07:39 PM
0 responses
7 views
0 likes
Last Post olisav57  
Started by trilliantrader, Yesterday, 03:01 PM
2 responses
22 views
0 likes
Last Post helpwanted  
Working...
X