Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Looking for automated trade trigger when MACD line crosses 0 line

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

    Looking for automated trade trigger when MACD line crosses 0 line

    Folks,
    I have tried tweaking the strategy several times, but the backtest returns nothing but zeros. I am trying to create an automated strategy where the trade is triggered when the MACD line crosses over the 0 line. My settings are 20/50/1 (so there is no signal line).
    In the condition builder, I have it plotted when the MACD line crosses above Average line, go long. I've removed most of the bells and whistles I originally had in the strategy just to leave the core trigger in and still not getting any backtest results. Tried variety of futures and timeframes. Looking for help.
    Thanks

    #2
    Hello Decoda,

    Thank you for your post.

    I have attached a screenshot of how to create and test for the MACD crossing above the 0 line

    Let me know if this helps in your development
    Attached Files
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Cal,
      Thanks for the help. I guess I was overthinking it, that seems the obvious way to do that.
      I have one other question, I would like to confirm this trigger (a lot of times the MACD will
      cross the zero line only to hang out there and go back, these are false triggers I'd like to
      avoid). I'm thinking of either when the MACD diverges from the zero line (MACD diff >.01)
      or when EMA20>EMA50 the trade is triggered from the original cross. The only problem
      is when I do either of these my backtests bring back all zero's.

      Ideally, I would like a cross above to "signal" the trade, but the trade actually happens once
      the lines diverge apart (by a tick or .01). I'm try to avoid an if/then scenario within a set amount
      of bars, but rather "trigger is activated by cross above, but wait for divergence and go long when it happens- however long it would take". If it doesn't happen, a cross below will eventually occur and invalidate the first cross. A trade would not occur on the second cross because my Current Position settings prevents
      me from going Long or Short if there is a position already established (I've set it to must
      be flat in order to Long or Short In).
      Can this be done?
      Thanks again for your help
      Last edited by decoda; 12-14-2014, 12:42 PM.

      Comment


        #4
        Hello decoda,

        Thank you for your patience.

        I could not think how it would be possible to do the divergence from the zero line in the Strategy Wizard. Below is the code that presents the idea for Long:
        Code:
                #region Variables
                private bool check = false;
        		private double valueAtCross = 0;
                #endregion
        
                /// <summary>
                /// This method is used to configure the strategy and is called once before any strategy method is called.
                /// </summary>
                protected override void Initialize()
                {
        			
                }
        
                /// <summary>
                /// Called on each bar update event (incoming tick)
                /// </summary>
                protected override void OnBarUpdate()
                {
        			if(CrossAbove(MACD(20, 50, 1).Diff, 0, 1)
        				&& Position.MarketPosition == MarketPosition.Flat)
        			{
        				check = true;
        				valueAtCross = MACD(20, 50, 1).Diff[0];
        			}
        			if(check
        				&& (MACD(20, 50, 1).Diff[0] > valueAtCross + 1*TickSize || EMA(20)[0] > EMA(50)[0]))
        			{
        				EnterLong();
        				check = false;
        			}
                }

        Comment


          #5
          Patrick,
          Thanks for your help. I didn't have any luck in the wizard either, I figured it was going to have to be coded. I'm going to try your code to see if it gives what I'm looking for. I'm not a programmer, but have been doing some C# research and going to try to build a loop where it keeps going until one of two parameters are reached (divergence occurs or an opposite cross). I think it's doable, and the code you've provided may be on the same page; I'll let you know.
          Thanks again for the help.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Harry, 05-02-2018, 01:54 PM
          10 responses
          3,203 views
          0 likes
          Last Post tharton3  
          Started by cre8able, Yesterday, 01:16 PM
          3 responses
          11 views
          0 likes
          Last Post cre8able  
          Started by ChartTourist, Today, 08:22 AM
          0 responses
          6 views
          0 likes
          Last Post ChartTourist  
          Started by LiamTwine, Today, 08:10 AM
          0 responses
          2 views
          0 likes
          Last Post LiamTwine  
          Started by Balage0922, Today, 07:38 AM
          0 responses
          5 views
          0 likes
          Last Post Balage0922  
          Working...
          X