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

Draw.TextFixed doesn't respect indicator panel

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

    Draw.TextFixed doesn't respect indicator panel

    Good afternoon,

    I have written an indicator that will use a chart data series as it's input. (I load two data series on the chart. The chart uses one and the indicator uses the other.) I want to draw a ray on the chart and a text box with information in the corner the user determines.

    When I first wrote this, using the following overload, it printed the ray in panel 2. I wanted it to print in panel 1.

    Code:
    Draw.Ray(this, string.Format("HVN"), bar.BarTime, hvnPrice, Time[0], hvnPrice, deltaColor, EvolvingHVNLineStyle, EvolvingHVNWidth);
    Then I tried this overload and that seemed to fix it:
    Code:
    Draw.Ray(this, string.Format("HVN"), bar.BarTime, hvnPrice, Time[0], hvnPrice, deltaColor, EvolvingHVNLineStyle, EvolvingHVNWidth, false);
    The line is printing on the first price panel just like I would like.


    Then I thought I would print some text and again I had trouble with this overload:
    Code:
    Draw.TextFixed( this, "msg", bar.getDelta.ToString(), DeltaPosition, textColor, textFont, outlineColor, outlineColor, DeltaBoxOpacity );
    So I tried this overload:
    Code:
    Draw.TextFixed( this, "msg", bar.getDelta.ToString(), DeltaPosition, textColor, textFont, outlineColor, outlineColor, DeltaBoxOpacity, DashStyleHelper.Solid, 2, false, "" );
    Unlike Dray.Ray, this didn't fix the issue. The text box still prints in the price panel I'd like to collapse and not see.

    So How do I get that text box in Panel 2 to print in Panel 1?

    Click image for larger version  Name:	Screenshot 2020-03-19 13.34.46.png Views:	0 Size:	57.4 KB ID:	1091096
    Last edited by traderpards; 03-19-2020, 01:41 PM.

    #2
    Hello traderpards,

    Thank you for your post.

    What is your setting in State == State.SetDefaults for IsOverlay?

    If this is set to false, the indicator and drawing objects will plot in the secondary panel unless you use overrides to plot them in the main panel. However, if you set this to true, everything in the indicator will automatically be drawn on the primary panel. Here's a link to our help guide regarding IsOverlay:



    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      IsOverlay is set to true... I wish it was set to false. That would be too easy. It also wouldn't explain why Draw.Ray works and Draw.TextFixed does not.

      BTW: DrawOnPricePanel is also set to true.

      What overrides are you talking about? The ones I tried?

      Comment


        #4
        Hi Kate,

        I wrote up a quick little script so you can see what I'm trying to do. OnBarUpdate calls Draw.Ray, which draws the object in the main price panel, which is what I expect. Draw.TextFixed draws the object in panel 1, which is not what I expect. I expect Draw.TextFixed to behave just like Draw.Ray does.

        Steps:
        1) Create a chart with two data series. The first one is a quick data series like an 8 range - I'm using a 2/12 Unirenko. The second one is a 1 minute of the same instrument. It's important you use two data series or it will appear to work.
        2) Load the indicator (attached) but set the input data series to the 1 minute to the chart panel. (Panel 1)

        You should get a chart that looks something like this:

        Click image for larger version

Name:	Screenshot 2020-03-19 17.34.13.png
Views:	449
Size:	47.4 KB
ID:	1091134


        See how the text box is not in the main chart panel? The indicator is using the bottom chart panel as a data series. Draw.Ray puts the ray in the correct panel but Draw.TextFixed does not.

        How do I make both draw objects appear in the main panel.

        Note: the bottom panel is not an indicator panel. It is a data series panel that I would like to collapse so I can't see it (because the information is supposed to be put on the main panel.)

        Thank you!

        Comment


          #5
          Hello traderpards,

          Thank you for your reply.

          Your script as written is working for me, though the line's a bit tough to see since I use a dark skin for the platform:

          Click image for larger version

Name:	2020-03-20_1251.png
Views:	338
Size:	70.8 KB
ID:	1091226

          Try completely removing the indicator from the chart and re-adding it - do you see everything being drawn in panel 1?

          Thanks in advance; I look forward to assisting you further.
          Kate W.NinjaTrader Customer Service

          Comment


            #6
            Hi Kate,

            Thank you for attempting to reproduce this. I suspect the indicator isn't set up right. I see you are using 2 - 1min. charts. That's OK but I'm willing to bet you didn't tie the indicator to the 1 minute chart in Panel 2. I just looked back at my notes and I didn't mean to tell you to attach the indicator to Panel 1. I meant Panel 2. Sorry about that!!

            Would you mind trying again? This time before you click OK (or Apply) can you click the Data Series category, Input Series property button and select the bottom data series. Might be a little more clear to use two different data series so as not to get them mixed up. You can use Range or Renko if you want. I used Unirenko.

            This screenshot shows which one to attach the indicator to:
            Click image for larger version

