• 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

Rendering a Ray type line in NT8

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

    Rendering a Ray type line in NT8

    Hi,
    I found this file in support forum which is attached here. It renders a horizontal line like Ray with a start poin. but I am trying to change it to ray type line which can be controlled by start and end point with a mouse click so that I can use it as a manually drawn trend line, but line should not end at the end point; rather continue like ray. I am attaching the file which I found in the forum. any advice from anyone here on how to go about that will be appreciated.

    currently I am using

    Point startAdj = new Point(startPoint.X, startPoint.Y);
    // Point endAdj = new Point(panel.X + panel.W, endPoint.X);
    endPoint.X = endPoint.Y + panel.W;
    Point endAdj = new Point(endPoint.Y + panel.W, endPoint.X);
    Attached Files
    Last edited by asmmbillah; 09-16-2019, 07:11 AM.

    #2
    Hello

    Thanks for your post.

    I would suggest downloading and installing the full labeled lines drawing tool set which already includes a Ray and just use that tool set. If you really just want to modify the file you found, you could use the download as an example for modifying to obtain the Ray functionality.

    This Drawing Tool set is publicly available on our NinjaTrader Ecosystem website:

    https://ninjatraderecosystem.com/use...-drawing-tool/

    Here is a basic guideline of how to Import NinjaScripts.

    To import NinjaScripts you will need the original .zip file.

    To Import
    1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
    2. From the Control Center window select the menu Tools>import>Ninjascript add-on..
    3. Select the downloaded .zip file
    4. NinjaTrader will then confirm if the import has been successful.
    Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

    Once installed, the drawing tools for labeled lines will show in the drawing tool drop down.

    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.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your suggestion. That helped.

      But I am trying to plot text at the end of the ray like the file I attached and I am using the below code:

      TextFormat textFormat = chartControl.Properties.LabelFont.ToDirectWriteTex tFormat();
      string label = BarsPeriod.Value.ToString()+BarsPeriod.BarsPeriodT ype.ToString();
      TextLayout textLayout = new TextLayout(Globals.DirectWriteFactory, label, textFormat, 999, textFormat.FontSize);
      Point labelAnchor = new Point(panel.W - textLayout.DetermineMinWidth(), extPoint.Y);
      RenderTarget.DrawTextLayout(labelAnchor.ToVector2( ), textLayout, Stroke.BrushDX);
      textLayout.Dispose();

      it is showing error "Error on calling "OnRender" method on bar 6219: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

      I don't know why this error is showing, please help.

      Comment


        #4
        Hello asmmbillah,

        Thanks for your post.

        While we do not provide debugging services, I suspect the issue relates to the use of BarsPeriod.Value and BarsPeriod.BarsPeriodType in OnRender().
        These would not exist in OnRender(). You could put their values either in a class level string or int variable type actually in State.DataLoaded as they would not change. As a class level variable, they would be available in all methods of the class.including OnRender().

        If that does not resolve the issue, i suggest adding print statements to find out at which line the code fails and debugging from there. Here is a link to our debugging tips: https://ninjatrader.com/support/help...script_cod.htm
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks.

          after using print statement, I found at RenderTarget.DrawTextLayout(labelAnchor.ToVector2( ), textLayout, Stroke.BrushDX); the code fails. Any suggestion?

          Comment


            #6
            Hello asmmbillah,

            Thanks for your reply.

            I would continue debugging with print statements. With the failure point found the next step would be to identify all of the variables values used in the code block up to that statement to see if anything is not as expected. Do not assume, print out the values to be certain.

            Also, make sure that you are removing the drawn line and use a newly drawn line with each use of new script.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Thanks a lot Paul for the above suggestion. That solved the error.

              Now I am trying to find a way to set to do something when Price on current bar crosses above or crosses below the line rendered. I have checked few examples on this forum but couldn't find any which may put me in the right direction to work with a rendered ray kind of line. I will appreciate, if you could direct me to the correct reference or example here. thanks in advance.

              Comment


                #8
                Hello asmmbillah,

                Thanks for your reply.

                What you would do is to gather the start anchor and end anchor as these provide your X & Y values and then calculate the slope of the ray. Once you have the slope then you can project the value of the ray on each new bar and check the price value to the ray value on current bar.

                I've attached an example indicator that, when connected to live data, when the current bar closes, will draw a ray. The indicator then calculates the Ray location on each new bar and plots a dot to shows its projected value, so the dots should cover the ray. (see attached screenshot of expected results)

                Click image for larger version

Name:	Yprojectedline.PNG
Views:	14
Size:	37.5 KB
ID:	1071061


                YAxisProjection.zip
                Paul H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by aslane, Today, 02:31 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Kate  
                Started by stoner, 10-16-2019, 01:38 PM
                5 responses
                51 views
                0 likes
                Last Post sledge
                by sledge
                 
                Started by music_p13, Today, 12:04 PM
                1 response
                24 views
                0 likes
                Last Post NinjaTrader_Kate  
                Started by zaro33, Today, 10:55 AM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_Heath  
                Started by itrader46, Today, 10:16 AM
                5 responses
                11 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X