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

Not able to Plot() some lines

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

    Not able to Plot() some lines

    I need some help with the code/syntax. Cannot get it to plot any of the lines.
    Thanks in advance...

    protected override void Initialize()
    {
    Overlay = true;
    Add(new Plot(new Pen(Color.Green, 2), PlotStyle.Square, "high2DA"));
    Add(new Plot(new Pen(Color.Red, 2), PlotStyle.Square, "low2DA"));
    Add(new Plot(new Pen(Color.Blue, 2), PlotStyle.Square, "highMON"));
    Add(new Plot(new Pen(Color.Violet, 2), PlotStyle.Square, "lowMON"));
    Plots[0].Pen.DashStyle = DashStyle.Dash;
    Plots[1].Pen.DashStyle = DashStyle.Dash;
    Plots[2].Pen.DashStyle = DashStyle.Dash;
    Plots[3].Pen.DashStyle = DashStyle.Dash;
    }

    protected override void OnBarUpdate()
    {
    if(Bars.FirstBarOfSession) {
    sessionCount++;
    }
    if (sessionCount < 2)
    return;
    if(Time[0].DayOfWeek == DayOfWeek.Monday) {
    bar = CurrentBar;
    }
    double highSOD = CurrentDayOHL().CurrentHigh[0];
    double lowSOD = CurrentDayOHL().CurrentLow[0];

    high2DA = PriorDayOHLC().PriorHigh[Bars.BarsSinceSession + 1];
    low2DA = PriorDayOHLC().PriorLow[Bars.BarsSinceSession + 1];

    if (bar !=0 ) {
    highMON = PriorDayOHLC().PriorHigh[CurrentBar - bar];
    lowMON = PriorDayOHLC().PriorLow[CurrentBar - bar];
    }

    #2
    2Look4me, I would not expect to see any values plotted for your snippet as you never .Set any value to your series here.

    Did you mean to use something like -

    Code:
    high2DA.Set(PriorDayOHLC().PriorHigh[Bars.BarsSinceSession + 1]);
    low2DA.Set(PriorDayOHLC().PriorLow[Bars.BarsSinceSession + 1]);
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I have defined:

      #region Variables
      private double highSOD, lowSOD, high2DA, low2DA, highMON, lowMON;
      #endregion

      and I am getting the compiling error: 'double' does not contain a definition for 'Set' and no extension method 'Set' ...

      Comment


        #4
        Right, you have defined double variables here - for plotting usage you want a plot value of double dataseries values.

        How the plots should be visualized you have already defined in the Initialize() method via the Add() statement, now you should just need to define the actual series holding the values in your properties section -

        Code:
        [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 high2DA
                {
                    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 low2DA
                {
                    get { return Values[1]; }
                }
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Thanks Bertrand, now I understand. Your explanations are so simple and thorough compared to the help manual!

          In seeing the lines plotted (please see screenshot for Monday 1/12/15 & 1/19/15); how can it be coded so that the Monday High and Low are also calculated on Monday, therefore plotted the rest of the week as well? Presently it doesn't calculate that on Mondays.
          Attached Files

          Comment


            #6
            Hello 2Look4me,

            Thank you for your response.

            You could use DayOfWeek to check that it is Monday, for example:
            Code:
            			if(Time[0].DayOfWeek == DayOfWeek.Monday)
            			{
            				// Set your values
            			}

            Comment


              #7
              Your suggestion to use DayOfWeek to check that is Monday is precisely what I have in the code. Just that when it's Monday, the respective High/Low are not calculated, but some other random HL as see in the screenshot and this is were I have a hard time figuring it out

              protected override void OnBarUpdate()
              {
              // Calculate The Bar Number for Monday
              if(Bars.FirstBarOfSession) {
              sessionCount++;
              }
              if (sessionCount < 2)
              return;
              if(Time[0].DayOfWeek == DayOfWeek.Monday){
              bar = CurrentBar;
              }
              // High and Low for Monday
              if (bar !=0 ) {
              highMON.Set(PriorDayOHLC().PriorHigh[CurrentBar - bar]);
              lowMON.Set(PriorDayOHLC().PriorLow[CurrentBar - bar]);
              }
              }

              Comment


                #8
                PriorDayOHLC() refers to PriorDay, which can never be Monday on a Monday. Try using MAX() and MIN().

                Comment


                  #9
                  Hello 2Look4me,

                  CurrentDayOHL() can pull that session's Open, High, or Low as long as you reference the barsAgo value that falls in the session.

                  Comment


                    #10
                    Thanks for the suggestions, I'll go back to the drawing board.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by sightcareclickhere, Today, 01:55 PM
                    0 responses
                    1 view
                    0 likes
                    Last Post sightcareclickhere  
                    Started by Mindset, 05-06-2023, 09:03 PM
                    9 responses
                    258 views
                    0 likes
                    Last Post ender_wiggum  
                    Started by Mizzouman1, Today, 07:35 AM
                    4 responses
                    18 views
                    0 likes
                    Last Post Mizzouman1  
                    Started by philmg, Today, 01:17 PM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_ChristopherJ  
                    Started by cre8able, Today, 01:01 PM
                    1 response
                    9 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Working...
                    X