Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Changing Plot color within code

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

    Changing Plot color within code

    if (Values[2][1]>Values[2][0])
    {
    Print("RED "+Diff[1].ToString()+" "+Diff[0].ToString());
    Plots[2].Pen = new Pen(Color.Red,3);
    }
    else
    {
    Print("BLUE "+Diff[1].ToString()+" "+Diff[0].ToString());
    Plots[2].Pen = new Pen(Color.Blue,3);
    }

    -------------------------------------------------------------------------------------------------
    This always plots Red, even thou the Print confirms it enters the Blue Loop.

    I'm sure I'm missing something simple. I'm new at C#, and NinjaScript.

    #2
    imported post

    Create an indicator with one plotandadd the following code in the OnBarUpdate() method:

    Values[
    0].Set(Close[0]);
    if (Close[0] > SMA(5)[0])
    Plots[
    0].Pen = new Pen(Color.Red, 2);
    else
    Plots[0].Pen = new Pen(Color.Blue, 2);
    Run it on a 10 tick chart with "Calculate on bar close" set to false. This works fine here. Assuming it works as expected on your side. Work up from this sample to see where it may be breaking.

    Ray
    RayNinjaTrader Customer Service

    Comment


      #3
      imported post

      This toggles the entire line from Blue to Red.

      I was wanting to have a multi-colored line.

      Comment


        #4
        imported post

        That is correct, working as designed. For multi-colored line, you have to actually use two lines and set Min/Max threshholds. See Custom Indicator Development Tutotrial Level 5 in the Help Guide.

        There is a known bug in the current beta release with respect to this so even if you work through the tutorial example, it will not work as expected. This is resolved for next beta which is targeted for Monday release.

        Ray
        RayNinjaTrader Customer Service

        Comment


          #5
          imported post

          Tried to work with those multi colored lines to.

          if
          (pctK2[0]>50)

          Plot1.Set(pctK2[
          0]);

          else

          Plot2.Set(pctK2[
          0]);



          As soon the value reaches above 50 it set the plot1 else plot2. Both different colors. See picture.

          In tradestation I could set the previous line color like this:

          setplotcolor[1](1,green)

          Is this also possible in NT ?
          Attached Files

          Comment


            #6
            imported post

            Please see the Help Guide NinjaScript > Developing Custom Indicators > Tutorial: Custom Plot Colors via Thresholds



            Ray
            RayNinjaTrader Customer Service

            Comment


              #7
              imported post

              Can't see how to use these tresholdswith stochasticsbut this fills up the gapsin the (see earlier attached) chart (and in my mind)

              if (pctK2[0] > pctK2[1])
              {
              Plot1.Set(pctK2[0]);
              Plot2.Reset();
              }
              else
              {
              Plot2.Set(pctK2[0]);
              Plot1.Reset();
              }
              Plot3.Set(pctK2[0]);

              Comment


                #8
                imported post

                Ray I noticed you said there was a bug in a version using Min & Max thresholds. I am having trouble and was wondering what version has the bug and is a new version out that fixes the bug.

                Thanks,

                OUFan


                Comment


                  #9
                  imported post

                  If you are running the latest beta, Beta 7, this issue is for sure resolved.

                  Ray
                  RayNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Johnny90, Today, 04:19 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post Johnny90  
                  Started by jeanne, Today, 03:43 AM
                  0 responses
                  8 views
                  0 likes
                  Last Post jeanne
                  by jeanne
                   
                  Started by brucejay27, Today, 02:58 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post brucejay27  
                  Started by maxeintstine, Today, 02:46 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post maxeintstine  
                  Started by constituyente, Today, 02:37 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post constituyente  
                  Working...
                  X