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 Aviram Y, Today, 05:29 AM
        0 responses
        5 views
        0 likes
        Last Post Aviram Y  
        Started by quantismo, 04-17-2024, 05:13 PM
        3 responses
        27 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by ScottWalsh, 04-16-2024, 04:29 PM
        7 responses
        36 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by cls71, Today, 04:45 AM
        0 responses
        6 views
        0 likes
        Last Post cls71
        by cls71
         
        Started by mjairg, 07-20-2023, 11:57 PM
        3 responses
        219 views
        1 like
        Last Post PaulMohn  
        Working...
        X