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 Mindset, 04-21-2026, 06:46 AM
          0 responses
          88 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          135 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          68 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          119 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          69 views
          0 likes
          Last Post PaulMohn  
          Working...
          X