Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ATMStrategyClose()

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

    ATMStrategyClose()

    Hello;

    I am working with an ATM Strategy. I have a manually coded trailing stop, and a second set of rules that closes the ATM Strategy if the trailing stop is adjusted higher than the current price. I have noticed that when ATMStrategyClose() is invoked the long position is closed but the strategy opens a short position even though there are no rules to allow that. How can I ensure that the strategy waits for another long entry signal before entering another long trade, rather than going short?


    Code:
    // Change the stop if the close is above the currentlevel
    if (GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Long && Close[0] > CurrentLevel)
    {
    AtmStrategyChangeStopTarget(0, InitialY + (Slope1 * BarsElapsed), "STOP1", atmStrategyId);
    }
    
    // Close if close below current level
    else if (GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Long && Close[0] < CurrentLevel)
    {
    AtmStrategyClose(atmStrategyId);
    }

    #2
    Hello MisterGee,

    Thank you for your post.

    When running this, are you manually entering any orders on the same instrument and account combination? Is there an existing position when the strategy is started?

    When the short position is opened, does it too get an ATM stop and target, or is it an unprotected short position?

    Does this occur each time the strategy is run, or only occasionally?

    I'm not seeing anything in this particular code sample that would normally cause a reversal into a short position, however, if the stop is hit at essentially the same time you call AtmStrategyClose, it could cause such a scenario to occur, since that would submit a market sell order to close the long position it thinks is still there.

    Are you running this OnEachTick, OnPriceChange or OnBarClose?

    Thanks in advance, I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the reply,

      All positions entered are done so via automated strategy, but it's only one position at a time on one instrument. The account is flat when the startegy is started.

      When the short position is opened it is unprotected and get closed when the automated strategy opens a long position.

      I'm not in front of my screen right now but I don't think it happened every time, but any time the position was closed via ATM stop loss or PT it did NOT happen. Only when it was closed with ATMStrategyClose().

      This is run OnBarClose.

      I'm wondering if you're on to something with the stop being hit close to when the ATMStrategyClose is being called.. any suggestions for testing that idea?

      Comment


        #4
        Hello MisterGee,

        Thank you for your reply.

        We could certainly take a look at your log and trace files to see if that's what may be occurring - if that's what it is we should be able to see it occur in those. Rather than post them here, since they may contain personally identifiable information like your account number, please send them to us directly through the platform, via Help > Email Support. In the subject line, please put 2861801 ATTN Kate W. so we know to route it to me when it comes in. The box for Log and Trace files should automatically be checked.

        Thanks in advance; I look forward to assisting you further.
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by IndieTrader, Today, 05:29 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by ballboy11, Today, 08:09 AM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by kempotrader, 05-03-2019, 10:52 AM
        8 responses
        89 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by waldoalvarez, Today, 07:53 AM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by sinpeople, 03-05-2021, 09:53 AM
        3 responses
        26 views
        0 likes
        Last Post NinjaTrader_ThomasC  
        Working...
        X