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

Difference Plot vs Value

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

    Difference Plot vs Value

    From an Indicator

    }
    PlotVWAPH1[0] = (iCumTypicalVolumeH1 / iCumVolumeH1);
    PlotVWAPL1[0] = (iCumTypicalVolumeL1 / iCumVolumeL1);
    }



    region Properties

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> PlotVWAPH1
    {
    get { return Values[0]; }
    }


    [Browsable(false)]
    [XmlIgnore]
    public Series<double> PlotVWAPL1
    {
    get { return Values[1]; }
    }


    ***************************

    When Indicator applied to chart the plots are as expected

    *******************************

    Indicator applied to Strategy using secondary dataseries Closes[1] which is a 1 minute bar

    Added Prints to Strategy


    Print("PlotH1 Strat: " + ATSVWAPScalper1.PlotVWAPH1[0]);/// Prints the Plot as shown on my chart as expected
    Print("PlotL1 Strat: " + ATSVWAPScalper1.PlotVWAPL1[0]);/// same

    Print("PlotH1 ValueH1: " + ATSVWAPScalper1.Plots[0]);
    Print("PlotL1 ValueL1: " + ATSVWAPScalper1.Plots[1]);


    Print Output

    PlotH1 Strat: 13469.4166666667
    PlotL1 Strat: 13467.5125521304
    PlotH1 ValueH1: NinjaTrader.Gui.Plot
    PlotL1 ValueL1: NinjaTrader.Gui.Plot​

    If i AddChartIndicator to the Chart to Plot on Chart if will n ot allow me to use PlotVWAPH![0] must use Plots[0] as shown

    ATSVWAPScalper1.Plots[0].Brush = Brushes.Orange;
    ATSVWAPScalper1.Plots[1].Brush = Brushes.Orange;
    AddChartIndicator(ATSVWAPScalper1);

    ************

    WHAT AM I MISSING HERE Values[0] is PlotVWAPH1 and plots on the chart as expected

    BUT THE Plots[0] plots on Chart entirely different value than the Print of PlotH1 Strat

    Why?

    AND IF I am using in Strategy condition sets referencing ATSVWAPScalper1.PlotVWAPH1[0]

    Is the Strategy getting the Print of

    Print("PlotH1 Strat: " + ATSVWAPScalper1.PlotVWAPH1[0]);/// Prints the Plot as shown on my chart as expected PlotH1 Strat: 13469.4166666667

    or the incorrect Plot of the Value plotted on chart ATSVWAPScalper1.Plots[0].Brush = Brushes.Orange;

    or a none value of the Print PlotH1 ValueH1: NinjaTrader.Gui.Plot

    Thanks​


    #2
    Hello DTSSTS,

    The Plots collection holds information about how the plot will be displayed.


    The Values collection holds the actual double values that is the data of the plot.


    Where you have mentioned:
    "If i AddChartIndicator to the Chart to Plot on Chart if will n ot allow me to use PlotVWAPH![0] must use Plots[0] as shown"

    How are you trying to use this?
    Are you trying to get the double values? If so, yes you can get values from a public series in an indicator.
    Are you trying to get the display information? If so, that would come from the Plots collection.

    When using AddDataSeries() this will add the actual instance of the indicator to the chart, so the values will be the same as in the host strategy.
    AddDataSeries() cannot add an indicator that is using secondary series as the input series.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I really did not follow much of your post. I really only trying to make sure I am rerference correct info for my strategy and visually I saw the difference on the Chart from the Print


      Print("PlotH1 Strat: " + ATSVWAPScalper1.PlotVWAPH1[0]);/// Prints the Plot as shown on my chart as expected​
      PlotH1 Strat: 13469.4166666667

      the above is correct as expected, so if my conditions in strat condition sets referencing ATSVWAPScalper1.PlotVWAPH1[0]

      then I assume the print result is what I am referencing --- IS THAT CORRECT?

      **********************

      REGARDING the difference in the Plot on Chart and the Print PlotH1 Strat: 13469.4166666667 being different ONE should that effect the use of ATSVWAPScalper1.PlotVWAPH1[0] ?

      TWO I think i realize what I have wrong in the indicator (I was trying to create a slim down version of another indicator that had multi plots to just the one I need) and I failed to include a line or two of code, which I am having an issue figuring out

      I need the Time of the highestBar of the last 120 Periods

      I was trying something like this DateTime highestBarTime = Time[0](HighestBar(High, 120);

      if (HighestBar(High, 120) == 0)


      int highestBarIndex = HighestBar(High, 120); <<<<< will not compile
      DateTime highestBarTime = Time[highestBarIndex];


      {
      startLogicH1 = true;
      }

      if ((startLogicH1 == true)
      && (Time[0] == highestBarTime))


      Thanks​​

      Comment


        #4
        Hello DTSSTS,

        the above is correct as expected, so if my conditions in strat condition sets referencing ATSVWAPScalper1.PlotVWAPH1[0]
        then I assume the print result is what I am referencing --- IS THAT CORRECT?
        ATSVWAPScalper1.PlotVWAPH1[0] would be the public Series<double> object returning Values[0] in the indicator code you have suggested in post # 1, and would be referenced correctly.

        REGARDING the difference in the Plot on Chart and the Print PlotH1 Strat: 13469.4166666667 being different ONE should that effect the use of ATSVWAPScalper1.PlotVWAPH1[0] ?
        I'm not understanding. You have another public Series<double> with the name PlotH1? I would not expect these to be the same unless you are setting the values of this to other plot.. What is this variable?​

        I need the Time of the highestBar of the last 120 Periods
        To get the highest bar in the last 120 bars using the HighestBar() method is correct.
        https://ninjatrader.com/support/help...highestbar.htm

        int highestBarIndex = HighestBar(High, 120); <<<<< will not compile
        This is compiling on my end. Are you sure this is the code that will not compile? There are no changes? Can I see a screenshot of the compile errors?

        Below is a link to a video showing this specific line of code compiles without any error.
        https://drive.google.com/file/d/1PNy...w?usp=drivesdk

        Are you certain the compile error line number is not referring to a different line of code?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Regading Values

          I do need this in my code CORRECT?

          region Properties

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> PlotVWAPH1
          {
          get { return Values[0]; }
          }


          [Browsable(false)]
          [XmlIgnore]
          public Series<double> PlotVWAPL1
          {
          get { return Values[1]; }
          }

          Comment


            #6
            int highestBarIndex = HighestBar(High, 120); <<< ---- error code CS1023

            Error: Embedded statement cannot be a declaration or labeled statement CS1023 Line 92 column 4



            thanks

            Comment


              #7
              Hello DTSSTS,

              It looks like the syntax of the script is not correct.

              Where is this being declared? Why is the next line of code an opening curly brace?
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8

                protected override void OnBarUpdate()
                {

                if (BarsInProgress == 0)


                if (CurrentBars[0] < 125)
                return;

                {

                if (HighestBar(High, 120) == 0)


                int highestBarIndex = HighestBar(High, 120);
                DateTime highestBarTime = Times[highestBarIndex];

                {
                startLogicH1 = true;
                }

                if ((startLogicH1 == true)
                && (Time[0] == highestBarTime))

                {
                iCumVolumeH1 = VOL()[0];
                iCumTypicalVolumeH1 = VOL()[0] * ((High[0] + Low[0] + Close[0]) / 3);
                }
                else
                {
                iCumVolumeH1 = iCumVolumeH1 + VOL()[0];
                iCumTypicalVolumeH1 = iCumTypicalVolumeH1 + (VOL()[0] * ((High[0] + Low[0] + Close[0]) / 3));
                }

                Comment


                  #9
                  Hello DTSSTS,

                  This syntax you have provided is incorrect.

                  if (BarsInProgress == 0) <-- if statement is not followed by an action block, so next if statement will be nested

                  if (CurrentBars[0] < 125) <-- nested if statement is not followed by an action block, so next statement to return is one line action block
                  return;

                  { <-- completely unexpected open curly brace that is not associated with anything at all

                  if (HighestBar(High, 120) == 0) <-- if statement is not followed by an action block so next line will be one line action block

                  int highestBarIndex = HighestBar(High, 120); <-- variable being declared in a one line action action block is not valid. you cannot use this variable later so C# does allow you to declare the variable here and causes a compile error.

                  { <-- other completely unexpected open curly brace that is not associated with anything.


                  In C# you can only use a variable within the scope in which it is declared. If you declare a variable in an action block, it can only be used in that action block.
                  Further, you cannot put code between an if statement and it's action block if that is what you are trying to do.

                  Try the following instead:
                  Code:
                  private int highestBarIndex;
                  private DateTime highestBarTime;
                  
                  protected override void OnBarUpdate()
                  {
                      if (BarsInProgress == 0 || CurrentBars[0] < 125)
                          return;
                  
                      highestBarIndex  = HighestBar(High, 120);
                      highestBarTime   = Times[0][highestBarIndex];
                  
                      if (​highestBarIndex == 0)
                      {
                          startLogicH1 = true;
                      }
                  }

                  Below is a link to a forum post with helpful resources on getting started with C#.
                  https://ninjatrader.com/support/foru...pts#post786040

                  C# programming education comes prerequisite to writing NinjaScript code. We highly recommend getting further acquainted with C# through a formal class, or through educational resources that can be found external to NinjaTrader.​
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    action block first time I ever had that discussed in 5 years

                    Also similar code I sent I am using in 2 other indicators without issue

                    I will work with your suggestions to see if i can get to compile, YOUR suggestion got me past these lines but have create many more syntax errors further down in script now

                    Thanks

                    Comment


                      #11
                      Clean up lower syntax

                      highestBarTime = Times[highestBarIndex];

                      has error reference to this line

                      Cannot implicity convert type 'NinjaTrader.NinjaScript.TimeSeries' to 'System.Datetime' CS0029 column 26

                      Thanks

                      Comment


                        #12
                        Hello DTSSTS,

                        Apologies I copied and pasted that invalid code from your code suggestion in post # 8.

                        Times[barsArray Index][barsAgo index] requires two indexes.

                        This should be

                        highestBarTime = Times[0][highestBarIndex];
                        or
                        highestBarTime = Time[highestBarIndex];
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          thanks
                          I had already changed Times to Time ie
                          highestBarTime = Time[highestBarIndex];

                          and compiled, but now I have no plots at all

                          NOT following the "requires two indexes"

                          as we do not have any barsAgo ?


                          Comment


                            #14
                            this is what i have

                            private int highestBarIndex;
                            private DateTime highestBarTime;​

                            private int lowestBarIndex;
                            private DateTime lowestBarTime;​

                            ****************************


                            protected override void OnBarUpdate()
                            {
                            if (BarsInProgress == 0 || CurrentBars[0] < 125)
                            return;

                            highestBarIndex = HighestBar(High, 120);
                            // highestBarTime = Times[0][highestBarIndex];// tried both
                            highestBarTime = Time[highestBarIndex];

                            lowestBarIndex = LowestBar(Low, 120);
                            // lowestBarTime = Times[0][lowestBarIndex];// tried both
                            lowestBarTime = Time[lowestBarIndex];


                            if (​highestBarIndex == 0)
                            {
                            startLogicH1 = true;
                            }
                            // } // blocked the to compile with below items tried with and without

                            if ((startLogicH1 == true)
                            && (Time[0] == highestBarTime))

                            {
                            iCumVolumeH1 = VOL()[0];
                            iCumTypicalVolumeH1 = VOL()[0] * ((High[0] + Low[0] + Close[0]) / 3);
                            }
                            else
                            {
                            iCumVolumeH1 = iCumVolumeH1 + VOL()[0];
                            iCumTypicalVolumeH1 = iCumTypicalVolumeH1 + (VOL()[0] * ((High[0] + Low[0] + Close[0]) / 3));
                            }



                            if (lowestBarIndex == 0)
                            {
                            startLogicL1 = true;
                            }
                            // }


                            if ((startLogicL1 == true)
                            && (Time[0] == lowestBarTime))

                            {
                            iCumVolumeL1 = VOL()[0];
                            iCumTypicalVolumeL1 = VOL()[0] * ((High[0] + Low[0] + Close[0]) / 3);
                            }
                            else
                            {
                            iCumVolumeL1 = iCumVolumeL1 + VOL()[0];
                            iCumTypicalVolumeL1 = iCumTypicalVolumeL1 + (VOL()[0] * ((High[0] + Low[0] + Close[0]) / 3));
                            }


                            PlotVWAPH1[0] = (iCumTypicalVolumeH1 / iCumVolumeH1);
                            PlotVWAPL1[0] = (iCumTypicalVolumeL1 / iCumVolumeL1);


                            }


                            I HAVE NO PLOTS IN PRINTS


                            Comment


                              #15
                              Hello DTSSTS,

                              Use Print() to understand behavior.

                              Print the value you are setting to the plot one line above the assignment along with the time of the bar.

                              Do you see your print? If not, that code is not being reached.

                              Are there errors on the Log tab of the Control Center?

                              If so, the script was disabled due to the error.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by DJ888, Today, 10:57 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by MacDad, 02-25-2024, 11:48 PM
                              7 responses
                              158 views
                              0 likes
                              Last Post loganjarosz123  
                              Started by Belfortbucks, Today, 09:29 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post Belfortbucks  
                              Started by zstheorist, Today, 07:52 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post zstheorist  
                              Started by pmachiraju, 11-01-2023, 04:46 AM
                              8 responses
                              151 views
                              0 likes
                              Last Post rehmans
                              by rehmans
                               
                              Working...
                              X