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

Print to Screen VS Output Window

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

    Print to Screen VS Output Window

    Hi,
    I've searched the forum and guide and can't seem to find the answer to this one.
    I can print all my variable values to the the Output Window. Is there a way to have them print to the screen? I want to keep an eye on my variables output without having to have an Output Window open. I've looked under Draw.Text but don't see a way to print variables that are getting updated each bar to the screen. And I don't want them to scroll like they do in the Output Window. Just see the Text of the variable and what the value is. Maybe an example of a Strategy or Indicator that prints variable to the screen so I can see how they do it?
    Thanks.

    #2
    Hello JoeF1953,

    Draw.Text would be how to do that. If you wanted to update the text you need to use the same Tag when drawing the new text.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Jesse, I read through the entire Draw.Text section and I don't see any examples that lets me draw anything BUT text. I don't see where I can insert a variable to print. Can you point me to an example? For example, lets say I want to print the PnL to the screen. This is a variable that changes after each trade. The text portion would stay the same ..."PnL" but the value will change. Where do I put that variable in the Draw.Text code?

      Comment


        #4
        Jesse, I got this to work to print the Pnl to the screen:

        Draw.TextFixed(this, "Tag1", "Real PnL" + RealPnL,TextPosition.Center, Brushes.Yellow, myFont, Brushes.Yellow, null, 1);

        Now, I want to add another line underneath that one to print another variable. I saw an example where they used "See Here \nSomeText" which moved the SomeText to the next line. I can't get that to work since + RealPnL is after the text and I get errors when trying to add more text with another variable on a new line after that

        I tried this:
        Draw.TextFixed(this, "Tag1", "Real PnL" + RealPnL,TextPosition.Center, Brushes.Yellow, myFont, Brushes.Yellow, null, 1);
        Draw.TextFixed(this, "Tag2", "PnLTarget" + PnLTarget,TextPosition.Center, Brushes.Yellow, myFont, Brushes.Yellow, null, 1);

        That just printed right over the top of the Real PnL line.

        How can I add variables as different lines and keep them in the same box? Is it even possible to keep them in the same box as different lines?
        Thanks

        Comment


          #5
          Hello JoeF1953,

          Draw text is only used for text and you can use a string variable if you wanted the text its drawing to be variable. The samples don't use variables as that would make them more confusing. You can just use a string variable in place of whatever the sample is showing as the text it draws.

          To do multi line text you would need to use the \n however that is not going to be very accurate in all cases. Multi line text would require using two Text(not TextFixed) objects and then positioning them how you wanted. TextFixed cannot do that, you cannot use more than one per corner and offset them.

          To do a similar task to TextFixed you could use OnRender to draw custom text instead of using drawing objects. You can find an example of that in the SampleCustomRender indicator that comes with the platform.

          I look forward to being of further assistance.




          JesseNinjaTrader Customer Service

          Comment


            #6
            Jesse, I have it "kind of" working. What I really need is the Y value at the center of the chart. I used OnRender to get that Y value. However, under OnBarUpdate it doesn't recognize it and only returns a value of 0. And I can't get the chart's Y value under OnBarUpdate, unless you know how to do it. Is there any way to pass the Y value obtained under OnRender to OnBarUpdate? (I looked at the OnRender sample and I really don't want to mess with all that.) Gets too complicated for the simple thing I want to do. Thanks....

            Comment


              #7
              Hello JoeF1953,

              The center of the Y would be the Y plus Height divided by 2.


              Code:
              (ChartPanel.Y + ChartPanel.H) /2
              You wouldn't use any X/Y values from OnBarUpdate. If you needed to render something you calculate in OnBarUpdate you would need to use both OnRender and OnBarUpdate.

              You could use a variable to store any data needed for example:

              Code:
              private double aValue; 
              
              protected override void OnBarUpdate()
              {
                  aValue = Close[0]; 
              }
              
              protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
              {
                  // now you can use aValue in your render logic which would represent whatever the last price OnBarUpdate set was
              }
              OnRender is the rendering loop meaning that its called very frequently and not specifically in order with the other NinjaScript events like OnBarUpdate. Anything that needs rendered needs saved as a variable or accessed in a specific way because its out of the event context.


              JesseNinjaTrader Customer Service

              Comment


                #8
                Jesse, Maybe I'm not being clear. I know how to get the center of the chart Y value under OnRender. The ONLY thing I want to use OnRender for is getting this value. I want the Draw.Text to execute under OnBarUpdate since my Draw.Text code doesn't work under OnRender but works fine under OnBarUpdate. I don't want to mess with OnRender. My question was, Is there any way to pass the Y value I got in OnRender to OnBarUpdate? If not, then perhaps theres a way to get the center of the chart Y value under OnBarUpdate? Thanks

                Comment


                  #9
                  Jesse, I decided to use some code I pieced together from Jim's DrawTextFixed.zip example. I'm just having it print to the Top Left on the screen since those locations are already "built in". So forget about Y. I appreciate your suggestions and I've learned a few things from this excursion into the unknown. I'm posting the code in case anyone else out there is having the same problem I was. Everything works perfectly and does exactly what I need it to do. Thanks again!!! Here's the code:

                  public class KeyReversal: Strategy
                  {
                  NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = 30, Bold = true };


                  protected override void OnBarUpdate()
                  {

                  Draw.TextFixed (this, "Line1", "PnL " + RealPnL, TextPosition.TopLeft, Brushes.Lime, myFont, null, null, 1);
                  Draw.TextFixed (this, "Line2", "\nPnL Target " + PnLTarget, TextPosition.TopLeft, Brushes.Lime, myFont, null, null, 1);
                  Draw.TextFixed (this, "Line3", "\n\nContracts To Goal " + ContractsToGoal , TextPosition.TopLeft, Brushes.Lime, myFont, null, null, 1);
                  Draw.TextFixed (this, "Line4", "\n\n\nContractsToTrade " + ContractsToTrade, TextPosition.TopLeft, Brushes.Lime, myFont,null, null, 1);

                  }

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by MacDad, 02-25-2024, 11:48 PM
                  7 responses
                  158 views
                  0 likes
                  Last Post loganjarosz123  
                  Started by Belfortbucks, Today, 09:29 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post Belfortbucks  
                  Started by zstheorist, Today, 07:52 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post zstheorist  
                  Started by pmachiraju, 11-01-2023, 04:46 AM
                  8 responses
                  151 views
                  0 likes
                  Last Post rehmans
                  by rehmans
                   
                  Started by mattbsea, Today, 05:44 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post mattbsea  
                  Working...
                  X