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

Change Plot Color; Newbie Alert

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

    Change Plot Color; Newbie Alert

    Hey all, brand new here. So I have been searching and I feel close but can't quite get there. Overall idea:

    A sub-panel with each bar producing a dot of a constant value. I want to change the color of that dot based off of a different indicator. In this case, I want the dot to be green if the slope of the EMA is positive and red if the slope is negative, black if it is neutral (if ever).

    Right now I have two EMAs that I am trying to calculate and two dot plots.

    Any help or links to material or other threads in the right direction would be appreciated. Thanks in advance!

    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.LawnGreen), PlotStyle.Dot, "EMA9"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Dot, "EMA8"));
    Add(new Line(Color.FromKnownColor(KnownColor.White), 4, "Divider"));

    CalculateOnBarClose = true;
    Overlay = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    EMA9.Set(9);
    EMA8.Set(8);

    // define each EMA period
    double slope9 = (EMA(Ema9p)[0]- EMA(Ema9p)[1]);
    double slope8 = (EMA(Ema8p)[0]- EMA(Ema8p)[1]);


    // If the slope is rising turn plot green, if falling turn red, if neutral leave black
    if ( slope9 > 0 )
    Plots[0].Pen = new Pen(Color.LimeGreen);
    else if ( slope9 < 0 )
    Plots[0].Pen = new Pen(Color.Red);
    else
    Plots[0].Pen = new Pen(Color.Black);

    if ( slope8 > 0 )
    Plots[1].Pen = new Pen(Color.LimeGreen);
    else if ( slope8 < 0 )
    Plots[1].Pen = new Pen(Color.Red);
    else
    Plots[1].Pen = new Pen(Color.Black);

    }

    #2
    Hello Mabba,

    Thanks for the post, and welcome to the NinjaTrader forum.

    The first thing I notice is the use of EMA9.Set(9); and EMA8.Set(8), which does not compile. If you need to set up an EMA as a class object, define it at the class level, then set it up at the beginning bar in OnBarUpdate. What you likely wanted to do is set a value for a custom series. The "bare bones" way of setting values is to use the Values[][] array. This array holds all plot values to be plotted on the chart. For the attached example, I set the Values to the EMA values.

    Changing the plot pen will change all values of the plot. You will want to use the PlotColors[][] array.



    I have attached a modification of the code that you posted for your reference. Place the attached file within ..\Documents\NinjaTrader 7\bin\Custom\Indicator, compile, and then load it onto a chart if you wish to see the output.

    Please let us know if we may be of any further assistance.
    Attached Files
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick reply Chris, I will give it a go!

      Comment


        #4
        I think I got it, I just changed the last line in the 'testscript' that you sent back to:

        Values[0][0] = 9;
        Values[1][0] = 8;

        Thanks, I will keep tinkering!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by BarzTrading, Today, 07:25 AM
        2 responses
        13 views
        1 like
        Last Post BarzTrading  
        Started by devatechnologies, 04-14-2024, 02:58 PM
        3 responses
        19 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by tkaboris, Today, 08:01 AM
        0 responses
        3 views
        0 likes
        Last Post tkaboris  
        Started by EB Worx, 04-04-2023, 02:34 AM
        7 responses
        162 views
        0 likes
        Last Post VFI26
        by VFI26
         
        Started by Mizzouman1, Today, 07:35 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X