Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Use of SharpDX to Draw Line

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

    #16
    [
    Originally posted by NinjaTrader_Jesse View Post
    Hello aligator,

    The script you attached is using drawing objects, you could limit that to the last drawn values by using a non unique tag name for the lines. Each time you call Draw.Line it will just update the existing line on the chart. Right now it uses lastlobar.ToString() as the string, you could use something like "MyLine" instead to make it non unique. In regard to seeing that as sharpdx instead that is something you could do if you wanted, that is not something our support could do for you. If any users wanted to make that modification and post the result they can certainly do that.
    Thank you Jesse. As I indicated in post #1, I have been following what you just described for using Draw.Line(). I simply wanted to know if this approach is possible in SharpDX, obviously it is not as you mentioned above.

    It would really be helpful if at least one resource-hungry indicator is rendered in SharpDX as an example, so that not-so-savy-NinjaTrader-Users can use it for further developement. One such indicator is the duo Head and Shoulder indicator written by NinjaTrader, "Stocks and Commodities - May 2013 - Detecting Head & Shoulders Algorithmically"

    Thank you again for the follow up.

    Cheers!

    Attached Files
    Last edited by aligator; 08-06-2024, 11:49 AM.

    Comment


      #17
      Hello aligator,

      It is also possible in SharpDX to draw a single line. SharpDX does not use a tag system so to draw a single line you would have a single line of code in OnRender like the following:

      Code:
      RenderTarget.DrawLine(Vector2 point0, Vector2 point1, Brush brush)

      That method takes two points which are X/Y points in the chart and a brush for color of the line. That draws a line from point a to point b. That single line in OnRender is all that is needed to draw 1 instance of a line. Anytime that line needs updated the points you are using for it would need to change to the new values and you continue using just that 1 line of code to render the line on the chart.

      While I cannot modify items for you I can recommend that you reach out to a third party developer if you wanted to have items created or modified in a custom way to improve performance. If other users feel they want to take on that type of task they can certainly modify and attach the script here. If this is something you wanted to attempt yourself we can continue to walk through what steps are required to draw 1 line on the chart while using OnRender. To go beyond that and have an option to toggle between 1 line or many lines while using OnRender would be much more involved because you then need to start storing data points in a collection so you have "instances" to loop over in OnRender so you can render lines for each instance.

      JesseNinjaTrader Customer Service

      Comment


        #18
        New example from previous post



        With updated post#10 script



        Attached all User Apps Share Scripts containing "SharpDX" as string

        Ninjatrader Manual to look for the string "OnRender()" examples all in one place with Ctrl+F:


        Not sure it is the latest manual version but should give better insightful help with OnRender().

        New indicator with SharpDX

        RenkoTrader v1.6
        https://ninjatraderecosystem.com/user-app-share-download/renko-trader-bot-semi-automatic-with-interface-and-higher-time-frame-filter/

        Hello guys this is a semi automatic bot, that will work on any renko chart, it has to be on a renko chart in order to work. Features: -Buttons interface to control bot from chart trader -Long/Short Button can trade on direction selected by user -Time filter in settings to select time bot should be […]




        New Example:
        SharpDX labels to the margin for the 4 plots of the PriorOHLC.cs


        Code:
                protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                {
        
                     base.OnRender(chartControl, chartScale);
                
                    float startX = (chartControl.GetXByBarIndex(ChartBars, ChartBars.ToIndex)) + ((float)LeftEdgeOffset) ;
                    float endX = (ChartPanel.X + ChartPanel.W);
                    bool firstLoop                    = true;            
                    string[] plotLabels        = new string[Values.Length];   /// another using the [] symbol using Values.Length itteration            
                    SharpDX.Direct2D1.Brush[] brushesDX = new SharpDX.Direct2D1.Brush[Values.Length];   /// check with NT forum to see what's needed 4support            
                    SharpDX.Vector2 textStartDX;
                    TextFormat textFormat = new TextFormat(Globals.DirectWriteFactory, "Arial", (float)this.TextFontSize);
                    float textFontSize                = textFormat.FontSize;
                    
                
                                                Print("Current Bar is    " + CurrentBar);                    
                                                Print(" Font Size is    " + textFormat.FontSize);
                                                Print(" start X is        " + startX );
                                                Print(" endX is         " + endX );
                    
                    
                    
                    for (int i = 0; i < Values.Length; i++)     /// this loop is working
                    {
        
                        Print("Values[i] is        " + Values[i].GetValueAt(CurrentBar - 1) );      /// this call is not
                        
                        if (Values[i].IsValidDataPointAt(CurrentBar - 1) && firstLoop && ShowLabels)    /// nor is this call
                        {
                            double plotValue = Values[i].GetValueAt(CurrentBar - 1);
                            float chartScaleYValue = chartScale.GetYByValue(plotValue);
                            plotLabels[i]             = Plots[i].Name;
                            brushesDX[i]                 = Plots[i].BrushDX;
                            
                                                Print("Current Bar is        " + CurrentBar);                    
                                                Print(" plotValue is        " + plotValue);
                                                Print(" startX is            " + startX);
                                                Print(" endX is                " + endX );
                                                Print(" chartScaleYValue is    " + chartScaleYValue );    
                            
                            textStartDX = new SharpDX.Vector2( (float)startX, (float)(chartScaleYValue - textFontSize/2) );
                            
                                                Print("textStartDX is        " + textStartDX);
                                                Print("plot name is            " + plotLabels[i]);
                                                Print("plots brush is        " + brushesDX[i]);
        
                            TextLayout textLayout = new TextLayout(Globals.DirectWriteFactory, plotLabels[i], textFormat, (float)ChartPanel.W - startX, textFontSize);
                            RenderTarget.DrawTextLayout(textStartDX, textLayout , brushesDX[i]);
                            
                            textLayout.Dispose();
        
                        }
        
                    }            
        //                   firstLoop = false;            
                }​
        Attached Files
        Last edited by PaulMohn; 08-07-2024, 04:36 AM.

        Comment


          #19
          All you guys need to do is copy the code and paste it into the strategy builder manually. For some reason dragging and dropping the files into the indicator folder causes an error. However, if you create both indicators manually in ninjascript editor, they work perfectly. I just did it. Be sure to name them at the begining as the same file names. Copy the code from the text file that you can pull up by opening it and viewing in notepad. Run compilation and save. One important note, when you do it, one may not compile because its looking for the other, so an error pops up. Just goto the "+" at the bottom of the script editor and start creating the second indicator, name it. Compile it, go back to the first one, boom. done.
          goto NEW, NINJASCRIPT EDITOR. Hit that "+" and then Indicator. Go easy peasy. good luck. Click image for larger version

Name:	image.png
Views:	25
Size:	87.7 KB
ID:	1334904

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by DoomNM, Today, 01:12 AM
          0 responses
          6 views
          0 likes
          Last Post DoomNM
          by DoomNM
           
          Started by kalalex, Yesterday, 01:31 AM
          2 responses
          25 views
          0 likes
          Last Post AndyM
          by AndyM
           
          Started by bxl2019, 03-16-2025, 12:34 PM
          3 responses
          22 views
          0 likes
          Last Post Leeroy_Jenkins  
          Started by Hilltree, Yesterday, 09:00 AM
          2 responses
          16 views
          0 likes
          Last Post Hilltree  
          Started by samish18, Yesterday, 06:46 PM
          0 responses
          10 views
          0 likes
          Last Post samish18  
          Working...
          X