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

Drawing a Custom Line

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

    Drawing a Custom Line

    The syntax for DrawLine() require "Integer" values for "startBarsAgo" and "endBarsAgo." However, I want to draw a line between two points that are fractions of a distance between two points on time axis. Thus the input for x will be a double, and if used as such an error will be generated that can not implicitly convert a double to an integer.

    Some questions:

    How can a double be used for x values for start and end of the line?

    As an example, how this situation is coded for drawing the vertical lines for Fibonacci Time Extensions levels?

    How to code converting a double to int (Math.Round...does not work, because the result is still a double)?

    Thanks
    Last edited by aligator; 11-05-2015, 09:59 AM.

    #2
    Hello,
    Can you provide an example of what you are trying to do?
    What you are wanting to accomplish may be possible using DateTIme values for the DrawLine overload.

    To convert a double to an int you can do Convert.ToInt32(enter double value here);
    Cody B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_CodyB View Post
      Hello,
      Can you provide an example of what you are trying to do?
      What you are wanting to accomplish may be possible using DateTIme values for the DrawLine overload.

      To convert a double to an int you can do Convert.ToInt32(enter double value here);
      Thank you CodyB:

      What I am trying to do is to draw Rectangle at the cross of the Fib Retracement and Time Extension Ratios. Also, drawing a line with Fib Ratio markings extended in time.

      Perhaps it is easier to explain using the attached screen shot.

      The problem I have is that fib ratios are doubles and the Syntax for time (x) axis will only accept integers. However, looking at your TimeExtensions Fib ratios I know it is possible to use doubles on time axis. I Just can't find a way to do that. Please take a look at the attached.

      Many Thanks.
      Attached Files

      Comment


        #4
        Hello,

        Thank you for the question.

        While what you are trying to do is possible, it would not be using the standard DrawingTools. The drawing objects in NinjaTrader are specific to being locked to a BarsAgo value, what you instead seem to be looking for are specific X and Y coordinates based on Time and Price which is possible. This would allow for between the bar drawing for example.

        To do this, you would instead need to use the Plot override. This is an advanced programming topic though so there is not much documentation regarding this, the best way to learn this would be from the example included.

        There is a sample called CustomPlotSample in the indicators that demonstrates some basics.

        You would need to use the following methods to convert values:

        Code:
        ChartControl.GetXByTime(Time[0]);
        
        ChartControl.GetYByValue(this, Close[0]);

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

        Comment


          #5
          Originally posted by NinjaTrader_CodyB View Post
          Hello,
          Can you provide an example of what you are trying to do?
          What you are wanting to accomplish may be possible using DateTIme values for the DrawLine overload.

          To convert a double to an int you can do Convert.ToInt32(enter double value here);
          Thank you Cody.

          Using the Convert.ToInt32(double) compiles, however it does not plot on chart.

          I am using the NT7 (64). Would that be the reason for not plotting. Would the Convert plot if I use NT7 (32)?

          Thanks.

          Comment


            #6
            Hello,

            If a script compiles, that does not necessarily mean it would work correctly depending on the logic you are using.

            Are you getting an error? Try checking the Tools -> Output window and leave it open while you refresh the indicator.

            If you are find with snapping the lines to the bars, rounding the value should work so long as the value is being rounded correctly and you have verified the output is correct.

            Can you confirm if you are getting errors in the output window?

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

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bortz, 11-06-2023, 08:04 AM
            47 responses
            1,607 views
            0 likes
            Last Post aligator  
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            9 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            19 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            6 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            15 views
            0 likes
            Last Post Javierw.ok  
            Working...
            X