NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 06-28-2012, 05:07 AM   #1
solondon
Junior Member
 
Join Date: Sep 2011
Posts: 14
Thanks: 1
Thanked 1 time in 1 post
Default transparent plot

Hi

trying to set a plot to transparent so i only see it on certain conditions, the commented section just Hides both plots. Any ideas how i accomplish this thanks

protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.MediumBlue), PlotStyle.Line, "LongProfitTarget"));
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "ShortProfitTarget"));
Overlay = true;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
LongProfitTarget.Set(Close[0]+ATR(5)[0]);
ShortProfitTarget.Set(Close[0]-ATR(5)[0]);

// if ((SMA(18)[0] >= SMA(18)[1]
// && SMA(9)[0] >= SMA(9)[1])
// && (SMA(18)[1] < SMA(18)[2] ||
// SMA(9)[1] < SMA(9)[2])
// && (ADX(14)[0]>16 || CrossAbove(ADX(14), 16, 10)))
//
// PlotColors[0][0] = Color.MediumBlue;
// else
// PlotColors[0][0] = Color.Transparent;
//
// if ((SMA(18)[0] <= SMA(18)[1]
// && SMA(9)[0] <= SMA(9)[1])
// && (SMA(18)[1] > SMA(18)[2] ||
// SMA(9)[1] > SMA(9)[2])
// && (ADX(14)[0]>16 || CrossAbove(ADX(14), 16, 10)))
//
// PlotColors[1][0] = Color.Orange;
// else
// PlotColors[1][0] = Color.Transparent;


}
solondon is offline  
Reply With Quote
Old 06-28-2012, 05:14 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

solondon, I would suggest calling the .Reset() method on the Plot for the bar where you would not like to see a value visualized - http://www.ninjatrader.com/support/h...ries_class.htm
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 06-29-2012, 06:42 AM   #3
solondon
Junior Member
 
Join Date: Sep 2011
Posts: 14
Thanks: 1
Thanked 1 time in 1 post
Default

hi i tried adding ShortProfitTarget.Reset(); but it dint make any difference, I cant find a working code example that does this, ie. show or hide the plot can you please help, thnx


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>
    /// Enter the description of your new custom indicator here
    /// </summary>
    [Description("Enter the description of your new custom indicator here")]
    public class aaPipMaximizer1ProfitTarget : Indicator
    {
        #region Variables
        // Wizard generated variables
            private int aTRperiod = 5; // Default setting for ATRperiod
        // User defined variables (add any user defined variables below)
        #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.MediumBlue), PlotStyle.Line, "LongProfitTarget"));
            Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "ShortProfitTarget"));
            Overlay				= true;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
         	LongProfitTarget.Set(Close[0]+ATR(5)[0]);
			ShortProfitTarget.Set(Close[0]-ATR(5)[0]);
			
			if ((SMA(18)[0] >= SMA(18)[1]
                && SMA(9)[0] >= SMA(9)[1]) 
				&& (SMA(18)[1] < SMA(18)[2] ||
				SMA(9)[1] < SMA(9)[2])
				&& (ADX(14)[0]>16 || CrossAbove(ADX(14), 16, 10)))
				PlotColors[0][0] = Color.MediumBlue;
			else
//				LongProfitTarget.Reset();
				PlotColors[0][0] = Color.Transparent;
//
			if ((SMA(18)[0] <= SMA(18)[1]
                &&  SMA(9)[0] <= SMA(9)[1])
				&& (SMA(18)[1] > SMA(18)[2] ||
				SMA(9)[1] > SMA(9)[2])
				&& (ADX(14)[0]>16 || CrossAbove(ADX(14), 16, 10))) 
				PlotColors[0][0] = Color.Orange;
			else
