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

Difficulty with the "AtmStrategyClose" command

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

    Difficulty with the "AtmStrategyClose" command

    I have a custom script that enters a trade if certain conditions are present ("XZY"). It enters the trade via an ATM strategy. The ninja script is run with COBC= false so its updated every tick.

    The strategy also contains a number of conditions which if true would implement the AtmStrategyClose command and hopefully cause the ATM strategy to close and leave me flat

    This works most of the time. When the exit conditions are met the trade closes and everything is fine.

    However, about 30% of the time something odd happens. The program not only closes the position but sends an additional close order which results in me being still in a trade (in the opposite direction) after the AtmStrategyClose order is implemented.

    By way of example I've attached a trade where this happened. This is the sequence highlighted in the attachment.

    At 10:54:01 it enters a short trade of 2 NQ at 4066 on the NQ. At that time the ATM enters two targets and two stop losses.

    At 10:56:57 the first target is hit at 4063.50. One NQ contract is bought and one Stop Loss is cancelled. I now have one contract short left and one stop loss. The remaining target is down around 4058.

    At 10:59:02 the condition which triggers the AtmStrategyClose command is triggered. This is confirmed by a print of the condition to the output window.

    At this time it looks like two things happen. First it looks like the Target 2 is adjusted to the NQ's current price (4062) to close the position by buying 1 NQ. This is fine and what I expect would happen. This leaves me flat in the position.

    HOWEVER, the program enters another order designated as a "Close" order. This order ends up buying 1 additional NQ and now leaves me long 1 NQ when I should be flat.

    Interestingly, this does not happen all the time. Other times it seems to execute it correctly by closing the position through the existing target orders. It does not enter an additional "close" order. Also, it only does this when using a live data feed. When I use market replay data it handles this correctly everytime. I want it obviously to just close the position and not leave me in a situation where in a position in the opposite direction.

    Any help would be appreciated.
    Attached Files

    #2
    Hello mdb4403,

    Just to confirm, the NinjaScript Strategy is placing orders using AtmStrategyCreate().
    Then with a specified condition, AtmStrategyClose() is called to exit the position.

    No other code is being used to close the position correct?
    No other conditions are being triggered at the same time?

    From the help guide:
    "Cancels any working orders and closes any open position of a strategy by first modifying any existing target orders so they are filled or submitting a market order if no target orders exist."
    http://ninjatrader.com/support/helpG...ategyclose.htm

    The behavior that would be incorrect is that the AtmStrategyClose is placing a close order and is also allowing a target or stop to close that order, is this correct?

    The Close order is expected any time the close is called and there is not a working profit target that can be used to close the order.

    May I confirm you have prints in your code that demonstrate the profit target is working when the AtmStrategyClose is called?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea you are correct that the order is being entered by an ATM Strategy and then with a specific condition an ATM close order is submitted and no other code is being used to submit or close orders. I have watched the Orders tab when this happens and the target order is identified in Green as working. I don't have a specific print to verify that.

      there are several condition that can trigger the AtmStrategyClose command. Its possible that two may be true at the same time. If I understand what you are saying that could result in one of the conditions using the working target to close the trade then the other using a close order. Could this be what is causing the situation. Is there a way to avoid that.

      Comment


        #4
        Hello mdb4403,

        If you have code in multiple places to exit a single position, do not allow them all to trigger.

        If one is triggered, set a bool that prevents the others from being able to trigger.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by geddyisodin, Yesterday, 05:20 AM
        8 responses
        49 views
        0 likes
        Last Post geddyisodin  
        Started by DayTradingDEMON, Today, 09:28 AM
        3 responses
        19 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Stanfillirenfro, Today, 07:23 AM
        9 responses
        23 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by George21, Today, 10:07 AM
        0 responses
        8 views
        0 likes
        Last Post George21  
        Started by navyguy06, Today, 09:28 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X