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

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?

    Paul H.NinjaTrader Customer Service

    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,
        Paul H.NinjaTrader Customer Service

        Comment


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

          Thanks Paul!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by pechtri, 06-22-2023, 02:31 AM
          9 responses
          122 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by frankthearm, 04-18-2024, 09:08 AM
          16 responses
          66 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by habeebft, Today, 01:18 PM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by benmarkal, Today, 12:52 PM
          2 responses
          18 views
          0 likes
          Last Post benmarkal  
          Started by f.saeidi, Today, 01:38 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X