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

Dynamic plot coloring

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

    Dynamic plot coloring

    I am trying to color my plot lines dynamically based on their direction. I found some code in the Help file about this and tried it. However, when I try running the code, the entire indicator is colored based on the value of the indicators on the last bar on the chart.

    Here is my code:
    if (Trigger[0] < TriggerAvg[0])

    {

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

    Plots[
    1].Pen = new Pen(Color.Magenta);

    }

    elseif (Trigger[0] > TriggerAvg[0])

    {

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

    Plots[
    1].Pen = new Pen(Color.Lime);

    }



    #2
    imported post

    See this post -

    http://ninjatrader.mywowbb.com/forum14/1794.html

    Ray
    RayNinjaTrader Customer Service

    Comment


      #3
      imported post

      Thanks Ray ...but ... does this mean I need to have four (4) plots to plot a two line indicator set? 2 plots for the up color and 2 for the down color?

      That's what it looks like to me based on that code.

      Comment


        #4
        imported post

        If you want a 2 line indicator where both lines change color based on direction then yes, you need 4 plots, 2 up and 2 down.

        Ray
        RayNinjaTrader Customer Service

        Comment


          #5
          imported post

          OK ... think I understand now.

          If I wanted a two line indicator with three possible colors for each, I would then need 6 plots, correct?

          Comment


            #6
            imported post

            That is correct.

            Ray
            RayNinjaTrader Customer Service

            Comment


              #7
              imported post

              I am in need of help with some similar code. I have a moving average that I want to plot four colors on. Green for the major up move, darkgreen for a pullback against the major up move, Red for major down trend and darkred for pullback against major down trend. These major trends and pullbacks will be determined by my code.

              I found this code exampleon the forums that I thought something similarwould work with my calculations, but when I put this type of code in the indicator, I get no plot at all. This is not my code, but this is code I found on the forum and I can't get it to work. My code needs only oneMoving Average with 4 color changes on the one moving average.

              protected override void OnBarUpDate()

              {

              if(SMA(5)[0] > SMA(15)[0]

              Plots[0].Pen.Color = Color.Green

              else

              Plots[0].Pen.Color = Color.Red;

              }

              I am an experienced TradeStation EL Programmer and this is very easy to do in their language, but I am stumped with Ninja Script.



              Thanks, for any Help

              Comment


                #8
                imported post

                OUFan,

                Yes, this is one area that TS makesit much easier and perhaps in time it will be made more straightfoward in Ninja and reduce the number of plots required. If you want to usenative Ninja plot functionality (and not the plot override that uses C# graphics object) I think this is what you are looking for but I have not tested this specific code snippet:

                Code:
                // Determine Color forPlot1 Line 
                if (SMA(5)[0] > SMA(15)[0]) 
                {
                 Plot1_Line_XUp.Set(1, Plot_Value[1]); //Needed for Line Plots
                 Plot1_Line_XUp.Set(Plot_Value[0]); // Needed for All Plots
                } 
                else 
                {
                Plot1_Line_XDn.Set(1, Plot_Value[1]); //Needed for Line Plots
                 Plot1_Line_XDn.Set(Plot_Value[0]); // Needed for All Plots
                }
                As you can see there is a separate plot for crossing up vs down, and it is a matter of "Setting" the plot line (with appropriate color) you want to display. If you are using only non-continuous plotstyles (e.g., dots, bars) you can get by with only " Plot1_Line_XUp.Set(Plot_Value[0]);" for example but if you want to ensure there is not a gap between different color plots, you will need to use an additional plot set to draw the from the previous bar as indicated.

                Hope that helps

                Regards,

                Whitmark
                whitmark
                NinjaTrader Ecosystem Vendor - Whitmark Development

                Comment


                  #9
                  imported post

                  Whitmark,

                  Thank you very much for your help, but could I ask one other favor of you. I am just now learning Ninja Script and am not exactly sure how and where to put the color changes in the code you just showed. If I was going to use Green for up and Red for down, could you show me howto code that into the code you posted.

                  Thank You for Your Help,

                  OUFan






                  Comment


                    #10
                    imported post

                    OUFan,

                    You have to add plots in the Initialize() method. The easiest way to do that if you are not just getting familiar with C# is to use the New Indicator wizard.

                    Start a new indicator, and within the wizard, add your four plots. When you are complete with the wizard, it will generate the code for you in the Initialize() method.

                    Ray
                    RayNinjaTrader Customer Service

                    Comment


                      #11
                      imported post

                      Ray,

                      Could you give a little more code example for changing colors on a moving average. I did as you said and made2 plots, but it only plots the color of the last calculation on all the historical data. I wanted to plot the color green when the fast moving average was above the slow moving average and red when the fast moving average was below the fast moving average. The fast moving average was above the slow moving average on my data on the last bar, so it made the slow moving average that I was plotting be all green, even though I could see plenty of times the fast moving average was below the fast moving average which should have made the moving average red.

                      I am wanting to only plot the slow moving average, but make it change colors when it met my above criteria. I would appreciate your help.

                      OUFan

                      Comment


                        #12
                        imported post

                        See attached sample indicator.

                        Unzip the attached file in My Documents\NinjaTrader 6\bin\Custom\Indicator

                        This will contain an indicator named DualColorLine.

                        Ray
                        Attached Files
                        RayNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by ScottWalsh, Today, 04:29 PM
                        0 responses
                        4 views
                        0 likes
                        Last Post ScottWalsh  
                        Started by rtwave, 04-12-2024, 09:30 AM
                        2 responses
                        21 views
                        0 likes
                        Last Post rtwave
                        by rtwave
                         
                        Started by tsantospinto, 04-12-2024, 07:04 PM
                        5 responses
                        69 views
                        0 likes
                        Last Post tsantospinto  
                        Started by cre8able, Today, 03:20 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post cre8able  
                        Started by Fran888, 02-16-2024, 10:48 AM
                        3 responses
                        49 views
                        0 likes
                        Last Post Sam2515
                        by Sam2515
                         
                        Working...
                        X