Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by helpwanted, Today, 03:06 AM
        1 response
        7 views
        0 likes
        Last Post sarafuenonly123  
        Started by Brevo, Today, 01:45 AM
        0 responses
        7 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        5 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        242 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        384 views
        1 like
        Last Post Gavini
        by Gavini
         
        Working...
        X