Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MACD Crossover - wont execute any trade

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

    MACD Crossover - wont execute any trade

    Hi i tried to build a simple macd crossover strategy but when i backtest the strategy no trades are placed, can somebody help me with the code please.

    my code:

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class macd : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // User defined variables (add any user defined variables below)
    #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()
    {

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
    {
    EnterLong(DefaultQuantity, "");
    DrawArrowLine("My arrow line" + CurrentBar, 0, 0, 0, 0, Color.Green);
    }

    // Condition set 2
    if (CrossBelow(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
    {
    EnterShort(DefaultQuantity, "");
    DrawArrowLine("My arrow line" + CurrentBar, 0, 0, 0, 0, Color.Blue);
    }
    }

    #region Properties
    [Description("")]
    [Category("Parameters")]
    public int MyInput0
    {
    get { return myInput0; }
    set { myInput0 = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #2
    Hi aidan545,

    Please check your Control Center logs for errors. Also, do you have enough data for the instrument you are backtesting? Potentially you may have a naming conflict. Please try renaming your strategy to something other than MACD because it is like a reserved word.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      im new to the software

      hi - i think i have enough data im using yahoo for the sp500 , i dont know where the error log can be found and i dont know how to rename the strategy .. if you could help me that would be great

      Comment


        #4
        Hi aidan545, the log tab can be found in the Control Center on the right side. Check there if any errors are listed when you run your strategy. To save this strategy to a new name, right click in it and select 'Save As', then enter a new name and you should be good to go.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        649 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        370 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        573 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        576 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X