Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with MACD strategy

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

    Help with MACD strategy

    I understand how to program this strategy in the wizzard, but what i can not figure out is how to add a second condition that would only trigger if the MACD line is crosing above the zero line or below the zero line.

    1. condition is if the MACD crosses above or below the signal line. (i can do this)
    and
    2. condition is if the MACD line is crosing above or below the zero line.

    any help will be appreciated, thanks in advance Tom

    #2
    Tom, welcome to our forums - you would need to let it Cross Above / Below the numerical value of 0 - you can find this in the Misc category in the wizard.

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks for repply, still having problems

      Thanks for your quick repply Bertrand, I must be doing something wrong.

      It is not entering into to trades, I tried to paste the code so you can see but it will not allow me beacause of the size. Can i post the code in some other way, please let me know.
      Any help again would be appreciated, thanks Tom

      Comment


        #4
        Please attach the code as a zip file and you should be able to put that here. Thanks.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Code

          Hi Bertrand,

          attached is the code
          Attached Files

          Comment


            #6
            tomonly23,

            Your code does not have any conditions for checking it versus a zero line.

            If you want to check MACD versus a zero line you want to select MACD on the left hand side of the Condition Builder and then selecting Misc>Numeric value>0 on the right hand side. Then choose Cross Above/Below.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Hi,

              I'm new and i'm trying to create a MACD crossover strategy and wondered why [tomonly23] you use a plot of MACD in time bar 0 but plot .avg in bar -1?

              Is it something specific i should consider?

              cheers

              Comment


                #8
                sjmuk, welcome to our forums - you would use this to compare the MACD value to the MACD Avg value, for example for a cross above / below to trigger signals.



                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  makes sense

                  ok that makes sense. And very prompt response by the way... thanks

                  Comment


                    #10
                    Macd cross over strategy

                    This does not work for me...
                    how can i set the zero line to -0.1 or 1.0

                    Comment


                      #11
                      Hello julian nisbett,

                      Thank you for your post.

                      Are you working in NinjaTrader 7 or NinjaTrader 8? And are you using the Strategy Wizard or Builder or writing the code directly?

                      Setting the MACD's Zero Line to a new value would require programming outside the Builder or Wizard. You could still check the condition against the new value in the Builder or Wizard. Please see the attached image for an example of this condition in the Strategy Builder of NinjaTrader 8.

                      I look forward to assisting you further.
                      Attached Files

                      Comment


                        #12
                        I know of this but it does not trigger my order
                        i got a little code there

                        ________________________________________

                        #region Using declarations
                        using System;
                        using System.Collections.Generic;
                        using System.ComponentModel;
                        using System.ComponentModel.DataAnnotations;
                        using System.Linq;
                        using System.Text;
                        using System.Threading.Tasks;
                        using System.Windows;
                        using System.Windows.Input;
                        using System.Windows.Media;
                        using System.Xml.Serialization;
                        using NinjaTrader.Cbi;
                        using NinjaTrader.Gui;
                        using NinjaTrader.Gui.Chart;
                        using NinjaTrader.Gui.SuperDom;
                        using NinjaTrader.Gui.Tools;
                        using NinjaTrader.Data;
                        using NinjaTrader.NinjaScript;
                        using NinjaTrader.Core.FloatingPoint;
                        using NinjaTrader.NinjaScript.Indicators;
                        using NinjaTrader.NinjaScript.DrawingTools;
                        #endregion


                        //This namespace holds Strategies in this folder and is required. Do not change it.
                        namespace NinjaTrader.NinjaScript.Strategies
                        {
                        public class MyCustomStrategy : Strategy
                        {
                        protected override void OnStateChange()
                        {

                        Add (MACD (50,100,90));
                        Add (MACD (50,100,90));

                        if (State == State.SetDefaults)
                        {
                        Description = @"Enter the description for your new custom Strategy here.";
                        Name = "MyCustomStrategy";
                        Calculate = Calculate.OnBarClose;
                        EntriesPerDirection = 1;
                        EntryHandling = EntryHandling.AllEntries;
                        IsExitOnSessionCloseStrategy = true;
                        ExitOnSessionCloseSeconds = 30;
                        IsFillLimitOnTouch = false;
                        MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
                        OrderFillResolution = OrderFillResolution.Standard;
                        Slippage = 0;
                        StartBehavior = StartBehavior.WaitUntilFlat;
                        TimeInForce = TimeInForce.Gtc;
                        TraceOrders = false;
                        RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
                        StopTargetHandling = StopTargetHandling.PerEntryExecution;
                        BarsRequiredToTrade = 20;
                        // Disable this property for performance gains in Strategy Analyzer optimizations
                        // See the Help Guide for additional information
                        IsInstantiatedOnEachOptimizationIteration = true;
                        }
                        else if (State == State.Configure)
                        {
                        }
                        }

                        protected override void OnBarUpdate()
                        {
                        if (CrossAbove (MACD(50,100,90), MACD(50,100,90).Avg, 1)
                        && MACD (50,100,90) [0] > 0.01)
                        {
                        EnterLong (1, "Buy Long");

                        }

                        if (CrossAbove (MACD(50,100,90), MACD(50,100,90).Avg, 1)
                        && MACD (50,100,90).Avg[0] < 0)
                        {
                        EnterShort (1, "Sell Short");


                        //Add your custom strategy logic here.
                        }
                        }
                        }}

                        Comment


                          #13
                          Hello julian nisbett,

                          Thank you for your response.

                          I am able to get executions in my testing of these conditions. Can you provide the following information?
                          • Who are you connected to? This is displayed by green on lower left corner of the Control Center window.
                          • What instrument(s) have you selected? If a futures instrument, what expiry is selected? (Example: ES 06-13)
                          • What period type is selected for your chart(s)? (Example: Tick, Minute, Day, etc.)
                          • Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?

                          I look forward to your response.

                          Comment


                            #14
                            sorry please remove Add (MACD (50,100,90));
                            Add (MACD (50,100,90));

                            then it should work...

                            I'm testing it on NQ 09-18
                            Ninjatrader Continuum (Live)

                            Comment


                              #15
                              Hello julian nisbett,

                              Thank you for your response.

                              I am in fact able to see the trades occur. Can you answer the following items?
                              • What period type is selected for your chart(s)? (Example: Tick, Minute, Day, etc.)
                              • Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?

                              I look forward to your response.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by elderan, Today, 08:03 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post elderan
                              by elderan
                               
                              Started by algospoke, Today, 06:40 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post algospoke  
                              Started by maybeimnotrader, Today, 05:46 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post maybeimnotrader  
                              Started by quantismo, Today, 05:13 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post quantismo  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              8 responses
                              169 views
                              0 likes
                              Last Post jeronymite  
                              Working...
                              X