Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Prevent Values[0][1] from displaying on chart.

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

    Prevent Values[0][1] from displaying on chart.

    Greetings!

    I am trying to get my indicator to be read by the strategy builder. My understanding is that the strategy builder reads what the data box outputs. Below is a sample of the piece of code I am having trouble with.

    Values[4][0] = MA5[0];
    Values[5][0] = MA6[0];
    Values[6][0] = Condition1 ? 1 : 0;
    Values[7][0] = Condition2? 1 : 0;

    In the snippet above, Values[4][0] and Values[5][0] plot correctly on the chart and plot correctly in the data box.

    However...

    Values[6][0] and Values[7][0] do not. These values output a 1 or a 0 to the data box AND plot a 1 or a 0 on the chart.

    *Condition1 and Condition2 are booleans. Without the ? operator I do not know how to pass a value to the Data Box.*

    My goal is to get the strategy builder to read Condition1 as True or False or 1 or 0 without plotting anything on the chart.

    Any help is appreciated. Thanks in advance!​

    #2
    Hello TheTechnician86,

    The question mark colon format is a ternary operator. If the condition is true, the value after the question mark is returned if the value is false the value after the colon is returned.
    W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.


    The values do need to be set in a plot series to be accessible by the Strategy Builder.
    If you are not wanting to see these plots on the chart, set the Brush to Transparent.

    AddPlot(Brushes.Transparent, "MyPlot");
    Or
    Plots[0].Brush = Brushes.Transparent;
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea

      Thanks for the reply. I have this

      On State Change
      AddPlot(Brushes.Orange, "MA 5");
      AddPlot(Brushes.Orange, "MA 6");
      AddPlot(Brushes.Green, "Pos Div");
      AddPlot(Brushes.Red, "Neg Div");

      On Bar Update
      If currentbar >0
      MA5 = double
      MA6 = double
      PosDig = bool
      NegDiv = bool

      if (PosDiv)
      {
      Draw.TriangleUp(this....);
      }

      if (NegDiv)
      {
      Draw.TriangleDown(this,.....);
      }


      Values[4][0] = MA5[0];
      Values[5][0] = MA6[0];
      Values[6][0] = PosDiv ? 1 : 0;
      Values[7][0] = NegDiv ? 1 : 0;​


      [Browsable(false)]
      [XmlIgnore]
      public Series<double> MA5Plot => Values[4];

      [Browsable(false)]
      [XmlIgnore]
      public Series<double> MA6Plot => Values[5];

      [Browsable(false)]
      [XmlIgnore]
      public Series<double> PosDivPlot => Values[6];

      [Browsable(false)]
      [XmlIgnore]
      public Series<double> NegDivPlot => Values[7];


      What is going right
      1. I am getting the values I want in the data box.
      2. PosDiv and NegDiv (which are already defined) are plotting correctly.

      What I need help with
      1. Values[6][0] and Values[7][0] are plotting on the chart as a 1 or a 0, which I do not want.
      2. I want to know if the PosDiv and NegDiv is true or false (I am thinking they need to be a 1 or a 0) so that i can use that boolean (or value) in the strategy builder.

      Thanks again!

      Comment


        #4
        Hello TheTechnician86,

        "Values[6][0] and Values[7][0] are plotting on the chart as a 1 or a 0, which I do not want."

        Set the plot brush to Transparent.

        "I want to know if the PosDiv and NegDiv is true or false (I am thinking they need to be a 1 or a 0) so that i can use that boolean (or value) in the strategy builder."

        Is this not currently working using a 1 for true and 0 for false?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Chelsea

          Thanks for the response. I have not been successful with setting the plot brush to transparent. I still get a 1 and 0 plotted on the chart. I think the problem is in the Values region of my code. I think adding ? 1 : 0; to values operation is what is somehow adding a plot to the chart.

          I tried commenting out
          AddPlot(Brushes.Transparent, "Pos Div");
          AddPlot(Brushes.Transparent, "Neg Div");

          but that still plotted a 1 and a 0 to the chart

          I tried commenting out the properties region and that did not work.
          I tried removing the ? 1 : 0; from the values section and that worked but then I don't get the 1 or 0 value.

          I am very confused as to how to pass the 1 or 0 value for every one of my conditions so that it is usable in the strategy builder.

          My obfuscated code is below. Can you point me in the right direction?


          namespace NinjaTrader.NinjaScript.Indicators
          {
          public class PriceMAdivergence : Indicator
          {
          private EMA MA1, MA2, MA3, MA4, MA5, MA6;

          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = @"Display Price MA Divergence";
          Name = "PriceMAdivergence";
          MA1Length = 1;
          MA2Length = 10;
          MA3Length = 20;
          MA4Length = 30;
          MA5Length = 40;
          MA6Length = 50;
          LookBackBarsLength = 20;
          DivDistFrmMA = 30;
          IsSuspendedWhileInactive = true;
          DisplayInDataBox = true;
          DrawOnPricePanel = true;
          DrawHorizontalGridLines = true;
          DrawVerticalGridLines = true;
          IsOverlay = true;
          PaintPriceMarkers = false;
          Calculate = Calculate.OnBarClose;
          MaximumBarsLookBack = MaximumBarsLookBack.Infinite;

          region Plots
          AddPlot(Brushes.LimeGreen, "MA 1");
          AddPlot(Brushes.Red, "MA 2");
          AddPlot(Brushes.LimeGreen, "MA 3");
          AddPlot(Brushes.Purple, "MA 4");
          AddPlot(Brushes.LimeGreen, "MA 5");
          AddPlot(Brushes.Orange, "MA 6");
          AddPlot(Brushes.Transparent, "Pos Div");
          AddPlot(Brushes.Transparent, "Neg Div");
          AddPlot(Brushes.Transparent, "Scalp CrossOver");
          AddPlot(Brushes.Transparent, "Scalp CrossUnder");
          AddPlot(Brushes.Transparent, "DayTradeCrossOver");
          AddPlot(Brushes.Transparent, "DayTradeCrossUnder");
          AddPlot(Brushes.Transparent, "SwingCrossOver");
          AddPlot(Brushes.Transparent, "SwingCrossUnder");
          AddPlot(Brushes.Transparent, "ScalpBuyTrend");
          AddPlot(Brushes.Transparent, "ScalpSellTrend");
          AddPlot(Brushes.Transparent, "DayBuyTrend");
          AddPlot(Brushes.Transparent, "DaySellTrend");
          AddPlot(Brushes.Transparent, "AplusBuy");
          AddPlot(Brushes.Transparent, "AplusSell");
          AddPlot(Brushes.Transparent, "ABuy");
          AddPlot(Brushes.Transparent, "ASell");
          AddPlot(Brushes.Transparent, "BBuy");
          AddPlot(Brushes.Transparent, "BSell");
          AddPlot(Brushes.Transparent, "CplusBuy");
          AddPlot(Brushes.Transparent, "CplusSell");
          AddPlot(Brushes.Transparent, "CBuy");
          AddPlot(Brushes.Transparent, "CSell");
          #endregion
          }

          else if (State == State.DataLoaded)
          {
          MA1 = EMA(MA1Length);
          MA2 = EMA(MA2Length);
          MA3 = EMA(MA3Length);
          MA4 = EMA(MA4Length);
          MA5 = EMA(MA5Length);
          MA6 = EMA(MA6Length);
          }
          }

          protected override void OnBarUpdate()
          {
          if (CurrentBar > 0)
          {
          region Declarations
          double MA1Value = MA1[0];
          double MA2Value = MA2[0];
          double MA3Value = MA3[0];
          double MA4Value = MA4[0];
          double MA5Value = MA5[0];
          double MA6Value = MA6[0];

          bool PosDiv = Close[0] > Close[1] ;
          bool NegDiv = Close[0] > Close[1];
          bool ScalpCrossOver = Close[0] > Close[1];
          bool ScalpCrossUnder = Close[0] > Close[1];
          bool DayTradeCrossOver = Close[0] > Close[1];
          bool DayTradeCrossUnder = Close[0] > Close[1];
          bool SwingCrossOver = Close[0] > Close[1];
          bool SwingCrossUnder = Close[0] > Close[1];

          bool ScalpBuyTrend = MA1Value > MA2Value;
          bool ScalpSellTrend = MA1Value < MA2Value;
          bool DayBuyTrend = MA1Value < MA2Value;
          bool DaySellTrend = MA1Value < MA2Value;
          bool SwingBuyTrend = MA1Value < MA2Value;
          bool SwingSellTrend = MA1Value < MA2Value;

          bool CBuy = Close[0] > Close[1];
          bool CSell = Close[0] > Close[1];
          bool CplusBuy = Close[0] > Close[1];
          bool CplusSell = Close[0] > Close[1];
          bool BBuy = Close[0] > Close[1];
          bool BSell = Close[0] > Close[1];
          bool ABuy = Close[0] > Close[1];
          bool ASell = Close[0] > Close[1];
          bool AplusBuy = Close[0] > Close[1];
          bool AplusSell = Close[0] > Close[1];
          #endregion

          region Conditions
          if (PosDiv)
          {
          Draw.TriangleUp(this, "PosDiv" + CurrentBar, false, 0, Low[0] - ((TickSize * (High[0] - Low[0])) * 3) * 3, Brushes.Orange);
          }

          if (NegDiv)
          {
          Draw.TriangleDown(this, "NegDiv" + CurrentBar, false, 0, High[0] + ((TickSize * (High[0] - Low[0])) * 3) * 3, Brushes.Orange);
          }

          #endregion

          region Values
          Values[0][0] = MA1[0];
          Values[1][0] = MA2[0];
          Values[2][0] = MA3[0];
          Values[3][0] = MA4[0];
          Values[4][0] = MA5[0];
          Values[5][0] = MA6[0];
          Values[6][0] = PosDiv ? 1 : 0;
          Values[7][0] = NegDiv ? 1 : 0;
          Values[8][0] = ScalpCrossOver ? 1 : 0;
          Values[9][0] = ScalpCrossUnder ? 1 : 0;
          Values[10][0] = DayTradeCrossOver ? 1 : 0;
          Values[11][0] = DayTradeCrossUnder ? 1 : 0;
          Values[12][0] = SwingCrossOver ? 1 : 0;
          Values[13][0] = SwingCrossUnder ? 1 : 0;
          Values[14][0] = ScalpBuyTrend ? 1 : 0;
          Values[15][0] = ScalpSellTrend ? 1 : 0;
          Values[16][0] = DayBuyTrend ? 1 : 0;
          Values[17][0] = DaySellTrend ? 1 : 0;
          Values[18][0] = AplusBuy ? 1 : 0;
          Values[19][0] = AplusSell ? 1 : 0;
          Values[20][0] = ABuy ? 1 : 0;
          Values[21][0] = ASell ? 1 : 0;
          Values[22][0] = BBuy ? 1 : 0;
          Values[23][0] = BSell ? 1 : 0;
          Values[24][0] = CplusBuy ? 1 : 0;
          Values[25][0] = CplusSell ? 1 : 0;
          Values[26][0] = CBuy ? 1 : 0;
          Values[27][0] = CSell ? 1 : 0;
          #endregion
          }
          }
          region Properties
          [Range(1, int.MaxValue), NinjaScriptProperty]
          [Display(Name = "MA1 Length", GroupName = "Parameters", Order = 0)]
          public int MA1Length { get; set; }

          [Range(1, int.MaxValue), NinjaScriptProperty]
          [Display(Name = "MA2 Length", GroupName = "Parameters", Order = 1)]
          public int MA2Length { get; set; }

          [Range(1, int.MaxValue), NinjaScriptProperty]
          [Display(Name = "MA3 Length", GroupName = "Parameters", Order = 2)]
          public int MA3Length { get; set; }

          [Range(1, int.MaxValue), NinjaScriptProperty]
          [Display(Name = "MA4 Length", GroupName = "Parameters", Order = 3)]
          public int MA4Length { get; set; }

          [Range(1, int.MaxValue), NinjaScriptProperty]
          [Display(Name = "MA5 Length", GroupName = "Parameters", Order = 4)]
          public int MA5Length { get; set; }

          [Range(1, int.MaxValue), NinjaScriptProperty]
          [Display(Name = "MA6 Length", GroupName = "Parameters", Order = 5)]
          public int MA6Length { get; set; }

          [Range(1, int.MaxValue), NinjaScriptProperty]
          [Display(Name = "LookBack Bars", GroupName = "Parameters", Order = 6)]
          public int LookBackBarsLength { get; set; }

          [Range(1, int.MaxValue), NinjaScriptProperty]
          [Display(Name = "Div Dist. From MA", GroupName = "Parameters", Order = 7)]
          public int DivDistFrmMA { get; set; }

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> MA1Plot => Values[0];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> MA2Plot => Values[1];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> MA3Plot => Values[2];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> MA4Plot => Values[3];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> MA5Plot => Values[4];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> MA6Plot => Values[5];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> PosDivPlot => Values[6];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> NegDivPlot => Values[7];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> ScalpCrossOverPlot => Values[8];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> ScalpCrossUnderPlot => Values[9];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> DayTradeCrossOverPlot => Values[10];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> DayTradeCrossUnderPlot => Values[11];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> SwingCrossOverPlot => Values[12];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> SwingCrossUnderPlot => Values[13];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> ScalpBuyTrendPlot => Values[14];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> ScalpSellTrendPlot => Values[15];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> DayBuyTrendPlot => Values[16];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> DaySellTrendPlot => Values[17];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> AplusBuyPlot => Values[18];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> AplusSellPlot => Values[19];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> ABuyPlot => Values[20];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> ASellPlot => Values[21];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> BBuyPlot => Values[22];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> BSellPlot => Values[23];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> CplusBuyPlot => Values[24];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> CplusSellPlot => Values[25];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> CBuyPlot => Values[26];

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> CSellPlot => Values[27];
          #endregion
          }
          }​​

          Comment


            #6
            Hello TheTechnician86,

            May I confirm you have removed the instance of the indicator from the Configured list and added a new instance to pull the new defaults set in State.SetDefaults?

            If so, may I have a reduced test script showing the plots with a Transparent brush are not transparent?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Chelsea

              I removed the instance of the indicator and I restarted NT to make sure I loaded a clean instantiation, but to no avail.

              As requested, attached is a simplified script with the same issue. I have reduced this down to the core of what I am trying to do. In short, I have declared variables and drew symbols on the chart when those variables occurred, passed those variables to a "Buy" or "Sell" Signal and drew "Buy" or "Sell" on the chart.

              The same issues persist. I get a line at the bottom of the chart and I am still not sure how to use the Buy or Sell Signals from this indicator in in strategy builder.

              Thanks for the consistent help!
              Attached Files

              Comment


                #8
                Hello TheTechnician86,

                This script does not appear to set the plots to transparent.

                On lines 53 to 58 I am seeing:

                AddPlot(Brushes.LimeGreen, "MA1");
                AddPlot(Brushes.Orange, "MA2");
                AddPlot(Brushes.Green, "Crossover");
                AddPlot(Brushes.Red, "Crossunder");
                AddPlot(Brushes.Green, "Buy");
                AddPlot(Brushes.Red, "Sell");​

                If you wanted the plots to be hidden this would instead be:

                AddPlot(Brushes.Transparent, "MA1");
                AddPlot(Brushes.Transparent, "MA2");
                AddPlot(Brushes.Transparent, "Crossover");
                AddPlot(Brushes.Transparent, "Crossunder");
                AddPlot(Brushes.Transparent, "Buy");
                AddPlot(Brushes.Transparent, "Sell");​
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Chelsea

                  I want to see all of the plots but when i load the indicator A red line is plotted on 1 and 0. I have changed 53 to 59 to the below and I still get the red lines.

                  AddPlot(Brushes.Green, "MA1");
                  AddPlot(Brushes.Red, "MA2");
                  AddPlot(Brushes.Green, "Crossover");
                  AddPlot(Brushes.Red, "Crossunder");
                  AddPlot(Brushes.Transparent, "Buy");
                  AddPlot(Brushes.Transparent, "Sell");​

                  I think its because I have these values set from 105 to 108

                  Values[2][0] = CrossOver ? 1 : 0;
                  Values[3][0] = CrossUnder ? 1 : 0;
                  Values[4][0] = Buy ? 1 : 0;
                  Values[5][0] = Sell ? 1 : 0;

                  Is there a different way to pass a 1 or a 0 or a True or a False to the strategy builder?​

                  Comment


                    #10
                    Hello TheTechnician86,

                    Are you referring to the Crossunder plot?

                    AddPlot(Brushes.Red, "Crossunder");

                    You want this not be visible correct?

                    Have you tried setting the brush to transparent?

                    "Is there a different way to pass a 1 or a 0 or a True or a False to the strategy builder?​"

                    Unfortunately, a plot is the only way to access indicator information in the strategy builder.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Chelsea

                      If i am understanding your last statement correctly, the only way for the strategy analyzer to recognize if a variable is true or false is to plot it. I want to plot

                      crossover
                      crossunder
                      buy
                      sell

                      My understanding is that we have to pass a 1 or a 0 to those variables so the strategy analyzer recognizes that variable as True or False. I did that by doing this

                      Values[2][0] = CrossOver ? 1 : 0;
                      Values[3][0] = CrossUnder ? 1 : 0;
                      Values[4][0] = Buy ? 1 : 0;
                      Values[5][0] = Sell ? 1 : 0;

                      But doing the above plots a line of a 1 or a 0 on the chart which i do not want. This is happening in the code I provided.


                      What is the recommended way see a variables normal plotting output but still pass a 1 or a 0 to strategy builder?

                      Comment


                        #12
                        Hello TheTechnician86,

                        I would recommend using a plot with a transparent brush to pass a 1 or 0 to the strategy builder.
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

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