Name:	Screenshot 2020-03-20 13.44.22.png
Views:	390
Size:	12.8 KB
ID:	1091234

            Also, you'll need to select Panel 1 in the Visual category, Panel Property. (Maybe my brain was on that when I said "Panel 1," I don't know.)

            Thank you!! I'm sorry I wasn't clear! I can guarantee you that if you set it up like this, you will see it.



            Comment


              #7
              Hello traderpards,

              Thank you for your reply.

              That certainly makes things considerably more clear.

              What I would actually recommend here is to make this a Multi-series script. You can add the secondary series directly into the script itself, and then use the secondary series to calculate the values to display, like this:

              Code:
              public class SamplePrint : Indicator
                  {
                      private double bid;
                      private double ask;
                      private double price;
              
                      private SimpleFont textFont;
              
                      protected override void OnStateChange()
                      {
                          if (State == State.SetDefaults)
                          {
                              Description                            = @"Enter the description for your new custom Indicator here.";
                              Name                                = "Sample Print";
                              Calculate                            = Calculate.OnEachTick;
                              IsOverlay                            = true;
                              DisplayInDataBox                    = true;
                              DrawOnPricePanel                    = true;
                              DrawHorizontalGridLines                = true;
                              DrawVerticalGridLines                = true;
                              PaintPriceMarkers                    = true;
                              ScaleJustification                    = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                              //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                              //See Help Guide for additional information.
                              IsSuspendedWhileInactive            = true;
                          }
                          else if (State == State.Historical)
                          {
              
                          }
                          else if (State == State.Configure)
                          {
                              AddDataSeries("YM 06-20", BarsPeriodType.Minute, 30);
                          }
                          else if (State == State.DataLoaded)
                          {
                              textFont = new SimpleFont("Courier", 20) { Bold = true };
                          }
                      }
              
                      protected override void OnBarUpdate()
                      {
                          if (CurrentBar < 20) return;
                          // use the secondary series to calculate this as well
                          if(BarsInProgress == 0)
                              return;
              
                          if( IsFirstTickOfBar == true )
                          {
                              ask = 0;
                              bid = 0;
                          }
              
                          Draw.Ray(this, "Close", Time[2], Close[0], Time[0], Close[0], Brushes.Black, DashStyleHelper.Dash, 2, false );
                      }
              
                      protected override void OnMarketData(MarketDataEventArgs e)
                      {
                          // only check for market data on the secondary series
                          if(BarsInProgress!= 0) 
                              return;
              
                          if (e.MarketDataType == MarketDataType.Last)
                          {
                              price = Instrument.MasterInstrument.RoundToTickSize(e.Price);
              
                              if (price >= ask)
                              {
                                  ask += e.Volume;
                              }
                              if (price <= bid)
                              {
                                  bid += e.Volume;
                              }
              
                              Draw.TextFixed( this, "msg", (ask-bid).ToString(), TextPosition.BottomRight, Brushes.White, textFont, Brushes.Black, Brushes.Black, 25, DashStyleHelper.Solid, 2, false, "" );
              
                          }
                      }
                  }
              This way it's applied to the panel of the primary series and you don't have to worry about trying to draw on the other panel. The downside of this would be that the secondary series is hardcoded here - if you know you're always going to use it with the secondary series being the same instrument as the primary, and you always want the secondary series to be a 30 minute series, you can use this instead for AddDataSeries:

              AddDataSeries(BarsPeriodType.Minute, 30);

              That will get you a 30 minute secondary series of whatever instrument you apply the indicator to. If you want to use a different instrument for the secondary series, you can hardcode it like I have above.

              ​​​​​​​Please let us know if we may be of further assistance to you.
              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Hi Kate,

                I've been coding Ninjascript for nearly 10 years and was aware of this workaround. I was actually kind of hoping you'd either figure out how to get the configuration I need to work or determine the behavior was not "expected" behavior and submit a fix. Really, I should be able to draw the output on any pane I want, wouldn't you agree? (Or at least the chart panel.) I can draw a ray based on the secondary data series on the chart panel so why can't I draw text on the chart panel?

                The reason this workaround isn't feasible is because I need it to be a variable background data series and not have it hard-coded. There are times I will need it to be a 15 minute and a 5 minute and that's accomplished configuring the background data series to his/her liking. And unfortunately Ninjatrader doesn't support variables when State == State.Confiigure.

                Any chance I can talk you into avoiding the workaround route?

                Thanks!

                Comment


                  #9
                  Hello traderpards,

                  Thank you for your reply.

                  There is not a workaround for this, the solution provided above would be the recommended solution in this case.

                  However, I have added votes for you to two existing feature requests; first, to allow drawing tool methods to specify any panel to be drawn in which is being tracked under SFT-962, and another to allow dynamic loading of data series, which is being tracked under SFT-882.

                  As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted in the Release Notes page of the Help Guide.

                  Release Notes — https://ninjatrader.com/support/help...ease_notes.htm

                  Please let us know if we may be of further assistance to you.

                  Kate W.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Trader146, Today, 09:17 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post Trader146  
                  Started by ttrader23, 05-08-2024, 09:04 AM
                  9 responses
                  43 views
                  0 likes
                  Last Post ttrader23  
                  Started by ZeroKuhl, Yesterday, 04:31 PM
                  8 responses
                  46 views
                  0 likes
                  Last Post ZeroKuhl  
                  Started by reynoldsn, Today, 07:04 PM
                  0 responses
                  11 views
                  0 likes
                  Last Post reynoldsn  
                  Started by puapwr, Today, 06:09 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post puapwr
                  by puapwr
                   
                  Working...
                  X