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

Make line plot vary between dash and dot style

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

    Make line plot vary between dash and dot style

    Hello,

    I have been changing color of my line plot through the if - else approach, like this:

    if (Plot0[0] > Plot0[1])
    {
    PlotBrushes[0][0] = Brushes.GhostWhite;
    }
    else if (Plot0[0] < Plot0[1])
    {
    PlotBrushes[0][0] = Brushes.Red;
    }
    else
    {
    PlotBrushes[0][0] = Brushes.Gray;
    }

    Could you please tell me the equivalent line I should utilize within the brackets in order to make the line go from dash to dot?

    Thank you,


    #2
    Hello catinabag,

    Thanks for your post.

    With a plot, you cannot change the PlotStyle or DashStyle in the same manner as the PlotBrush.

    The PlotStyle or DashStyle would be applied to the entire plot.

    You may be able to accomplish your goal by using multiple plots, each set to the DashStyle of your choice. I've attached a screenshot of a quick example.

    Click image for larger version

Name:	DashStylePlotExample.PNG
Views:	769
Size:	131.9 KB
ID:	1108664
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      cool - thank you !

      Comment


        #4
        Originally posted by NinjaTrader_PaulH View Post
        You may be able to accomplish your goal by using multiple plots, each set to the DashStyle of your choice. I've attached a screenshot of a quick example.
        I am getting the errors here when compiling:

        "name Test1 does not exist in current environment" CS0103
        "name Test2 does not exist in current environment" CS0103

        Do I need to declare this variable in the beginning somewhere? I don't see anything else related to Test1 or Test2 in your screenshot. Maybe if you scroll up ?

        Comment


          #5
          Hello patricia70,

          Thanks for your reply.

          Test1 and Test2 are the names of the plots, so if you named your plots differently then you would need to references those names.

          Paul H.NinjaTrader Customer Service

          Comment


            #6
            I have named them exactly as you did in your example (Test1 and Test2). But that doesn't work because I get the mentioned error.

            I have found out by trial and error that I can use the two different plots by:

            Code:
            Values[0][0] = Low[0];
            Values[1][0] = High[0];

            Comment


              #7
              Hello patricia70,

              Thanks for your reply.

              I would suggest attaching your code file for review. You may be missing the output side of the plots.

              Yes, you can use Values, however, I prefer using Plot names as reading the code it becomes clear what you are using.


              Paul H.NinjaTrader Customer Service

              Comment


                #8
                I'd also like to use "your" way because of the reason you mentioned. I have substituted Test1 and Test2 accordingly. Here's my code:

                Code:
                [...]
                
                protected override void OnStateChange()
                {
                if (State == State.SetDefaults)
                {
                Description = @"foo";
                Name = "bar";
                Calculate = Calculate.OnBarClose;
                IsOverlay = true;
                DisplayInDataBox = true;
                DrawOnPricePanel = true;
                DrawHorizontalGridLines = true;
                DrawVerticalGridLines = true;
                PaintPriceMarkers = true;
                ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                IsSuspendedWhileInactive = true;
                AddPlot(new Stroke (Brushes.Red, DashStyleHelper.Dash, 2), PlotStyle.Line, "ts_upper");
                AddPlot(new Stroke (Brushes.Green, DashStyleHelper.Dash, 2), PlotStyle.Line, "ts_lower");
                }
                
                [...]
                
                    protected override void OnBarUpdate()
                    {
                       if (CurrentBar < 2) return;
                       {
                       if ( trendDir == 1 )
                       ts_lower[0] = Low[1];
                       if ( trendDir == -1 )
                       ts_upper[0] = High[1];
                    }
                [...]
                Last edited by patricia70; 11-04-2020, 03:53 PM.

                Comment


                  #9
                  Hello patricia70,
                  Be sure to add properties for these plots as below:-
                  Code:
                  [INDENT][I][Browsable(false)]
                  [XmlIgnore]
                  public Series<double> ts_lower
                  {
                  get { return Values[0]; }
                  }
                  
                  [Browsable(false)]
                  [XmlIgnore]
                  public Series<double> ts_upper
                  {
                  get { return Values[1]; }
                  }[/I][/INDENT]
                  If you don't add these properties then you have to use Values[0][0] / Values[1][0] for you code. Hope it helps!

                  Comment


                    #10
                    that's it! thank you.
                    I hate it copying, pasting or writing code that I don't understand. I would like to understand what each line is doing. Can you point me to the right direction for a good understanding tutorial about those properties?
                    Last edited by patricia70; 11-05-2020, 02:21 AM.

                    Comment


                      #11
                      Hello patricia70,
                      Please refer below details:-
                      [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog
                      [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template
                      public Series<double> test // this line defines plot as double series
                      { get { return Values[0]; } } // this line assigns value at current bar to series defined
                      This is standard syntax & if you use new indicator wizard its done automatically. Hope it helps!

                      Comment


                        #12
                        helps a bit, thank you. I need to dig further into it.
                        Last edited by patricia70; 11-05-2020, 03:25 AM.

                        Comment


                          #13
                          Hello patricia70,
                          Refer below link for further reading:

                          Comment


                            #14
                            thank you.

                            Comment


                              #15
                              Hello patricia70,

                              Thanks for your replies and glad forum member s.kinra was able to help.

                              Going forward, a simpler approach would be to use the Ninjascript indicator wizard when creating your strategy as, in the case of plots, it will create all of the structure you were missing automatically for you. The wizard can also create lines, custom data series, and various user inputs. So basically you specify the Inputs and outputs you wish, the wizard creates all the structure and then provides you with a script where you can then enter your code in the OnBarUpdate().

                              Please see the help guide here: https://ninjatrader.com/support/help...?ns_wizard.htm
                              Paul H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by bortz, 11-06-2023, 08:04 AM
                              47 responses
                              1,605 views
                              0 likes
                              Last Post aligator  
                              Started by jaybedreamin, Today, 05:56 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post jaybedreamin  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              6 responses
                              18 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by Jon17, Today, 04:33 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post Jon17
                              by Jon17
                               
                              Started by Javierw.ok, Today, 04:12 PM
                              0 responses
                              13 views
                              0 likes
                              Last Post Javierw.ok  
                              Working...
                              X