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

RenderTarget to render in price + indi panels

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

    RenderTarget to render in price + indi panels

    Hello,

    With one single indicator, is it possible to render simultaneously in the price panel and in the indicator panel, by means of the RenderTarget object?

    Thanks

    #2
    Hello cls71,
    Thanks for your post.

    It is possible. However, it is not supported.

    We can leave this forum post open to see if any users have an example of how to do this.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Thanks JoshG, If would be possible, would you be so kind as to share a simple script? For example, render a line in the price panel and other line in the indicator panel simultaneously. Thanks in advance.

      Comment


        #4
        cls71,

        This is going to be unsupported. I have no further information.
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          I will share here what I discover ...

          The indicator is loaded in an independent panel and DrawOnPricePanel = true.
          With this code I can access the ChartBars RenderTarget. I thought I could use this RenderTarget to render in the price panel, but it's not like that. Render but without getting to paint in the price panel.

          Apparently, when the OnRender method of the indicator is executed, the price panel is inaccessible (even if you use the RenderTarget from the price panel).

          Code:
            SharpDX.Direct2D1.RenderTarget RTchartbars;
          
            public override void OnRenderTargetChanged()
            {
                      RTchartbars = null;
          
                      foreach(NinjaTrader.Gui.NinjaScript.IChartObject o in ChartControl.ChartObjects )
                      {
                          if (o.Name == "ChartBars")
                          {
                              Dispatcher.InvokeAsync(new Action(() =>
                              {
                                  RTchartbars = o.RenderTarget;
                              }));
                          }
                      }
            }
          
            protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
            {
                      RenderTarget.FillRectangle(new SharpDX.RectangleF(20, 100, 200, 200), Brushes.RoyalBlue.ToDxBrush(RenderTarget));
          
                      if (RTchartbars != null)
                          RTchartbars.FillRectangle(new SharpDX.RectangleF(80, 400, 300, 300), Brushes.Fuchsia.ToDxBrush(RTchartbars));
            }

          Comment


            #6
            Originally posted by cls71 View Post
            I will share here what I discover ...

            The indicator is loaded in an independent panel and DrawOnPricePanel = true.
            With this code I can access the ChartBars RenderTarget. I thought I could use this RenderTarget to render in the price panel, but it's not like that. Render but without getting to paint in the price panel.

            Apparently, when the OnRender method of the indicator is executed, the price panel is inaccessible (even if you use the RenderTarget from the price panel).
            Were you ever able to figure it out?

            Comment


              #7
              Ok I may have a solution for people... fairly fresh in the making, so may still need some tweaks, but so far so good.
              In your indicator, implement IRenderPassThroughTarget and do the rendering in that implemented method rather than the main OnRender. This will enable you to draw directly to the Price Panel.
              In your OnStateChange::Configure / DataLoaded method, Create an instance of the RenderHelperDrawingTool using the static factory method. Let me know if any issues crop up - as I say, only created yesterday

              Code:
              public interface IRenderPassThroughTarget
              {
                 void RenderFromPassThrough(RenderTarget renderTarget, ChartControl chartControl, ChartScale chartScale);
              }
              
              public class RenderHelperDrawingTool : DrawingTool
              {
                 public IRenderPassThroughTarget PassThroughTarget { get; private set; }
              
                 public static RenderHelperDrawingTool Create(NinjaScriptBase owner, string tag, IRenderPassThroughTarget passThroughTarget)
                 {
                    return DrawToggledPricePanel(owner, true, () =>
                    {
                       RenderHelperDrawingTool result = GetByTagOrNew(owner, typeof(RenderHelperDrawingTool), tag, null) as RenderHelperDrawingTool;
              
                       if (result != null)
                       {
                          SetDrawingToolCommonValues(result, tag, false, owner, false);
              
                          result.PassThroughTarget = passThroughTarget;
              
                          result.SetState(State.Active);
                    }
              
                    return result;
                 });
              }
              
              protected override void OnStateChange()
              {
                 if (State == State.SetDefaults)
                 {
                    Name = "RenderHelperTool";
                    IsLocked = true;
                    IsVisible = true;
                    IgnoresUserInput = true;
                 }
                 else if (State == State.Configure)
                 {
                 }
              }
              
              public override void OnRender(ChartControl chartControl, ChartScale chartScale)
              {
                 if (PassThroughTarget != null)
                 {
                    PassThroughTarget.RenderFromPassThrough(RenderTarg et, chartControl, chartScale);
                 }
              }
              }
              rebelant
              NinjaTrader Ecosystem Vendor - rebelant

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by cls71, Today, 04:45 AM
              0 responses
              1 view
              0 likes
              Last Post cls71
              by cls71
               
              Started by mjairg, 07-20-2023, 11:57 PM
              3 responses
              213 views
              1 like
              Last Post PaulMohn  
              Started by TheWhiteDragon, 01-21-2019, 12:44 PM
              4 responses
              544 views
              0 likes
              Last Post PaulMohn  
              Started by GLFX005, Today, 03:23 AM
              0 responses
              3 views
              0 likes
              Last Post GLFX005
              by GLFX005
               
              Started by XXtrader, Yesterday, 11:30 PM
              2 responses
              12 views
              0 likes
              Last Post XXtrader  
              Working...
              X