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

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 funk10101, Today, 12:02 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post funk10101  
                  Started by gravdigaz6, Yesterday, 11:40 PM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by MarianApalaghiei, Yesterday, 10:49 PM
                  3 responses
                  10 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by XXtrader, Yesterday, 11:30 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post XXtrader  
                  Started by love2code2trade, 04-17-2024, 01:45 PM
                  4 responses
                  28 views
                  0 likes
                  Last Post love2code2trade  
                  Working...
                  X