Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple MACD Crossover Strategy that isn't so simple

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

    #16
    To be more specific, it didnt Exit on a long position. It just seemed to be waiting for a stop loss or profit, which I removed.

    What I would like is for it to exit when the opposite MACD cross occurs.

    Also, I tried my code and it didnt seem to exit as well. Any ideas?

    Comment


      #17
      May have fixed this issue

      I believe I fixed it. I added the ExitShort(); command once it enters the macd long cross. Does this make sense

      if (CrossAbove(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
      {
      ExitShort();
      buyFlag = true; // enable ability to buy because Macd crossed above 0
      sellFlag = false; // disable ability to sell because Macd crossed above 0
      }

      if (buyFlag && Stochastics(7, 14, 3).K[0] > 80) //&& Position.MarketPosition == MarketPosition.Flat)
      {
      EnterLong(); // BuyFlag and stochstics K are true so enter long
      buyFlag = false; // reset buyFlag until next macd cross above
      }

      Comment


        #18
        Hello eberline,

        Thanks for your replies.

        To answer your latest post, if you would review post #12 we added the exit short condition after checking that we were in a short position. While the method ExitShort is ignored if we are not in a position (so what you have will work) it is better practice to test for the position before exiting.

        Comment


          #19
          Total Profit

          Thank you Paul.

          How do I set a total profit condition? Meaning when a total profit is reached, close the strategy for the day?

          Similarly, how would I set a total loss for the day?

          Thank You.

          Comment


            #20
            Hello eberline,

            Thanks for your post and questions.

            Moneymanagement while in a strategy is addressed in the sample code here: http://www.ninjatrader.com/support/f...ead.php?t=4084

            Please let me know if I can be of further assistance.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            68 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            39 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            63 views
            1 like
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            62 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            53 views
            0 likes
            Last Post CarlTrading  
            Working...
            X