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

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:

    This is an expansion of the the NinjaTrader Lines Drawing Tool(s) that adds text boxes to each line that will show prices associated with the endpoint or where the line crosses the price scale. Vertical lines will show time stamps. Your own messages can be added to each text box. New settings can be set […]


    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:	532
Size:	37.5 KB
ID:	1071061


                [ATTACH]n1071062[/ATTACH]
                Paul H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by BarzTrading, Today, 07:25 AM
                2 responses
                27 views
                1 like
                Last Post BarzTrading  
                Started by devatechnologies, 04-14-2024, 02:58 PM
                3 responses
                20 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by tkaboris, Today, 08:01 AM
                0 responses
                6 views
                0 likes
                Last Post tkaboris  
                Started by EB Worx, 04-04-2023, 02:34 AM
                7 responses
                163 views
                0 likes
                Last Post VFI26
                by VFI26
                 
                Started by Mizzouman1, Today, 07:35 AM
                1 response
                11 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X