Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Close position when two moving averages crossing

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

    Close position when two moving averages crossing

    Hi all,

    So I'm trying to build a strategy with two MA's, lets say these are the 10MA & 20MA, I got my strategy to buy it when they cross and now I want my strategy to automatically take profit when the 5MA crosses the 20MA. How would I code this because it uses a different MA to close the position?

    #2
    Hello Lotyok,

    Thanks for your post and welcome to the NinjaTrader forums!

    You would code it very much the same as you did for the cross to enter except you would be using the 5 and the 20 and calling an exit method.



    Comment


      #3
      Hi thanks for your reply!

      So.. this is what confuses me. Do I make that in the "Conditions and Actions" or "Stops and Profits"?

      Comment


        #4
        Hello Lotyok,

        Thanks for your reply.

        Great question!

        The stops and profits window in the Strategy Builder would be for fixed value exits only, such as a profit or stop of say 10 ticks, or $300, or 5% and these would be applied to every entry.

        In your case, you are wanting a dynamic exit based on the changing conditions of two moving averages. So you would need to use a set with the conditions of the moving averages cross and in the actions under Order management> select an appropriate exit method such as exitLong() or exitShort().

        If you have not already reviewed, here are the resources to help with the Strategy Builder:
        Here are the educational resource available on the strategy builder:
        Free live webinar every other Thursday at 4:00 PM EST, through this link to all webinars: https://ninjatrader.com/PlatformTraining
        Previous recording of the Strategy Builder 301 webinar: https://youtu.be/HCyt90GAs9k?list=PL...auWXkWe0Nf&t=2
        Help guide for the strategy builder: https://ninjatrader.com/support/help...gy_builder.htm

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        87 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        132 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        65 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        118 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        67 views
        0 likes
        Last Post PaulMohn  
        Working...
        X