Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator to print MACD to output window

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

    Indicator to print MACD to output window

    hi there

    I am using the code below to print MACD values to the output window, which it is doing fine but it is not printing the MACD Average, how can I get it to do this?

    Thanks in advance.

    Here is the 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.Gui.Chart;
    #endregion

    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    /// <summary>
    ///
    /// </summary>
    [Description("")]
    public class WilliamsRValuePrint : Indicator
    {
    #region Variables

    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    Overlay = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    //double rsiValue = WilliamsR(40)[0]; RSI(Median, 14, 1)[0];

    //double rsiValue = CashCloseES().PriorClose[0];
    double rsiValue = MACD(6,13,9)[0];
    // Prints whatever indicator etc value against the timestamp.
    Print("" + Time[0] + "" + " " + rsiValue.ToString("N2"));


    //Produces comma separated file for data export and ##-## file update.
    //Print(Time[0]+ "," +Open[0]+ ","+High[0]+ ","+Low[0]+ ","+Close[0]+ ","+Volume[0]);


    Plot0.Set(rsiValue);
    }

    #region Properties
    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries Plot0
    {
    get { return Values[0]; }
    }

    #endregion
    }
    }

    #region NinjaScript generated code. Neither change nor remove.
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    public partial class Indicator : IndicatorBase
    {
    private WilliamsRValuePrint[] cacheWilliamsRValuePrint = null;

    private static WilliamsRValuePrint checkWilliamsRValuePrint = new WilliamsRValuePrint();

    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    public WilliamsRValuePrint WilliamsRValuePrint()
    {
    return WilliamsRValuePrint(Input);
    }

    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    public WilliamsRValuePrint WilliamsRValuePrint(Data.IDataSeries input)
    {
    if (cacheWilliamsRValuePrint != null)
    for (int idx = 0; idx < cacheWilliamsRValuePrint.Length; idx++)
    if (cacheWilliamsRValuePrint[idx].EqualsInput(input))
    return cacheWilliamsRValuePrint[idx];

    lock (checkWilliamsRValuePrint)
    {
    if (cacheWilliamsRValuePrint != null)
    for (int idx = 0; idx < cacheWilliamsRValuePrint.Length; idx++)
    if (cacheWilliamsRValuePrint[idx].EqualsInput(input))
    return cacheWilliamsRValuePrint[idx];

    WilliamsRValuePrint indicator = new WilliamsRValuePrint();
    indicator.BarsRequired = BarsRequired;
    indicator.CalculateOnBarClose = CalculateOnBarClose;
    #if NT7
    indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
    indicator.MaximumBarsLookBack = MaximumBarsLookBack;
    #endif
    indicator.Input = input;
    Indicators.Add(indicator);
    indicator.SetUp();

    WilliamsRValuePrint[] tmp = new WilliamsRValuePrint[cacheWilliamsRValuePrint == null ? 1 : cacheWilliamsRValuePrint.Length + 1];
    if (cacheWilliamsRValuePrint != null)
    cacheWilliamsRValuePrint.CopyTo(tmp, 0);
    tmp[tmp.Length - 1] = indicator;
    cacheWilliamsRValuePrint = tmp;
    return indicator;
    }
    }
    }
    }

    // This namespace holds all market analyzer column definitions and is required. Do not change it.
    namespace NinjaTrader.MarketAnalyzer
    {
    public partial class Column : ColumnBase
    {
    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.WilliamsRValuePrint WilliamsRValuePrint()
    {
    return _indicator.WilliamsRValuePrint(Input);
    }

    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    public Indicator.WilliamsRValuePrint WilliamsRValuePrint(Data.IDataSeries input)
    {
    return _indicator.WilliamsRValuePrint(input);
    }
    }
    }

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    public partial class Strategy : StrategyBase
    {
    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.WilliamsRValuePrint WilliamsRValuePrint()
    {
    return _indicator.WilliamsRValuePrint(Input);
    }

    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    public Indicator.WilliamsRValuePrint WilliamsRValuePrint(Data.IDataSeries input)
    {
    if (InInitialize && input == null)
    throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

    return _indicator.WilliamsRValuePrint(input);
    }
    }
    }
    #endregion

    #2
    Hi GKonheiser, you would need to point to the Avg plot / series of the MACD -

    double rsiValue = MACD(6,13,9).Avg[0];

    http://www.ninjatrader.com/support/h...gence_macd.htm
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks that great. How can I change the number of decimal places it prints. At the moment its only printing 2 D.P for the Average and I would like 3 or 4 D.P?

      Comment


        #4
        You have the print formatting set to 2 ( .ToString("N2")); ). You can of course change that to 3 or 4 as needed ("N3", "N4").
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by mg.watts, Today, 03:17 PM
        0 responses
        8 views
        0 likes
        Last Post mg.watts  
        Started by JTizz, Today, 01:20 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by omermirza, Today, 12:39 PM
        2 responses
        12 views
        0 likes
        Last Post omermirza  
        Started by mballagan, Today, 01:02 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Kate  
        Started by larkmail, Today, 12:30 PM
        3 responses
        11 views
        0 likes
        Last Post NinjaTrader_Kate  
        Working...
        X