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

transparent plot

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

    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;


    }

    #2
    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
    BertrandNinjaTrader Customer Service

    Comment


      #3
      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

      Comment


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

        Comment


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



          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

          Comment


            #6
            needed the following in Onbarupdate

            if (CurrentBar < 20) return;

            thanks for the help, cant beleive i forgot this!

            Comment


              #7
              Glad to hear it works now for you.
              BertrandNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by rtwave, 04-12-2024, 09:30 AM
              4 responses
              29 views
              0 likes
              Last Post rtwave
              by rtwave
               
              Started by yertle, Yesterday, 08:38 AM
              7 responses
              28 views
              0 likes
              Last Post yertle
              by yertle
               
              Started by bmartz, 03-12-2024, 06:12 AM
              2 responses
              21 views
              0 likes
              Last Post bmartz
              by bmartz
               
              Started by funk10101, Today, 12:02 AM
              0 responses
              6 views
              0 likes
              Last Post funk10101  
              Started by gravdigaz6, Yesterday, 11:40 PM
              1 response
              9 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X