• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Rendered Line to set Global and vice versa

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

    Rendered Line to set Global and vice versa

    Hi,
    I am rendering a line which I am using as trend line and I am drawing it manually. But when I run this indicator on several time frame of same instrument and draw line in one, it does draw on all other timeframe charts. I wanted to stop it. What should I do to stop it please?

    thanks.

    #2
    Hello asmmbillah,

    I noticed in the subject you mentioned global, a global object should appear on other time frames of the same instrument. Are you asking how to draw a non global object?


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      I am rendering a line with start and end anchor points. How to make it non global. It’s not drawn by regular draw.line(). I am rather using
      RenderTarget.DrawLine(Vector2 point0, Vector2 point1, Brush brush, float strokeWidth, StrokeStyle strokeStyle), but I don't see the typical bool IsGlobal. Any advice how to restrict it just to the chart and time frame the indicator is added?

      Thanks in advance.
      Last edited by asmmbillah; 09-21-2019, 09:23 AM.

      Comment


        #4
        Hello asmmbillah,

        SharpDX render would not be global and would only be seen in the chart that has the indicator added. If you are adding this indicator to multiple time frames and see this line, this would mean that your OnRender logic is allowing the line to be drawn in each instance of that indicator.

        If you do not want the indicator to draw a line on specific time frames, you could check BarsPeriod to ensure that the indicator is applied to a certain time frame and if the indicator should draw that line based on that criteria.

        I.E.

        if (BarsArray[0].BarsPeriod.BarsPeriodType == BarsPeriodType.Tick) allowDrawing = true;

        if (allowDrawing) RenderTarget.DrawLine();


        BarsPeriod - https://ninjatrader.com/support/help...barsperiod.htm

        We look forward to being of further assistance.
        JimNinjaTrader Customer Service

        Comment


          #5
          thanks for your reply. That make sense. But what should be best place to check ie, in onBarUpdate()? or in OnRender()?

          What would be the best syntax, if I don't want to render other than the insturment and time frame where the indicator is rendering?
          I am currently using 7 additional data series like below:

          else if (State == State.Configure)
          {
          AddDataSeries(BarsPeriodType.Minute, 15);
          AddDataSeries(BarsPeriodType.Minute, 60);
          AddDataSeries(BarsPeriodType.Minute, 240);
          AddDataSeries(BarsPeriodType.Day, 1);
          AddDataSeries(BarsPeriodType.Week, 1);
          AddDataSeries(BarsPeriodType.Month, 1);
          AddDataSeries(BarsPeriodType.Month, 3);
          }

          But when I render on 60 min, it renders on other time frames at the same time. But when I print BarsPeriod, it prints all added data series BarsPeriod and prints the bool as true, where as I am trying to restrict it only true for 60 min ie, the chart time frame where i am currently rendering the line. And currently I am trying with below:

          if (BarsArray[0].BarsPeriod == BarsPeriod)
          allowDrawing = true;

          it does not work as expected. For ref, I am using the same indicator with all other time frames as well at the same time to test.
          Please advise.

          Thanks in advance.
          Last edited by asmmbillah; 09-24-2019, 06:35 AM.

          Comment


            #6
            Hello asmmbillah,

            "allowDrawing" would be a private bool that you create in your script. You can check the BarsArray[0].BarsPeriod properties as early as State.DataLoaded to see what the BarsPeriod properties for the primary data series are (the data series the script is applied against.) If the primary data series is the data series that you want the script to draw against, set your allowDrawing bool to true, and use that bool to control your drawing in OnRender.

            If you are adding additional data series in your script, I may then suggest to use BarsInProgress checks for your OnBarUpdate logic so whatever you want to draw in OnRender is managed in OnBarUpdate within a BarsInProgress == 0 check and only relative to the script's primary data series.

            We look forward to being of further assistance.
            JimNinjaTrader Customer Service

            Comment


              #7
              Hi Jim,
              Thanks for your reply and notes.

              I have made the corrections and still it does not work. Let me guide you through what I did after the above suggestions:

              I have added
              private bool allowDrawing;

              As i am using additinal data series like below:

              else if (State == State.Configure)
              {
              AddDataSeries(BarsPeriodType.Minute, 15);
              AddDataSeries(BarsPeriodType.Minute, 60);
              AddDataSeries(BarsPeriodType.Minute, 240);
              AddDataSeries(BarsPeriodType.Day, 1);
              AddDataSeries(BarsPeriodType.Week, 1);
              AddDataSeries(BarsPeriodType.Month, 1);
              AddDataSeries(BarsPeriodType.Month, 3);
              }

              I have used in OnBarUpdate()

              if (BarsInProgress == 0 && BarsArray[0].BarsPeriod == BarsPeriod)
              allowDrawing = true;

              then I have used

              if (allowDrawing) RenderTarget.DrawLine();

              But no change in the render. For further ref I have made a small clip for you which you can watch in the below link:

              https://www.dropbox.com/s/25sqp7tfbg...04-05.mp4?dl=0

              I think for some reason, it is returning true always for all instances. It is not restricting the line drawing to the specific timeframe chart where the line is actually drawn manually. I may be wrong.

              I think, it will clarify even further what the issue is. I hope you will suggest the right path to solve this rendering issue.


              Thanks in advance.
              Last edited by asmmbillah; 09-25-2019, 06:58 AM.

              Comment


                #8
                Hello asmmbillah,

                if (BarsInProgress == 0 && BarsArray[0].BarsPeriod == BarsPeriod)

                In plain English, this translates to: if the iterating bar belongs to the primary data series, AND the BarsPeriod of the primary data series equals the BarsPeriod of the iterating bar.

                This would always be true when BarsInProgress 0 is iterating and would not perform any filtering.

                My suggestions would be to either check if the primary data series' BarsPeriod matches specific criteria (hard coded) OR that you make sure that your rendering code is only relevant to what is being processed with BarsInProgress == 0 in OnBarUpdate.

                Taking the latter approach, please make sure that everything that you are using in OnRender is relevant only to what you are calculating in a BarsInProgress == 0 check in OnBarUpdate. This would mean that everything that is done in OnRender would only be relative to what is calculated with the primary data series.

                Please let me know if you have any questions.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Thanks for your reply.

                  What I have understood from your above reply is to resolve the issue I should use below codes:

                  protected override void OnBarUpdate()
                  {

                  if (BarsInProgress == 0 )
                  {
                  allowDrawing = true;

                  }
                  }

                  and then

                  protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                  {
                  if (allowDrawing)
                  {
                  // Do all Rendering calculation and logic here
                  }

                  }

                  Is that what you meant?

                  Hard coded check will not be suitable for the goal of this indicator. Because it will be required to draw the line in different time frames.
                  And though it sounds quite easy, but What should be syntax if I want to specify only a specific time frame of an instrument than others while using several instance of same indicator on different charts of same instrument. Because when i am using BarsInProgress == 0 or BarsArray[0].Barsperiod it will be true for all time frames for that indicator. It is getting very confusing now for me. Becuase I am trying to simply restrict it to specific timeframe where I am drawing the line.

                  I know you don't do debuggin, but I am attaching the trimmed version of the script for your ref to give you ref, if I am missing anything to explain to you.

                  Only thing, what I understand is, can resolve the issue is to know how to define the current timeframe where the line is drawn. is it possible to store chart time frame to a variable where mouse was clicked? just an idea to try.
                  please advise.
                  Last edited by asmmbillah; 09-25-2019, 11:12 AM.

                  Comment


                    #10
                    Hello asmmbillah,

                    Thanks for your post.

                    OnRender will draw everything that it is told to draw. If you are adding criteria to draw from a global context, OnRender will draw it. From a general standpoint with indicators, we would use OnBarUpdate to calculate bar data and then save that information in variables or Series objects for our rendering.

                    Now in your case, you are using OnRender to render items that the script adds with its own button clicks. For the functionality of what you are trying to accomplish, I would instead recommend building a DrawingTool to meet the goal instead of rolling your own implementation in an indicator. If you follow the regular model for a DrawingTool, the object would then be seen only on the chart it is drawn on, unless the user decides to make this a global drawing object.

                    If you want to continue with an approach from an indicator, I could possibly suggest checking the AdvancedRiskReward Indicator as it provides OnRender functionality based on mouse clicks. This script would have been a better implementation in a DrawingTool, but it was converted from a NinjaTrader 7 indicator and left as an indicator for convenience. This approach would not be what we recommend and we couldn't offer additional support.

                    Once a Drawing Tool is created, you could invoke it from an indicator's added button with:
                    Code:
                    if (ChartControl != null)
                        ChartControl.TryStartDrawing("NinjaTrader.NinjaScript.DrawingTools.HorizontalLabeledLine");
                    Otherwise, I could not recommend a way identify the exact chart which would own the indicator that is performing your custom drawing. (You could possible check the BarsArray[0].Instrument and BarsArray[0].BarsPeriod properties on the mouse click and save these to private variables for comparing in OnRender, but with the way the script is built this may not work with charts of the same Instrument and BarsType.)

                    AdvancedRiskReward - https://ninjatraderecosystem.com/use...ard-indicator/

                    DrawingTool Documentation - https://ninjatrader.com/support/help...wing_tools.htm

                    Our Open Source DrawingTools can be referenced for further direction as well. You could gut the contents of an existing drawing tool in a copy and then use that as the base for this script.

                    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

                    Please let me know if I can be of further assistance.
                    JimNinjaTrader Customer Service

                    Comment


                      #11
                      Thanks for your reply. You mentioned "You could possible check the BarsArray[0].Instrument and BarsArray[0].BarsPeriod properties on the mouse click and save these to private variables for comparing in OnRender,"

                      Can you please add further details on this process and reference please? Because, I have stored the BarsPeriod after click and it does not render on other time frames until I click on the other time frame chart. When I do, it plots all the lines and draws new line. I was wondering if there is any way to avoid rendering old lines.

                      Do you think, is it a good idea to store lines in a Dictionary to key as barsPeriod and line as value ?

                      Thanks in advance.
                      Last edited by asmmbillah; 09-26-2019, 07:17 AM.

                      Comment


                        #12
                        Hello asmmbillah,

                        Please see attached demonstration for saving BarsPeriod and Instrument to private variables and checking those values with logic in OnRender.

                        BarsPeriod - https://ninjatrader.com/support/help...barsperiod.htm

                        Instrument - https://ninjatrader.com/support/help...instrument.htm

                        I look forward to being of further assistance.
                        Attached Files
                        JimNinjaTrader Customer Service

                        Comment


                          #13
                          Thanks for the sample script and your reply. That resolves the issue.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by lordvader34, Today, 07:07 AM
                          1 response
                          6 views
                          0 likes
                          Last Post lordvader34  
                          Started by aslane, Today, 07:01 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post aslane
                          by aslane
                           
                          Started by frankduc, Today, 06:56 AM
                          0 responses
                          4 views
                          0 likes
                          Last Post frankduc  
                          Started by priceisking, Yesterday, 06:57 PM
                          1 response
                          11 views
                          0 likes
                          Last Post NinjaTrader_PaulH  
                          Started by alantse123, Today, 12:22 AM
                          1 response
                          6 views
                          0 likes
                          Last Post NinjaTrader_PaulH  
                          Working...
                          X