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

Question about accessing the PlotBrushes series of an indicator from a strategy

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

    Question about accessing the PlotBrushes series of an indicator from a strategy

    I am trying to read the plot color of the last bar from a strategy but the color returned is always empty.

    Can you help ?

    Here is what i am doing:

    I have this class wide variable defined which holds a collection of indicators on the chart:
    private List<NinjaTrader.Gui.NinjaScript.IndicatorRenderBa se> indicatorCollection;


    In a method i have this code
    ============================

    // define the variable which will hold a ref. to an underlying indicator on the chart
    NinjaTrader.Gui.NinjaScript.IndicatorRenderBase _indicator;

    // get an indicator from the collection
    _indicator = indicatorCollection[i];

    // loop through all the plots created by this indicator
    int _plotsCount = _indicator.Values.Length;
    for (int _plotIndex = 0; _plotIndex < _plotsCount ; _plotIndex++)
    {
    int _lastBarPainted = ChartBars.ToIndex - (_indicator.Calculate == Calculate.OnBarClose ? 1:0);
    Plot _plot = _indicator.Plots[_plotIndex];
    BrushSeries _plotBrushes = _indicator.PlotBrushes[_plotIndex];
    Brush _plotColor = _plotBrushes[_lastBarPainted];
    }

    Print(_plot.Name + " " + _plotColor); // <- i always get an empty content for the _plotColor variable


    There is no script error and the indicator name is displayed in the output window but the _plotColor is empty and i can't understand what's wrong in my code.​

    #2
    Hi, thanks for posting. The ChartControl object has a collection of indicators that you can use to get the PlotColor:
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post
      Hi, thanks for posting. The ChartControl object has a collection of indicators that you can use to get the PlotColor:
      https://ninjatrader.com/support/help...indicators.htm
      My script is already using this ChartControl object to get the collection of indicators on a chart. However, if i try these commands:
      BrushSeries _plotBrushes = _indicator.PlotBrushes[_plotIndex];
      Brush _plotColor = _plotBrushes[_lastBarPainted];

      _plotColor is empty. Do you have any idea why?

      Comment


        #4
        I finally was able by forgetting about the PlotBrushes[] BrushSeries.

        I used this instead:
        Plot _plot = _indicator.Plots[_plotIndex];
        Brush _plotColor = _plot.Brush;

        Don't know why the other approach did not work though.

        Comment


          #5
          Hi, Im also noticing the PlotBrushes[0] is an empty array in this context. I will check to see if this is expected or not.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Hi, It looks like this output is expected. The same thing will happen if you host an indicator in a parent script, the parent script will not have access to the PlotBrushes[][] array of the hosted indicator. I will submit a feature request to ask our development team to make PlotBrushes available to other scripts that access an indicator's PlotBrushes array.
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by lightsun47, Today, 03:51 PM
            0 responses
            5 views
            0 likes
            Last Post lightsun47  
            Started by 00nevest, Today, 02:27 PM
            1 response
            12 views
            0 likes
            Last Post 00nevest  
            Started by futtrader, 04-21-2024, 01:50 AM
            4 responses
            46 views
            0 likes
            Last Post futtrader  
            Started by Option Whisperer, Today, 09:55 AM
            1 response
            14 views
            0 likes
            Last Post bltdavid  
            Started by port119, Today, 02:43 PM
            0 responses
            10 views
            0 likes
            Last Post port119
            by port119
             
            Working...
            X