//				ShortProfitTarget.Reset();
				PlotColors[1][0] = Color.Transparent;

			}

        #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 LongProfitTarget
        {
            get { return Values[0]; }
        }

        [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 ShortProfitTarget
        {
            get { return Values[1]; }
        }

        [Description("")]
        [GridCategory("Parameters")]
        public int ATRperiod
        {
            get { return aTRperiod; }
            set { aTRperiod = Math.Max(1, value); }
        }
        #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 aaPipMaximizer1ProfitTarget[] cacheaaPipMaximizer1ProfitTarget = null;

        private static aaPipMaximizer1ProfitTarget checkaaPipMaximizer1ProfitTarget = new aaPipMaximizer1ProfitTarget();

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(int aTRperiod)
        {
            return aaPipMaximizer1ProfitTarget(Input, aTRperiod);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(Data.IDataSeries input, int aTRperiod)
        {
            if (cacheaaPipMaximizer1ProfitTarget != null)
                for (int idx = 0; idx < cacheaaPipMaximizer1ProfitTarget.Length; idx++)
                    if (cacheaaPipMaximizer1ProfitTarget[idx].ATRperiod == aTRperiod && cacheaaPipMaximizer1ProfitTarget[idx].EqualsInput(input))
                        return cacheaaPipMaximizer1ProfitTarget[idx];

            lock (checkaaPipMaximizer1ProfitTarget)
            {
                checkaaPipMaximizer1ProfitTarget.ATRperiod = aTRperiod;
                aTRperiod = checkaaPipMaximizer1ProfitTarget.ATRperiod;

                if (cacheaaPipMaximizer1ProfitTarget != null)
                    for (int idx = 0; idx < cacheaaPipMaximizer1ProfitTarget.Length; idx++)
                        if (cacheaaPipMaximizer1ProfitTarget[idx].ATRperiod == aTRperiod && cacheaaPipMaximizer1ProfitTarget[idx].EqualsInput(input))
                            return cacheaaPipMaximizer1ProfitTarget[idx];

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

                aaPipMaximizer1ProfitTarget[] tmp = new aaPipMaximizer1ProfitTarget[cacheaaPipMaximizer1ProfitTarget == null ? 1 : cacheaaPipMaximizer1ProfitTarget.Length + 1];
                if (cacheaaPipMaximizer1ProfitTarget != null)
                    cacheaaPipMaximizer1ProfitTarget.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheaaPipMaximizer1ProfitTarget = 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>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(int aTRperiod)
        {
            return _indicator.aaPipMaximizer1ProfitTarget(Input, aTRperiod);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public Indicator.aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(Data.IDataSeries input, int aTRperiod)
        {
            return _indicator.aaPipMaximizer1ProfitTarget(input, aTRperiod);
        }
    }
}

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    public partial class Strategy : StrategyBase
    {
        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(int aTRperiod)
        {
            return _indicator.aaPipMaximizer1ProfitTarget(Input, aTRperiod);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public Indicator.aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(Data.IDataSeries input, int aTRperiod)
        {
            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.aaPipMaximizer1ProfitTarget(input, aTRperiod);
        }
    }
}
#endregion
solondon is offline  
Reply With Quote
Old 06-29-2012, 06:48 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

solondon, looking at your code - why do you set a value in the first place that you do not want to be set, so visualized? I would move the setting of value directly into your conditions for plotting then.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 06-29-2012, 08:40 AM   #5
solondon
Junior Member
 
Join Date: Sep 2011
Posts: 14
Thanks: 1
Thanked 1 time in 1 post
Default

the code was based on the only example i could find in your documentation

http://www.ninjatrader.com/support/h...plotcolors.htm

I tried it like that because what i think your suggesting doesnt work ie.

if ((SMA(18)[0] >= SMA(18)[1]
&& SMA(9)[0] >= SMA(9)[1])
&& (SMA(18)[1] < SMA(18)[2] ||
SMA(9)[1] < SMA(9)[2])
&& (ADX(14)[0]>16 || CrossAbove(ADX(14), 16, 10)))
LongProfitTarget.Set(Close[0]+ATR(5)[0]);


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>
    /// Enter the description of your new custom indicator here
    /// </summary>
    [Description("Enter the description of your new custom indicator here")]
    public class aaPipMaximizer1ProfitTarget : Indicator
    {
        #region Variables
        // Wizard generated variables
            private int aTRperiod = 5; // Default setting for ATRperiod
        // User defined variables (add any user defined variables below)
        #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.MediumBlue), PlotStyle.Line, "LongProfitTarget"));
            Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "ShortProfitTarget"));
            Overlay				= true;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
//         	LongProfitTarget.Set(Close[0]+ATR(5)[0]);
//			ShortProfitTarget.Set(Close[0]-ATR(5)[0]);
			
			if ((SMA(18)[0] >= SMA(18)[1]
                && SMA(9)[0] >= SMA(9)[1]) 
				&& (SMA(18)[1] < SMA(18)[2] ||
				SMA(9)[1] < SMA(9)[2])
				&& (ADX(14)[0]>16 || CrossAbove(ADX(14), 16, 10)))
				LongProfitTarget.Set(Close[0]+ATR(5)[0]);

			if ((SMA(18)[0] <= SMA(18)[1]
                &&  SMA(9)[0] <= SMA(9)[1])
				&& (SMA(18)[1] > SMA(18)[2] ||
				SMA(9)[1] > SMA(9)[2])
				&& (ADX(14)[0]>16 || CrossAbove(ADX(14), 16, 10))) 
				ShortProfitTarget.Set(Close[0]-ATR(5)[0]);

			}

        #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 LongProfitTarget
        {
            get { return Values[0]; }
        }

        [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 ShortProfitTarget
        {
            get { return Values[1]; }
        }

        [Description("")]
        [GridCategory("Parameters")]
        public int ATRperiod
        {
            get { return aTRperiod; }
            set { aTRperiod = Math.Max(1, value); }
        }
        #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 aaPipMaximizer1ProfitTarget[] cacheaaPipMaximizer1ProfitTarget = null;

        private static aaPipMaximizer1ProfitTarget checkaaPipMaximizer1ProfitTarget = new aaPipMaximizer1ProfitTarget();

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(int aTRperiod)
        {
            return aaPipMaximizer1ProfitTarget(Input, aTRperiod);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(Data.IDataSeries input, int aTRperiod)
        {
            if (cacheaaPipMaximizer1ProfitTarget != null)
                for (int idx = 0; idx < cacheaaPipMaximizer1ProfitTarget.Length; idx++)
                    if (cacheaaPipMaximizer1ProfitTarget[idx].ATRperiod == aTRperiod && cacheaaPipMaximizer1ProfitTarget[idx].EqualsInput(input))
                        return cacheaaPipMaximizer1ProfitTarget[idx];

            lock (checkaaPipMaximizer1ProfitTarget)
            {
                checkaaPipMaximizer1ProfitTarget.ATRperiod = aTRperiod;
                aTRperiod = checkaaPipMaximizer1ProfitTarget.ATRperiod;

                if (cacheaaPipMaximizer1ProfitTarget != null)
                    for (int idx = 0; idx < cacheaaPipMaximizer1ProfitTarget.Length; idx++)
                        if (cacheaaPipMaximizer1ProfitTarget[idx].ATRperiod == aTRperiod && cacheaaPipMaximizer1ProfitTarget[idx].EqualsInput(input))
                            return cacheaaPipMaximizer1ProfitTarget[idx];

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

                aaPipMaximizer1ProfitTarget[] tmp = new aaPipMaximizer1ProfitTarget[cacheaaPipMaximizer1ProfitTarget == null ? 1 : cacheaaPipMaximizer1ProfitTarget.Length + 1];
                if (cacheaaPipMaximizer1ProfitTarget != null)
                    cacheaaPipMaximizer1ProfitTarget.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheaaPipMaximizer1ProfitTarget = 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>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(int aTRperiod)
        {
            return _indicator.aaPipMaximizer1ProfitTarget(Input, aTRperiod);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public Indicator.aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(Data.IDataSeries input, int aTRperiod)
        {
            return _indicator.aaPipMaximizer1ProfitTarget(input, aTRperiod);
        }
    }
}

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    public partial class Strategy : StrategyBase
    {
        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(int aTRperiod)
        {
            return _indicator.aaPipMaximizer1ProfitTarget(Input, aTRperiod);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public Indicator.aaPipMaximizer1ProfitTarget aaPipMaximizer1ProfitTarget(Data.IDataSeries input, int aTRperiod)
        {
            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.aaPipMaximizer1ProfitTarget(input, aTRperiod);
        }
    }
}
#endregion
solondon is offline  
Reply With Quote
Old 06-29-2012, 09:36 AM   #6
solondon
Junior Member
 
Join Date: Sep 2011
Posts: 14
Thanks: 1
Thanked 1 time in 1 post
Default

needed the following in Onbarupdate

if (CurrentBar < 20) return;

thanks for the help, cant beleive i forgot this!
solondon is offline  
Reply With Quote
The following user says thank you to solondon for this post:
Old 06-29-2012, 09:40 AM   #7
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

Glad to hear it works now for you.
NinjaTrader_Bertrand is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Bertrand for this post:
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
transparent solvmatic Charting 12 12-01-2011 03:10 PM
Semi-transparent windows nintra Suggestions And Feedback 5 11-18-2010 09:34 AM
Scaling goes away chart Transparent gg80108 Version 7 Beta General Questions & Bug Reports 1 06-04-2010 09:26 AM
Transparent plot is no longer in the Data Box? Wessel Version 7 Beta General Questions & Bug Reports 2 04-19-2010 11:33 AM
Transparent colors yellowTrader Indicator Development 9 03-03-2009 11:22 AM


All times are GMT -6. The time now is 03:54 PM.