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

Vertical offset in rendering once indicator is exported as assembly to another system

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

    Vertical offset in rendering once indicator is exported as assembly to another system

    My indicator is drawing using OnRender. When executed on my computer (development system) everything is preforming as expected. See the first image below.

    After exporting as Assembly to another computer the rendering is done higher on the screen than it should. See the second image below.

    I am using Wpf, and a set of functions to simplify the translation between price to screen coordinates. Please see the short code for DrawDXLine.

    Click image for larger version  Name:	Screen Shot 2022-07-27 at 4.02.36 PM.png Views:	0 Size:	1.50 MB ID:	1209890

    Click image for larger version  Name:	MichasScreen01.png Views:	0 Size:	1,004.5 KB ID:	1209889

    Code:
    protected void DrawDXLine(int idxslot1, int idxslot2, double val1, double val2, Stroke stroke, ChartControl chartControl, Gui.Chart.ChartScale chartScale)
    {
    DrawDXLine(idxslot1, idxslot2, val1, val2, stroke.Brush, stroke.DashStyleHelper, stroke.Width, chartControl, chartScale, stroke.Opacity);
    }
    
    protected void DrawDXLine(int idxslot1, int idxslot2, double val1, double val2, Brush brush, DashStyleHelper dashStyle, float width, Gui.Chart.ChartControl chartControl, Gui.Chart.ChartScale chartScale, int opacity = 100)
    {
    Point p1 = new Point(BarToX(idxslot1, chartControl), PriceToY(val1, chartScale));
    Point p2 = new Point(BarToX(idxslot2, chartControl), PriceToY(val2, chartScale));
    DrawDXLine(p1, p2, brush, dashStyle, width, chartControl, chartScale, opacity);
    }
    
    protected void DrawDXLine(double x1, double x2, double y1, double y2, Brush brush, DashStyleHelper dashStyle, float width, Gui.Chart.ChartControl chartControl, Gui.Chart.ChartScale chartScale, int opacity = 100)
    {
    Point p1 = new Point(x1, y1);
    Point p2 = new Point(x2, y2);
    DrawDXLine(p1, p2, brush, dashStyle, width, chartControl, chartScale, opacity);
    }
    
    protected void DrawDXLine(Point p1, Point p2, Brush brush, DashStyleHelper dashStyle, float width, ChartControl chartControl, Gui.Chart.ChartScale chartScale, int opacity = 100)
    {
    SharpDX.Direct2D1.DashStyle _dashStyle;
    if (!Enum.TryParse(dashStyle.ToString(), true, out _dashStyle)) _dashStyle = SharpDX.Direct2D1.DashStyle.Dash;
    SharpDX.Direct2D1.StrokeStyleProperties properties = new SharpDX.Direct2D1.StrokeStyleProperties() {DashStyle=_dashStyle};
    SharpDX.Direct2D1.StrokeStyle strokeStyle = new SharpDX.Direct2D1.StrokeStyle(Core.Globals.D2DFact ory, properties);
    SharpDX.Direct2D1.Brush dxBrush = brush.ToDxBrush(RenderTarget);
    dxBrush.Opacity = opacity/100f;
    RenderTarget.DrawLine(p1.ToVector2(), p2.ToVector2(), dxBrush, width, strokeStyle);
    dxBrush.Dispose();
    strokeStyle.Dispose();
    }
    //retrieve the x coordinate in pixel of a a relative bar index.
    
    protected double BarToX(int bars, Gui.Chart.ChartControl chartControl, bool atMiddle = false)
    {
    return chartControl.GetXByBarIndex(chartControl.BarsArray[0], bars) - (atMiddle ? (chartControl.Properties.BarDistance / 2) : 0);
    }
    
    //retrieve the y coordinate in pixel of a a relative price.
    protected double PriceToY(double val, Gui.Chart.ChartScale chartScale)
    {
    return chartScale.GetYByValueWpf(val);
    }
    Last edited by Shai Samuel; 07-27-2022, 07:40 AM.

    #2
    Hello Shai Samuel,

    May I confirm the val1 value is coming from WPF (like a mouse click)?

    I see you are using GetYByValueWpf() (used for converting a WPF value to the sharp dx y value) instead of GetYByValue() (used to convert a price to a sharp dx y value).

    https://ninjatrader.com/support/help...byvaluewpf.htm
    https://ninjatrader.com/support/help...etybyvalue.htm

    Does this example have the same behavior on that computer?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Yes, you are correct. Thank you.

      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