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

Dynamically change lines and plots but not the dashStyle??

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

    Dynamically change lines and plots but not the dashStyle??

    here is what i am trying to do.

    Initialize:
    (i have tried solid, dash, and dot, this is just my last at bat)

    pen = new Pen(Color.Black, 5);
    pen.DashStyle = DashStyle.Custom;
    Add(new Plot(pen, PlotStyle.Line, "Indicator"));
    --------------------------------------------------------------------
    switch (selector) {
    case 1:
    Plots[5].Pen.DashStyle = DashStyle.Solid;
    PlotColors[5][0] = Color.FromArgb(0,192,0);
    //Plots[5].Pen.DashStyle = DashStyle.Solid;
    break;
    case 0:
    Plots[5].Pen.DashStyle = DashStyle.Dot;
    PlotColors[5][0] = Color.Yellow;
    //Plots[5].Pen.DashStyle = DashStyle.Dot;
    break;
    case -1:
    Plots[5].Pen.DashStyle = DashStyle.Dash;
    PlotColors[5][0] = Color.FromArgb(192,0,0);
    //Plots[5].Pen.DashStyle = DashStyle.Dash;
    break;
    }



    the issue is that the first plot change is the only plot change,
    the colours change just fine but the plot only makes the very first
    change and then that is it. how do i get the plot ot change with the
    colour? i found the nt help on line and plots see below, but not
    dashstyle.

    neither above or below the plotcolors line of code effect the dashstyle

    any ideas or thoughts?







    no worries i already went thur the NT help

    =====Lines======================================== ==========================================

    // Dynamically change the upper line's color and thickness based on the indicator value

    protected override void OnBarUpdate()

    {

    if (Value[0] > 70)

    Lines[1].Pen = new Pen(Color.Blue, 3);

    else

    Lines[1].Pen = new Pen(Color.Gray, 1);

    }

    =====PLOTS======================================== ==========================================

    // Dynamically change the primary plot's color based on the indicator value

    protected override void OnBarUpdate()

    {

    if (Value[0] > 70)

    Plots[0].Pen = new Pen(Color.Blue);

    else

    Plots[0].Pen = new Pen(Color.Red);

    }

    #2
    i have found this online, i know that i do not need all of this to dynamically the plot
    but i do not know what it is that i do need. any help or suggestions?


    private void Form1_Paint(object sender, PaintEventArgs e)
    {
    DashStyle[] dash_style = {
    DashStyle.Dash,
    DashStyle.DashDot,
    DashStyle.DashDotDot,
    DashStyle.Dot,
    DashStyle.Solid
    };
    using (Pen the_pen = new Pen(Color.Red, 3))
    {
    int x1 = 10;
    int x2 = 100;
    int x3 = 300;
    int y = 10;

    // Show the standard styles.
    for (int i = 0; i < dash_style.Length; i++)
    {
    e.Graphics.DrawString(dash_style[i].ToString(), this.Font, Brushes.Red, x1, y);
    y += 5;

    the_pen.DashStyle = dash_style[i];
    e.Graphics.DrawLine(the_pen, x2, y, x3, y);
    y += 20;
    }

    // Show a custom style.
    float[] dash_pattern = {5F, 1F, 5F, 1F, 1F, 1F};
    the_pen.DashStyle = DashStyle.Custom;
    the_pen.DashPattern = dash_pattern;

    e.Graphics.DrawString("Custom", this.Font, Brushes.Red, x1, y);
    y += 5;
    e.Graphics.DrawLine(the_pen, x2, y, x3, y);
    y += 20;

    this.ClientSize = new Size(x3 + 10, y);
    }
    }

    Comment


      #3
      jupiejupe, your second post has unsupported code in it, so I can't comment on that content. As for your first post, does the plot style change if you hard code it in (not using cases)?
      AustinNinjaTrader Customer Service

      Comment


        #4
        the colour changes dynamically, while the dashstyle is only set once and then stays that way throughout.

        concerning the cases i am not sure about how to go about that, i am learning to code and this is what has been supplied to me, i am a hack (cut and paste) coder, so i have no idea how to revert to a non case code.
        Last edited by jupiejupe; 04-16-2011, 03:07 PM.

        Comment


          #5
          concerning the second set of code that you can not comment on, i am thinking this is what i need to add to the plot line? can you comment on this?

          // Show a custom style.
          float[] dash_pattern = {5F, 1F, 5F, 1F, 1F, 1F};
          pen.DashStyle = DashStyle.Custom;
          pen.DashPattern = dash_pattern;
          Last edited by jupiejupe; 04-16-2011, 03:34 PM.

          Comment


            #6
            from the second group of code i have got this not working but it's no longer giving errors.
            it paints the black but it does not change the DashStyle.

            DashStyle[] dash_style = {
            DashStyle.Dash,
            DashStyle.DashDot,
            DashStyle.DashDotDot,
            DashStyle.Dot,
            DashStyle.Solid
            };

            using (Pen the_pen = new Pen(Color.Black, 3))
            {
            // Show the standard styles.
            for (int i = 0; i < dash_style.Length; i++)
            {
            the_pen.DashStyle = dash_style[i];
            }
            // Show a custom style.
            float[] dash_pattern = {5F, 1F, 5F, 1F, 1F, 1F};
            the_pen.DashStyle = DashStyle.Custom;
            the_pen.DashPattern = dash_pattern;
            }

            Comment


              #7
              Originally posted by jupiejupe View Post
              the colour changes dynamically, while the dashstyle is only set once and then stays that way throughout.

              concerning the cases i am not sure about how to go about that, i am learning to code and this is what has been supplied to me, i am a hack (cut and paste) coder, so i have no idea how to revert to a non case code.
              That is because you are trying to use branching code in the Initialize() method. Always for me a dodgy proposition.

              Try moving your line and plot variation code to OnStartUp().

              Comment


                #8
                i hope it would not be rube of me to ask for an example, again i am just learning this stuff. funny thing is i wanted to be a trader not a programmer.

                the switch code in not in the initialize. this is the only code in the initialize.

                pen = new Pen(Color.Black, 5);
                pen.DashStyle = DashStyle.Custom;
                Add(new Plot(pen, PlotStyle.Line, "XXX"));

                all of this code is down with the indicator logic after the xxx.set

                switch (selector) {
                case 1:
                PlotColors[5][0] = Color.FromArgb(0,192,0);//OrderSignal.Long
                break;
                case 0:
                PlotColors[5][0] = Color.White;//OrderSignal.Check
                break;
                case -1:
                PlotColors[5][0] = Color.FromArgb(192,0,0);//OrderSignal.Short
                break;
                }

                i have tried a few ways to get the line plot to dynamically change

                //Plots[5].Pen.DashStyle = DashStyle.Dot[0];


                //Plots[5].Pen.DashStyle = DashStyle[0];
                //float[] dash_pattern = {5F, 0F};
                //pen.DashStyle = DashStyle.Custom;
                //pen.DashPattern = dash_pattern;


                DashStyle[] dash_style = {
                DashStyle.Dash,
                DashStyle.DashDot,
                DashStyle.DashDotDot,
                DashStyle.Dot,
                DashStyle.Solid
                };

                using (Pen the_pen = new Pen(Color.Black, 3))
                {
                // Show the standard styles.
                for (int i = 0; i < dash_style.Length; i++)
                {
                the_pen.DashStyle = dash_style[i];
                }
                // Show a custom style.
                float[] dash_pattern = {5F, 1F, 5F, 1F, 1F, 1F};
                the_pen.DashStyle = DashStyle.Custom;
                the_pen.DashPattern = dash_pattern;
                }
                Last edited by jupiejupe; 04-16-2011, 09:42 PM.

                Comment


                  #9
                  I am going to take you at your word that there is only one Plot created in your Initialize() method. In that case, why are you using a plot index of 5? (Just curious why you did it: I am not being sarcastic/snarky) If there is only one plot, your plot index should be "0". Everywhere you have Plots[5], you probably want to change to Plots[0]. The same for PlotColors.

                  There should probably be something in your log about the errors that should have been generated by reference to a non-existent Plot. Unfortunately, though I have also made the error before, I have never looked in the log, because when I saw the failure to handle the Plot, I usually found the error by looking again at the code, and noticing the wrong Plot index. That is why I say, "probably": I am not certain that it will be in the log; I just think that it probably is.

                  ... funny thing is i wanted to be a trader not a programmer.
                  Join the club of those who just want to trade but end up spending a whole lot of time programming their new ideas, so as to not have to do things manually!
                  Last edited by koganam; 04-17-2011, 11:13 PM.

                  Comment


                    #10
                    jupiejupe, are there any errors in the logs (right-most tab of Control Center) as koganam suggested?
                    AustinNinjaTrader Customer Service

                    Comment


                      #11
                      sorry about the late reply:

                      yes it is plot[5] this indicator has the option to plot different aspects of it's self, the one that i am solely using is plot[5] i do not care about the other aspects. so this is the reason. but my plot[5] has a total of six different values it can draw, so i wanted to be able to change the dashstyle as well as the colour to help myself notice between the (strong: 1, 0, -1) and also the (weak 1, 0, -1).

                      i only posted strong side to show what i was doing, because i am fairly sure that if i receive the correct structure to dynamically change the dashstyle then i can figure out how to apply it to all the plots.

                      Comment


                        #12
                        hold on now,
                        i am rereading the help guide and i found this on this selection: Advanced - Custom Plot Colors via Thresholds

                        "We now have a simple plot switching mechanism that displays the correct colored line depending on if the value of ROC is above or below zero. In fact, you can take this concept a little bit farther. You can even set different plots style (bar, dot etc..) depending on threshold values."

                        KEY PHRASE: "You can even set different plots style (bar, dot etc..) depending on threshold values."

                        this is what i am trying to do. there is no other reference about this. how to dynamically change the line other than this.

                        so i am asking how is this done, i have tried what seems logical, at least i should say logical to me,

                        Comment


                          #13
                          and on this forum post Josh says that plots can be changed
                          "Plots[0].Pen.DashStyle = DashStyle.Dash;"



                          this is what i tried but only the first change in to the plot is the only change?

                          any suggestions?

                          Comment


                            #14
                            Originally posted by jupiejupe View Post
                            and on this forum post Josh says that plots can be changed
                            "Plots[0].Pen.DashStyle = DashStyle.Dash;"



                            this is what i tried but only the first change in to the plot is the only change?

                            any suggestions?
                            Actually you change a Plot with PlotStyle.

                            Code:
                            Plots[5].PlotStyle = PlotStyle.Dot;

                            Comment


                              #15
                              okay i'll try this too - thanks
                              Last edited by jupiejupe; 04-19-2011, 10:16 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Harry, 05-02-2018, 01:54 PM
                              10 responses
                              3,203 views
                              0 likes
                              Last Post tharton3  
                              Started by cre8able, Yesterday, 01:16 PM
                              3 responses
                              11 views
                              0 likes
                              Last Post cre8able  
                              Started by ChartTourist, Today, 08:22 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post ChartTourist  
                              Started by LiamTwine, Today, 08:10 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post LiamTwine  
                              Started by Balage0922, Today, 07:38 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post Balage0922  
                              Working...
                              X