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

Multiple series indicator

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

    Multiple series indicator

    Hello.
    I create indicator, who draw different price lines on the chart. It take Close price from 1 minute timeframe. I would like to see the same lines on different timeframes (like 30, 60 minutes).
    For example, I can't see line with Time = 16:15 on 30- or 60- minutes chart.
    Need to work with AddDataSeries(BarsPeriodType.Minute, 1)?

    #2
    This is a part of the code:

    if (State == State.SetDefaults)
    {
    AddPlot(new Stroke(Brushes.Violet, DashStyleHelper.Solid, 2), plotStyleLines, "Close1615");
    }

    else if (State == State.Configure)
    {
    AddDataSeries(BarsPeriodType.Minute, 1);
    }


    ​protected override void OnBarUpdate()
    {​
    ​if (ToTime(Time[0]) == Convert.ToInt32(RTH_end_time_1615.ToString("HHmmss ")))
    {
    currentDayClose1615 = currentClose;
    }​
    Values[0][0] = priorDayClose1615;

    BUT I don't see the line. If I block the line AddDataSeries(BarsPeriodType.Minute, 1); and open 1 minute chart - I see the line.

    Comment


      #3
      Hello vitaly_p,

      When you add another series you are going to change how the logic is evaluated because both series call OnBarUpdate.

      If you meant for the logic to be executed on the primary series you need to surround that with a bars in progress check:

      if(BarsInProgress == 0)
      {
      // code here
      }


      You would otherwise have to use a Print here to see how the condition you made is working when running on the primary and 1 minute series to better understand why the value is not set.
      JesseNinjaTrader Customer Service

      Comment


        #4
        Hello Jesse

        Thank you for you answer.

        If I understand correctly if I have 30 min chart and put indicator on this chart all code inside (BarsInProgress == 0) will be for data from this 30 min chart and inside (BarsInProgress == 1) will be for new data Series 1 min.

        If I put all code into (BarsInProgress == 0) I see all lines like without new data series. but I don't see line with close price 16:15.
        If I change (BarsInProgress == 1) I see error "Error in calling 'OnBarUpdate' method on bar -1: You are accessing an index with an invalid value because it is out of range. I.E. refers to the [barsAgo] series with a value of 5, with only 4 bars on the chart."

        In documentation https://ninjatrader.com/support/help...l?momentum.htm I see that when added new Series after that - call (BarsInProgress == 1) for this series. Or not?​

        Comment


          #5
          Hello vitaly_p

          The error you are seeing means you are trying to access data before its available. You need to add a CurrentBars check when working with multi series:

          if(CurrentBars[0] < 1 || CurrentBars[1] < 1) return;

          //existing code after the condition

          You would replace the 1 with the amount of bars ago you needed to use for any series you use. 1 bar would be the minimum to ensure some data is present
          JesseNinjaTrader Customer Service

          Comment


            #6
            I added this check but I see she same error and don't see the plot lines with (BarsInProgress == 1)....

            Comment


              #7
              Hello vitaly_p,

              Where specifically did you add that code?

              JesseNinjaTrader Customer Service

              Comment


                #8
                protected override void OnBarUpdate()
                {
                if(BarsInProgress == 1)
                {

                if (!Bars.BarsType.IsIntraday)
                return;

                if(CurrentBars[0] < 1 || CurrentBars[1] < 1) return;​

                CODE
                }

                Comment


                  #9
                  Hello vitaly_p,

                  You need to add this before the bars in progress conditions:

                  protected override void OnBarUpdate()
                  {
                  if(CurrentBars[0] < 1 || CurrentBars[1] < 1) return;​


                  if(BarsInProgress == 1)
                  {

                  if (!Bars.BarsType.IsIntraday)
                  return;

                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    The same ... Could you look full code? Please. Maybe I have another error
                    Attached Files

                    Comment


                      #11
                      Hello vitaly_p,

                      What was the error message after adding that code? Did the bar index increase? If it still says -1 then there is some other problem happening or the code didn't get recompiled or reloaded. The current bar check is returning if either series is less than 1 bar so the error should also have a new bar index higher than -1.

                      To find what the specific problem is you can use comments, temporarily comment out all of the code inside BarsInProgress 0 to check if its the BarsInProgress 1 code. If so comment out the BarsInProgress 1 code and make sure the script can run without throwing the error. Then uncomment 1 line at a time and re test until you find the specific line causing the error.

                      I see that you are using Draw.Line with BarsAgo that you are using from variables. That may be part of the problem if the BarsAgo you are supplying is invalid based on the bars on the chart.
                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        Thank you Jesse.

                        I will try it

                        Comment


                          #13
                          Hello Jesse

                          Thank you for help!
                          It was a problem with BarsAgo series.
                          When I moved Draw from BarsInProgress 1 to BarsInProgress 0 - all work perfect!!
                          (All main logic into BarsInProgress 1 and all "Draw" into BarsInProgress 0)​

                          Comment


                            #14
                            Hello Jesse

                            I have a next question:

                            I would like to delete Rays on chart and draw Lines with some condition. I looping all Rays for it. BUT I have error with tmpRay: "cannot implicitly convert type NinjaTrader.NinjaScript.DrawingTools.DrawingTool toNinjaTrader.NinjaScript.DrawingTools.Ray ". Please, help me. how convert it?

                            Part of this code:

                            Ray tmpRay = null;

                            foreach (DrawingTool draw in DrawObjects.ToList())
                            {
                            if (draw is DrawingTools.Ray)
                            {
                            //Print(draw.Tag);

                            tmpRay = draw;

                            if(ToTime(Time[0]) >= Convert.ToInt32(ZoneRTH_start_time.ToString("HHmms s")) && ToTime(Time[0]) <= Convert.ToInt32(ZoneRTH_end_time.ToString("HHmmss" )))
                            {
                            if( CrossAbove( High , tmpRay.StartAnchor.Price, 1) || CrossBelow( Low , tmpRay.StartAnchor.Price, 1) )
                            {
                            Brush tmpBrush = tmpRay.Stroke.Brush; // COPY Color from Ray

                            RemoveDrawObject(tmpRay.Tag);

                            int nrayBarsAgo = CurrentBar - tmpRay.StartAnchor.DrawnOnBar;

                            Draw.Line(this, "Line"+(CurrentBar - nrayBarsAgo), false, nrayBarsAgo+1, tmpRay.StartAnchor.Price, 0, tmpRay.StartAnchor.Price, tmpBrush, DashStyleHelper.Dash, 2);

                            }
                            }
                            }
                            }​

                            Comment


                              #15
                              correct format : tmpRay = (Ray)draw;
                              Right?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              1 response
                              17 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by benmarkal, Yesterday, 12:52 PM
                              3 responses
                              23 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by helpwanted, Today, 03:06 AM
                              1 response
                              20 views
                              0 likes
                              Last Post sarafuenonly123  
                              Started by Brevo, Today, 01:45 AM
                              0 responses
                              11 views
                              0 likes
                              Last Post Brevo
                              by Brevo
                               
                              Started by pvincent, 06-23-2022, 12:53 PM
                              14 responses
                              244 views
                              0 likes
                              Last Post Nyman
                              by Nyman
                               
                              Working...
                              X