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

Converting a custom NT 7 indicator to NT 8

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

    Converting a custom NT 7 indicator to NT 8

    Hello

    I would like to convert a custom NT 7 indicator to NT 8. This indicator is a bit advanced. I believe I have converted most of it but there are questions regarding some parts of it:

    1) Are the following conversions from NT 7 to NT 8 valid:

    Part I
    ===========

    Point -> SharpDX.Vector2

    ChartControl.BarSpace -> ChartControl.Properties.BarDistance

    Bars.Get(barIndex).High -> _Bars.GetHigh(barIndex)

    ChartControl.LastBarPainted -> ChartBars.ToIndex

    ChartControl.FirstBarPainted -> ChartBars.FromIndex

    ChartControl.LastBarPainted -> ChartBars.ToIndex

    ChartControl.BarSpace -> ChartControl.Properties.BarDistance

    Bars.GetSessionBar(0) -> Bars.GetSessionEndTime(0)

    Bars.Get(lastBarIndex).Time.TimeOfDay -> Bars.GetTime(lastBarIndex).TimeOfDay

    Rectangle -> SharpDX.RectangleF

    Point.Empty -> SharpDX.Point.Zero

    ChartControl.ChartPanel.Invalidate() -> Invalidate()

    NT 7:
    -------
    MouseEventArgs e

    Point testPnt = new Point (e.X, e.Y);

    NT 8 equivalent?:
    ------------------------
    MouseButtonEventArgs e

    SharpDX.Point testPnt = new SharpDX.Point((int)e.GetPosition(ChartControl).X, (int)e.GetPosition(ChartControl).Y);


    NT 7:
    -------
    KeyEventArgs e

    if ((e.KeyCode == Keys.W) && (e.Control == true))

    NT 8 equivalent?:
    ----------------------
    KeyEventArgs e

    if ((e.Key == Key.W && Keyboard.Modifiers == ModifierKeys.Control))

    NT 7:
    -------
    this.ChartControl.ChartPanel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_ MouseDown);
    this.ChartControl.ChartPanel.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_ MouseMove);
    this.ChartControl.ChartPanel.KeyDown += new System.Windows.Forms.KeyEventHandler (this.chart_KeyDown);
    this.ChartControl.ChartPanel.Paint += new System.Windows.Forms.PaintEventHandler (this.chart_Paint);​

    NT 8 equivalent?:
    -----------------------
    ChartPanel.MouseDown += func_MouseDown;
    ChartPanel.MouseMove += func_MouseMove;
    ChartPanel.KeyDown += func_KeyDown;
    ChartPanel.Paint += ???




    Last edited by svrz; 08-30-2023, 08:07 AM.

    #2
    Part II
    ======================

    NT 7:
    --------
    Code:
    public void DrawSnap (Graphics graphics, Rectangle rect, Color color)
    {
    if (graphics == null)
    return;
    
    SmoothingMode oldSmoothingMode = graphics.SmoothingMode;
    graphics.SmoothingMode = SmoothingMode.HighQuality ;
    
    graphics.FillRectangle( new SolidBrush (color), rect);
    
    graphics.SmoothingMode = oldSmoothingMode;
    }
    NT 8 equivalent?:
    ----------------------

    Code:
    public void DrawSnap(SharpDX.RectangleF rect, SharpDX.Color color, SharpDX.Direct2D1.RenderTarget renderTarget)
    {
    //The NT 8 equivalent for following commented out lines are unknown
    //SmoothingMode oldSmoothingMode = graphics.SmoothingMode;
    //graphics.SmoothingMode = SmoothingMode.HighQuality;
    
    //graphics.FillRectangle(new SolidBrush(color), rect);
    
    //graphics.SmoothingMode = oldSmoothingMode;
    using (SharpDX.Direct2D1.SolidColorBrush customDXBrush = new SharpDX.Direct2D1.SolidColorBrush(renderTarget, color))
    {
    renderTarget.FillRectangle(rect, customDXBrush);
    }
    }
    NT 7:
    --------
    Code:
    protected void Draw (Graphics graphics, List<LineEx> TrendLines, Color color, int width)
    {
    SmoothingMode oldSmoothingMode = graphics.SmoothingMode;
    graphics.SmoothingMode = SmoothingMode.HighQuality ;
    Pen pen = new Pen (color, width);
    for (int i=0; i < TrendLines.Count; i++)
    graphics.DrawLine (pen, TrendLines[i].P1, TrendLines[i].P2);
    
    graphics.SmoothingMode = oldSmoothingMode;
    }
    NT 8 equivalent?:
    ----------------------
    Code:
    protected void Draw(List<LineEx> TrendLines, SharpDX.Color color, int width, SharpDX.Direct2D1.RenderTarget renderTarget)
    {
    //***@@todo-check***
    //RenderTarget.DrawLine()
    
    //SmoothingMode oldSmoothingMode = graphics.SmoothingMode;
    //graphics.SmoothingMode = SmoothingMode.HighQuality;
    //Pen pen = new Pen(color, width);
    //for (int i = 0; i < TrendLines.Count; i++)
    // graphics.DrawLine(pen, TrendLines[i].P1, TrendLines[i].P2);
    
    //graphics.SmoothingMode = oldSmoothingMode;
    
    for (int i = 0; i < TrendLines.Count; i++)
    {
    using (SharpDX.Direct2D1.SolidColorBrush customDXBrush = new SharpDX.Direct2D1.SolidColorBrush(renderTarget, color))
    {
    renderTarget.DrawLine(TrendLines[i].P1, TrendLines[i].P2, customDXBrush, width);
    }
    }
    }
    ​​​​

    Comment


      #3
      Part III
      ======================

      NT 7:
      -----
      Code:
      public bool IsInLine(Channel channel, Point pnt)
      {
      List<LineEx> TrendLines = CreateTrendlines ( channel );
      
      Pen p = new Pen(Color.Black, 8);
      GraphicsPath pth=new GraphicsPath();
      
      for (int i=0; i < TrendLines.Count; i++)
      {
      pth.Reset ();
      
      if (TrendLines[i].P1 != TrendLines[i].P2)
      {
      pth.AddLine( TrendLines[i].P1, TrendLines[i].P2 );
      pth.Widen(p);
      
      if(pth.IsVisible(pnt))
      {
      p.Dispose();
      return true;
      }
      }
      }
      p.Dispose();
      return false;
      }

      NT 8 equivalent?
      -------------------------​
      Code:
      public bool IsInLine(Channel channel, SharpDX.Vector2 pnt, SharpDX.Direct2D1.RenderTarget renderTarget)
      {
      List<LineEx> TrendLines = CreateTrendlines(channel);
      
      //Pen p = new Pen(Color.Black, 8);
      //GraphicsPath pth = new GraphicsPath();
      SharpDX.Direct2D1.PathGeometry pth = new SharpDX.Direct2D1.PathGeometry(Core.Globals.D2DFac tory);
      SharpDX.Direct2D1.GeometrySink geometrySink = pth.Open();
      
      for (int i = 0; i < TrendLines.Count; i++)
      {
      //pth.Reset();
      
      if (TrendLines[i].P1 != TrendLines[i].P2)
      {
      //pth.AddLine(TrendLines[i].P1, TrendLines[i].P2);
      //pth.Widen(p);
      
      SharpDX.Vector2[] vector2 = new SharpDX.Vector2[2];
      
      vector2[0] = TrendLines[i].P1;
      vector2[1] = TrendLines[i].P2;
      
      geometrySink.AddLines(vector2);
      
      //@@todo isvisible | widen
      if (pth.FillContainsPoint(pnt))
      {
      pth.Dispose();
      return true;
      }
      
      //if (pth.IsVisible(pnt))
      //{
      // p.Dispose();
      // return true;
      //}
      }
      }
      
      geometrySink.EndFigure(SharpDX.Direct2D1.FigureEnd .Closed);
      geometrySink.Close();
      
      SharpDX.Direct2D1.SolidColorBrush customDXBrush =
      new SharpDX.Direct2D1.SolidColorBrush(renderTarget, SharpDX.Color.Black);
      
      renderTarget.FillGeometry(pth, customDXBrush);
      
      //p.Dispose();
      pth.Dispose();
      customDXBrush.Dispose();
      
      return false;
      }
      Last edited by svrz; 08-29-2023, 04:07 PM.

      Comment


        #4
        Part IV
        --------

        NT 7
        ------
        Code:
        public int IsInAnchorPoint (Rectangle[] rectAnchor, Point pnt)
        {
        int AnchorPointSelected = 0;
        
        Rectangle rect;
        for (int i=0; i < 4; i++)
        {
        rect = Rectangle.Inflate (rectAnchor[i], 4,4);
        if ( rect.Contains (pnt) )
        {
        AnchorPointSelected =(i+1);
        return AnchorPointSelected ;
        }
        }
        return AnchorPointSelected ;
        }

        NT 8?
        -------
        Code:
        public int IsInAnchorPoint(SharpDX.RectangleF[] rectAnchor, SharpDX.Vector2 pnt)
        {
        int AnchorPointSelected = 0;
        
        for (int i = 0; i < 4; i++)
        {
        SharpDX.RectangleF rect = new SharpDX.RectangleF(rectAnchor[i].X, rectAnchor[i].Y, rectAnchor[i].Width,
        rectAnchor[i].Height);
        rect.Inflate(4, 4);
        if (rect.Contains(pnt))
        {
        AnchorPointSelected = (i + 1);
        return AnchorPointSelected;
        }
        }
        return AnchorPointSelected;
        }
        NT 7
        -------
        Code:
        public void DrawAnchor (Graphics graphics, int point, Color color, bool inflate, Rectangle[] rectAnchor)
        {
        Rectangle rect ;
        
        if (inflate)
        rect = Rectangle.Inflate (rectAnchor[point-1], 1,1);
        else
        rect = rectAnchor[point-1];
        
        if (point < 4)
        graphics.FillRectangle( new SolidBrush (color), rect);
        else
        graphics.FillEllipse (new SolidBrush (color), rect);
        }


        NT 8?
        -------
        Code:
        public void DrawAnchor(int point, SharpDX.Color color, bool inflate, SharpDX.RectangleF[] rectAnchor,
        SharpDX.Direct2D1.RenderTarget renderTarget)
        {
        SharpDX.RectangleF rect;
        
        if (inflate)
        {
        rect = new SharpDX.RectangleF(rectAnchor[point - 1].X, rectAnchor[point - 1].Y, rectAnchor[point - 1].Width,
        rectAnchor[point - 1].Height);
        rect.Inflate(1, 1);
        }
        
        else
        rect = rectAnchor[point - 1];
        
        //***@@todo***
        SharpDX.Direct2D1.Ellipse ellipse = new SharpDX.Direct2D1.Ellipse();
        if (point < 4)
        FillRect(rect, color, renderTarget);
        else
        FillEllipse(ellipse, color, renderTarget);
        }
        NT 7
        -----
        Code:
        private void FillRect(SharpDX.RectangleF rect, SharpDX.Color color, SharpDX.Direct2D1.RenderTarget renderTarget)
        {
        using (SharpDX.Direct2D1.SolidColorBrush customDXBrush = new SharpDX.Direct2D1.SolidColorBrush(renderTarget, color))
        {
        renderTarget.FillRectangle(rect, customDXBrush);
        }
        }
        NT 8?
        -----
        Code:
        private void FillEllipse(SharpDX.Direct2D1.Ellipse ellipse, SharpDX.Color color, SharpDX.Direct2D1.RenderTarget renderTarget)
        {
        using (SharpDX.Direct2D1.SolidColorBrush customDXBrush = new SharpDX.Direct2D1.SolidColorBrush(renderTarget, color))
        {
        renderTarget.FillEllipse(ellipse, customDXBrush);
        }
        }
        NT 7
        -------
        Code:
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
        {
        
        }
        NT 8?
        ------
        ???​​​​

        Any help or hint is greatly appreciated.

        Comment


          #5
          Hello svrz,

          While I won't be able to go through each individual item you posted it does look like you are on the right track. When converting items its best to convert small parts of the code at a time and test that code to ensure it has the same output/result as the original nt7 code. You can find a lot of the differences between nt7 and nt8 in the code breaking changes guide. Prints would be the best go to for doing conversions so you can print the values of the items you mentioned to make sure its working in an equivalent way.

          JesseNinjaTrader Customer Service

          Comment


            #6
            Thanks for reply, Jesse.

            Can you at least tell me what the NT 8 equivalents of the following NT 7 classes are? I don't believe the above link addresses any of these classes.

            Graphics
            SmoothingMode
            GraphicsPath

            Thanks in advance.

            Comment


              #7
              Hello svrz,

              The rendering items may or may not have an equivalent in nt8, you likely will need to redesign that part of the script to match how NT8 renders. You can now use the sharpdx library for rendering. There are details about custom rendering in the following pages:



              JesseNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Mathias79, Today, 10:38 AM
              0 responses
              1 view
              0 likes
              Last Post Mathias79  
              Started by 21laienoch, Today, 10:21 AM
              1 response
              3 views
              0 likes
              Last Post NinjaTrader_ChristopherJ  
              Started by synthhokie, Today, 10:24 AM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by RaddiFX, Today, 10:15 AM
              1 response
              3 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by Rogers101, 05-05-2024, 11:30 AM
              23 responses
              68 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X