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

moving average that changes colors

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

    moving average that changes colors

    hello everyone,


    i have been trying to code an indicator that will change colors according to two different data sets but i have run into a lot of trouble with nt's regions, variables, data sets and other minutiae.

    i'd like to plot a 9 period sma. this 9 period sma would be plotted orange if a 10 period sma and an 18 period sma are both rising. it would be plotted purple if the 10 period and 18 period sma's are both falling and it would be plotted black in any other case.

    i have managed to create an sma that changes colors if it is rising or falling, but i haven't had success in plotting one sma according to how two other sma's are trending. maybe someone with more extensive experience coding in nt could help me.


    thanks.

    #2
    Hello,
    Thank you for your post.

    You can have the 8 period SMA change colors based off of the two other SMA's by doing something similar to the following:
    Code:
    if(CurrentBar < 1)
        return;
    	
    mySMA.Set(SMA(8)[0]);
    			
    if( Rising(SMA(18)) && Rising(SMA(10)) )
    {
    	PlotColors[0][0] = Color.Orange;	
    }
    else if( Falling(SMA(18)) && Falling(SMA(10)) )
    {
    	PlotColors[0][0] = Color.Purple;
    }
    else 
    {
    	PlotColors[0][0] = Color.Black;
    }
    If we can be of any other assistance please let us know.
    Cody B.NinjaTrader Customer Service

    Comment


      #3
      Cody,


      thanks for your super fast reply.


      i have tried to paste the code you suggested into a copy of the sma indicator but it won't compile.

      i get several error messages, and the one i haven't been able to get past reads something like this:

      operator && cannot be applied to operands of type boole and nt.indicator.sma

      i see that it will take some time and reading to at least get the basics for coding in nt. is there any kind of manual for beginners that would be recommendable?


      thanks.

      Comment


        #4
        Originally posted by rtwave View Post
        Cody,


        thanks for your super fast reply.


        i have tried to paste the code you suggested into a copy of the sma indicator but it won't compile.

        i get several error messages, and the one i haven't been able to get past reads something like this:

        operator && cannot be applied to operands of type boole and nt.indicator.sma

        i see that it will take some time and reading to at least get the basics for coding in nt. is there any kind of manual for beginners that would be recommendable?


        thanks.
        ref: http://ninjatrader.com/support/forum...37&postcount=1

        Comment


          #5
          Codys code was more meant to be its own indicator rather than a change to the original sma. His code already includes everything u need for it to work, ecxept adding the actual plot

          here would be his code implemented in a full script. just take ur copied sma file delete everything, paste this code and compile, should work like a charm.

          EDIT:you would find this indicator as "coloredSMA" not what ur filename would say. just to prevent confusion.

          Code:
          #region Using declarations
          using System;
          using System.ComponentModel;
          using System.Diagnostics;
          using System.Drawing;
          using System.Drawing.Drawing2D;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Data;
          using NinjaTrader.Gui.Chart;
          #endregion
          
          namespace NinjaTrader.Indicator
          {
          
              [Description("")]
              public class ColoredSMA : Indicator
              {
                  #region Variables
          
                  #endregion
          
          
                  protected override void Initialize()
                  {
                      Add(new Plot(Color.Orange, "ColoredSMA"));
                      Overlay                = true;
                  }
          
          
                  protected override void OnBarUpdate()
                  {
                      if(CurrentBar < 1)
                      return;
                      
                      Value.Set(SMA(9)[0]);
                      if( Rising(SMA(18)) && Rising(SMA(10)) )
                      {
                          PlotColors[0][0] = Color.Orange;    
                      }
                      else if( Falling(SMA(18)) && Falling(SMA(10)) )
                      {
                          PlotColors[0][0] = Color.Purple;
                      }
                      else 
                      {
                          PlotColors[0][0] = Color.Black;
                      }
                  }
          
                  #region Properties
                  [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                  [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                  public DataSeries Default
                  {
                      get { return Values[0]; }
                  }
                  #endregion
              }
          }
          Last edited by BigRo; 12-11-2015, 05:37 AM.

          Comment


            #6
            Hello rtwave,

            BigRo is correct here. koganam also refers to the Help Guide documentation that you can find at the following link: http://ninjatrader.com/support/helpG..._resources.htm

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by zstheorist, Today, 07:52 PM
            0 responses
            3 views
            0 likes
            Last Post zstheorist  
            Started by pmachiraju, 11-01-2023, 04:46 AM
            8 responses
            149 views
            0 likes
            Last Post rehmans
            by rehmans
             
            Started by mattbsea, Today, 05:44 PM
            0 responses
            5 views
            0 likes
            Last Post mattbsea  
            Started by RideMe, 04-07-2024, 04:54 PM
            6 responses
            33 views
            0 likes
            Last Post RideMe
            by RideMe
             
            Started by tkaboris, Today, 05:13 PM
            0 responses
            5 views
            0 likes
            Last Post tkaboris  
            Working...
            X