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

Draw Line using two Data Series

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

    Draw Line using two Data Series

    I am trying to get a line drawn starting at the last Close of the 15min Data Series (which below is my BarsArray [1]).

    DrawLine("Priceline", false, 1, Closes[1][1], 0, Closes[1][0], Color.Lime, DashStyle.Solid, 1);

    But instead of it ending at "0" = current bar of the 15min, I want it to end on the current bar x-axis of the 1min Data Series, which would be my BarsArray[2].

    I tried to replace the "0" above with Closes[2][0] but that doesn't work. Is there a way to accomplish what I want, and if so, can you please tell/show me how.

    sandman

    #2
    Hello sandman,

    Thanks for your post.

    Can you post a chart of what you are trying to do?

    Is your Draw statement run during BarsInProgress == 0?
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Paul.

      I'll try. See attached image. Top left shows a 15Min LineOnClose running obviously from 15 minutes to 15 minutes. Top right shows the same in a 1Min chart. LineOnClose obviously still runs from 15minutes to 15minutes using a 15min DataSeries.

      Bottom chart is my attempt to show what I want. Basically this 15min LineOnClose BUT not drawing to the next end of 15Min but only drawing till the current 1min Bar. As time elapses towards the end of the 15 minute interval, with each minute that passes, this line would become longer and longer. Hope this makes sense.

      sandman
      Attached Files

      Comment


        #4
        Hello sandman,

        Thanks for your reply.

        I'm still not sure I follow what you are trying to do. It appears that you only have two data series on the chart, a 1 minute and a 15 minute. in your script you would onlyneed to add the 15 minute series because when you apply to the chart the script will automatically use the charts data series and refer to it as BarsArray[0] and the 15 minute added data would then be BarsArray[1].

        With that in mind, you might try using the Time option in the Drawline() method, for example, using CalculateOnbarClose = true:

        if (BarsInProgress == 0) // draw on the 1 minute bar updxate.
        {
        DrawLine("Priceline", false, Times[1][0], Closes[1][0], Times[0][0], Closes[0][0], Color.Lime, DashStyle.Solid, 3);
        }


        If you are using CalculateOnBarClose = true Times[1][0] would be the last closed 15 minute bar time, Closes[1][0] woul be the price level, Times[0][0] is the last closed 1 minute bar and Closes[0][0] would be the time of the last minute bar.

        If you are using CalculateOnBarClose = false then I think what you want is this:

        if (BarsInProgress == 0)
        {
        DrawLine("Priceline", false, Times[1][1], Closes[1][1], Times[0][0], Closes[0][0], Color.Lime, DashStyle.Solid, 3);
        }


        Where Times[1][1] is the last closed 15 minute bar and closes[1]1[] is the close price of that bar, Times[0][0] and Ckloses[0][0] would be the current bar at the current price.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Paul.

          I had not known at all about the use of what you call the Time option = "Times". That opened the door and a first fast trial seems to show that it does what I intended it to do. Thanks for the samples you included with the potential use.

          Thank you very much. Have a good day!

          sandman

          Comment


            #6
            Paul.

            See attached image which shows a 5Min chart with the LinRegs from a 60Min DataSeries. Your mention of the time option allowed for that i.e.

            DrawLine("lrup", false, Times[1][1], (LinReg(BarsArray[1],4))[1], Times[1][0], (LinReg(BarsArray[1],4))[0], Color.MediumSlateBlue, DashStyle.Dash, 2);

            Now please allow me to expand on this subject. Is there a similar method to do this for DrawRegion - what I am trying to do is to color the region between the two 60Min LinRegs.

            I used:

            DrawRegion("LRRegion1", Times[1][1], Times[1][0], Plot1, Plot2, Color.Empty, upcolor, upopacity);
            but the result is distorted - see attached second image. Should it be easier for you to give any input, I am also including the .cs file, Test3Trapez.

            sandman
            Attached Files

            Comment


              #7
              Hello sandman,

              Thanks for your post.

              Could you clarify which distortion is the area of concern?
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Paul. What I'd like it to do is to fill exactly the region between the 2 LinRegs. I attach an image which hopefully communicates it. Just let me know if it doesn't.

                sandman
                Attached Files

                Comment


                  #9
                  Hello sandman,

                  Thanks for your reply.

                  Have you compared the coding of the LinReg indicator you created to what you have posted in Test3Trapez.CS? Can you also share that file?
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Paul. Hm, not certain what you mean but I somewhat assume you mean the separate indicator/file that draws the two LinReg lines. It's attached. It's called LinReg49AnycTF. (cTF is my abbreviation for choose Timeframe). This is the one I am very happy with using the Time Option which you had provided. Let me know if you meant something different.

                    sandman

                    (In case you are wondering. Sure, I can open a 5Min chart, add a 60Min or 240Min Data Series to it, and put the LinRegs of these higher time frames into that chart. The "problem" then is that if we are in the beginning of the 240 bar, the right side of that poor little 5 min chart is huge and blank except for the two 240 LinRegs. By using that LinReg49AnycTF the right side of the chart is not being "wasted").
                    Attached Files

                    Comment


                      #11
                      Hello sandman,

                      Thanks for your reply.

                      The indicator LinReg49AnycTF will draw from the last higher time frame bar to the forming higher time frame bar showing the current values. Once the last lower time frame bar in the higher time frame has completed, the lines are removed and new lines are drawn, thus the indicator only draws two lines and removes any historical lines. What indicator did you use on the screenshot that shows what you are wanting to do?
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        Paul. I used a regular LinReg indicator which I amended to be two colored for falling and rising. See attached.

                        What I want:

                        a. The two LR lines as drawn by the LinReg49AnycTF - that it only draws the lines for the current bar is totally fine.

                        b. The region between these two lines to be colored. Again, the past is of no concern. Just a colored region between the two LinRegs for that (higher timeframe) bar currently in progress. Sorry if the image I sent gave the wrong idea.

                        sandman
                        Attached Files

                        Comment


                          #13
                          Hello sandman,

                          Thanks for your reply.

                          Going back to the original script sample of Test3Trapez, there are 3 issues to discuss.

                          The jagged lines of the draw region on the 5-minute chart are created by the actual values of the LinRegs on the higher time frame. If you change the color on the LinReg plots you can see that the region does draw precisely between them. The 60-minute bar draws one data point every 12 5-minute bars and the LinReg will draw a straight line from one data point to the next on the 60-minute historical bars.

                          On the right edge, the draw region will attempt to draw the region the to "future" time of the higher time frames close time (the 60-minute bar close time is known and remains constant from the first second the bar opens until the last. For reasons I do not understand, even though you are supplying the plot data series to DrawRegion(), the drawregion is trying to draw to the price level of 0 (zero) at the future close time of the 60-minute bar.

                          The DrawRegions tag name you were using was causing the draw regions to be created and then overlaid on top of each other thus creating a darker region than you really wanted. (This is a very common issue when coding regions and causes poor performance). the best way to handle this is to only draw the regions when there is a change, in this case, you could use the crossover of the LinRegs and then tie the tag name to the bar (or time) of the crossover, however, this requires additional logic.

                          Please review and test the attached modified Test3Trapez. With reference to the screenshot, it will draw the last region according to the logic included based on crossover. To prevent it from drawing down to zero, I had the indicator draw from the last 60-minute bar to the current 5-minute bar.
                          Attached Files
                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14
                            Paul.
                            Thank you very much. It's almost midnight where I am, so I will have to try it out tomorrow. But the image looks promising. I'll let you know tomorrow once I have checked it out further.

                            sandman

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by warreng86, 11-10-2020, 02:04 PM
                            5 responses
                            1,356 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by Perr0Grande, Today, 08:16 PM
                            0 responses
                            3 views
                            0 likes
                            Last Post Perr0Grande  
                            Started by elderan, Today, 08:03 PM
                            0 responses
                            5 views
                            0 likes
                            Last Post elderan
                            by elderan
                             
                            Started by algospoke, Today, 06:40 PM
                            0 responses
                            10 views
                            0 likes
                            Last Post algospoke  
                            Started by maybeimnotrader, Today, 05:46 PM
                            0 responses
                            12 views
                            0 likes
                            Last Post maybeimnotrader  
                            Working...
                            X