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

OnRender with multiple DataSeries

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

    OnRender with multiple DataSeries

    Hello,

    I wrote an indicator that renders a rectangle when the High of the current candle is higher than the previous one. The indicator works, but when I add a second series of data, it paints them for a moment until the price updates, and then they all disappear. I suppose that the chart takes into account each candle from both data series and there is some conflict. What do I need to change so that in OnRender it only accesses the main data series and not the second one? Here I include the original code with the second data series commented out for it to work :

    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] < BarsRequiredToPlot /*|| CurrentBars[1] < BarsRequiredToPlot*/ )
    {return;}

    if (BarsInProgress == 0 )

    {

    HigherHigh[0] = false;

    if (High[0] > High[1])
    {HigherHigh[0] = true;}

    }
    }

    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)

    {

    for (int index = ChartBars.FromIndex; index <= ChartBars.ToIndex; index++)
    {


    float xStart = chartControl.GetXByBarIndex(ChartBars, index );

    float yStart = chartScale.GetYByValue(High.GetValueAt(index) + 5 * TickSize);

    float width = 6;

    SharpDX.RectangleF rect = new SharpDX.RectangleF(xStart-width/2, yStart, width, 10);


    // define the brush used in the rectangle
    SharpDX.Direct2D1.SolidColorBrush customDXBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Lime);
    SharpDX.Direct2D1.SolidColorBrush outlineBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Black);


    if (Bars.GetHigh(index)>Bars.GetHigh(index-1))
    if (HigherHigh.GetValueAt(index) == true)
    {

    RenderTarget.FillRectangle(rect, customDXBrush);
    RenderTarget.DrawRectangle(rect, outlineBrush, 1);

    }

    // always dispose of a brush when finished
    customDXBrush.Dispose();
    outlineBrush.Dispose();

    }


    // Default plotting in base class. Should be left Uncommented if indicators holds at least one plot you want displayed
    base.OnRender(chartControl, chartScale);

    }

    Thanks so much!​

    #2
    Hello Anton343,

    If you have multiple series, you should be specifying the series you want values from.

    if (BarsArray[0].GetHigh(index)>BarsArray[0].GetHigh(index-1))

    Use prints to understand the behavior. Are all the values in the condition as you expect?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I have changed that in the code, but it still doesn't work with two sets of data. I am attaching the indicator. Thank you.
      Attached Files

      Comment


        #4
        Hello Anton343,

        Save the print output from the NinjaScript Output window to a text file and include this with your next post.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Is this what you mean?
          Attached Files

          Comment


            #6
            Hello Anton343,

            May I confirm you have added prints to debug the code and understand the behavior as directed?

            With the error message, this is indicating an invalid index was used.
            Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:


            What index is the invalid index?

            Which line of code is the last evaluated before the error appears?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              hi,
              The indicator compiles perfectly, and the only error in the output is that one. I don't know what to change to fix it. It's clear that it's a problem with having two data series, but I can't seem to resolve it.

              Earlier, I attached the indicator so you can take a look if it's more convenient for you.

              Comment


                #8
                Hello Anton343,

                You will need to debug the script by adding prints as advised in post # 2.

                To find which line is causing an error, add a unique print above each line in OnRender(). Which print is the last to appear? The line of code below that is likely causing an error.


                Unfortunately, I cannot debug the script on your behalf. In the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one on one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates.

                You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  hi chelsea

                  I understand, I will try to debug the code to find the error. Thank you."

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by burtoninlondon, Today, 12:38 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post burtoninlondon  
                  Started by AaronKoRn, Yesterday, 09:49 PM
                  0 responses
                  11 views
                  0 likes
                  Last Post AaronKoRn  
                  Started by carnitron, Yesterday, 08:42 PM
                  0 responses
                  10 views
                  0 likes
                  Last Post carnitron  
                  Started by strategist007, Yesterday, 07:51 PM
                  0 responses
                  12 views
                  0 likes
                  Last Post strategist007  
                  Started by StockTrader88, 03-06-2021, 08:58 AM
                  44 responses
                  3,982 views
                  3 likes
                  Last Post jhudas88  
                  Working...
                  X