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

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 TraderBCL, Today, 04:38 AM
        1 response
        6 views
        0 likes
        Last Post bltdavid  
        Started by martin70, 03-24-2023, 04:58 AM
        14 responses
        105 views
        0 likes
        Last Post martin70  
        Started by Radano, 06-10-2021, 01:40 AM
        19 responses
        606 views
        0 likes
        Last Post Radano
        by Radano
         
        Started by KenneGaray, Today, 03:48 AM
        0 responses
        4 views
        0 likes
        Last Post KenneGaray  
        Started by thanajo, 05-04-2021, 02:11 AM
        4 responses
        471 views
        0 likes
        Last Post tradingnasdaqprueba  
        Working...
        X