Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exiting ATM Strategy due to loss limit

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

    Exiting ATM Strategy due to loss limit

    Hello,

    I have been trying to code an exit strategy for my ATM strategy that will exit the trade when the position has gone too far into the red. This is my current code:

    Code:
    if (GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Short
    && (Close[0] - GetAtmStrategyPositionAveragePrice(atmStrategyId) >= 9)
    {
    AtmStrategyClose(atmStrategyId);
    }
    If the position down 9 points or more then I would like it to close. I have been testing on Playback Connection. This strategy operates OnBarUpdate.

    Thanks in advance.

    #2
    Hello MisterGee,

    Thanks for your post.

    Does your code produce the desired results?

    If not what results do you see?

    Comment


      #3
      No. The strategy does not produce the desired result. There are no results. I included a print line to observe when the code is triggered and there are no instances of the print line in the output window even though there are multiple occurrences of trades losing more than 9 points.

      Comment


        #4
        Hello MisterGee,

        Thanks for your reply.

        I tested your code with a copy of SampleATM strategy set to sell instead of buy and in market replay was able to see that your code did work.

        Here is what i used:

        if (atmStrategyId.Length > 0)
        {
        Print ("Gap: "+(Close[0] - GetAtmStrategyPositionAveragePrice(atmStrategyId)) );

        if (GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Short && (Close[0] - GetAtmStrategyPositionAveragePrice(atmStrategyId) >= 2))
        {
        AtmStrategyClose(atmStrategyId);
        Print ("Strategy Closed");
        }
        }


        Here is a short video I made using market replay to demonstrate: https://Paul-ninjaTrader.tinytake.co...M18xNTY0NzMyMw

        From this we can conclude that your code works so there must be some other reason that it is not working as expected. You will need to continue debugging,

        Comment


          #5
          Well, that's good and bad news I guess!

          Thanks Paul!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CarlTrading, 03-31-2026, 09:41 PM
          1 response
          80 views
          1 like
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          40 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          64 views
          2 likes
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          64 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          54 views
          0 likes
          Last Post CarlTrading  
          Working...
          X