Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with displaying fixed text

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

    Help with displaying fixed text

    Hi i want to display unrealized profit loss in real time but i get this error.

    else if (State == State.Realtime)
    {
    if (Position.MarketPosition != MarketPosition.Flat)
    Print("Open PnL: " + Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]));
    Draw.TextFixed(this, "tag1", Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]), TextPosition.BottomRight);
    }

    ​​

    #2
    Hello tkaboris,

    Can you post the error that you are getting please?

    Comment


      #3
      i am sory
      Click image for larger version

Name:	image.png
Views:	174
Size:	514.3 KB
ID:	1264786

      Comment


        #4
        Hello tkaboris,

        The second error is the relevant error here. The first error lets you know that there is no overload pattern for what you provided meaning you provided the wrong parameter. The second error lets you know what parameter is wrong. You provided a price but it wants a String. You need to add .ToString() to the end of your GetUnrelaizedProfitLoss(...).ToString()

        Comment


          #5
          when i add toString it still shows error that it cant convert from method to string

          Click image for larger version

Name:	image.png
Views:	167
Size:	459.8 KB
ID:	1264796

          Comment


            #6
            Hello tkaboris,

            You left out the parenthesis, in C# you can convert a variable to a string by using ToString()

            Comment


              #7
              Thank you.
              Its telling me that operator > cant be applied to string. we converted it to string but I am trying to change color based on profitloss.. If in plus it will be in green color, if less then < then in red color.

              how do you recommend to go about it? since i cant use toString()...


              if (marketDataUpdate.MarketDataType == MarketDataType.Last)
              {

              if (Position.MarketPosition == MarketPosition.Flat)

              Draw.TextFixed(this, "myTextFixed", "DAILY PNL $" + dailyPnL.ToString(), TextPosition.BottomRight, Brushes.White,
              ChartControl.Properties.LabelFont, Brushes.RoyalBlue, Brushes.RoyalBlue, 35);

              if (Position.MarketPosition != MarketPosition.Flat)
              if(Position.GetUnrealizedProfitLoss(PerformanceUni t.Currency, Close[0]).ToString() > 0){
              Draw.TextFixed(this, "tag1", "OPEN PNL $" + Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]).ToString(), TextPosition.BottomRight);
              }​
              }

              Comment


                #8
                if(Position.GetUnrealizedProfitLoss(PerformanceUni t.Currency, Close[0]).ToString() > 0){
                double ProfitOrLoss = Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]);
                Draw.TextFixed(this, "tag1", "OPEN PNL $" + ProfitOrLoss.ToString(), TextPosition.BottomRight);
                }​​
                eDanny
                NinjaTrader Ecosystem Vendor - Integrity Traders

                Comment


                  #9
                  Originally posted by tkaboris View Post
                  if(Position.GetUnrealizedProfitLoss(PerformanceUni t.Currency, Close[0]).ToString() > 0){
                  You need to study up on some programming basics.

                  Study this tutorial,
                  W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.


                  Then, understand this:
                  In the above tutorial, you can see they show you things like,

                  if (A > B) ...

                  your code is wrong because whenever you specify A and B,
                  they (generally) must be of the same type.

                  That means, A and B are both strings, or both numbers, but using
                  a condition in an if statement when A is a string and B is number,
                  in C# that is wrong, and shows a lack of understanding of the
                  fundamentals of C# programming.

                  This line of code,

                  if (Position.GetUnrealizedProfitLoss(PerformanceUnit. Currency, Close[0]).ToString() > 0) {

                  needs to remove the .ToString().

                  Make sure you understand why.

                  But be careful ...
                  other lines of code may need the ToString(), knowing the difference
                  of when you need ToString() and when you don't sounds like something
                  you need to work on in your education.

                  Don't despair, lots of good tutorials on the internet.


                  Comment


                    #10
                    Originally posted by bltdavid View Post

                    You need to study up on some programming basics.

                    Study this tutorial,
                    W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.


                    Then, understand this:
                    In the above tutorial, you can see they show you things like,

                    if (A > B) ...

                    your code is wrong because whenever you specify A and B,
                    they (generally) must be of the same type.

                    That means, A and B are both strings, or both numbers, but using
                    a condition in an if statement when A is a string and B is number,
                    in C# that is wrong, and shows a lack of understanding of the
                    fundamentals of C# programming.

                    This line of code,

                    if (Position.GetUnrealizedProfitLoss(PerformanceUnit. Currency, Close[0]).ToString() > 0) {

                    needs to remove the .ToString().

                    Make sure you understand why.

                    But be careful ...
                    other lines of code may need the ToString(), knowing the difference
                    of when you need ToString() and when you don't sounds like something
                    you need to work on in your education.

                    Don't despair, lots of good tutorials on the internet.

                    Yes you are right, i removed that toString and got it to work

                    Comment


                      #11
                      I am sorry. one more question

                      Currently for the day I have a positive PNL, trades i took manually or previously with strategy. However when in flat it shows 0, and on my chart trader it shows positive PNL. How can i make sure that it displays what is displayed in chart trader for the day?

                      protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
                      {
                      if (marketDataUpdate.MarketDataType == MarketDataType.Last)
                      {

                      region PNL on the chart
                      NinjaTrader.Gui.Tools.SimpleFont fontNeutral = new NinjaTrader.Gui.Tools.SimpleFont("Verdana", 12) { Size = 20, Bold = true };
                      NinjaTrader.Gui.Tools.SimpleFont fontPositive = new NinjaTrader.Gui.Tools.SimpleFont("Verdana", 12) { Size = 20, Bold = true };
                      NinjaTrader.Gui.Tools.SimpleFont fontNegative = new NinjaTrader.Gui.Tools.SimpleFont("CVerdana", 12) { Size = 20, Bold = true };

                      if (Position.MarketPosition == MarketPosition.Flat)
                      Draw.TextFixed(this, "tag1", "DAILY PNL $ " + dailyPnL.ToString(), TextPosition.BottomRight, Brushes.White,
                      fontNeutral, Brushes.RoyalBlue, Brushes.RoyalBlue, 35);

                      if (Position.MarketPosition != MarketPosition.Flat)
                      if(Position.GetUnrealizedProfitLoss(PerformanceUni t.Currency, Close[0]) >= 0.1){
                      Draw.TextFixed(this, "tag2", "OPEN PNL $ " + Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]).ToString(), TextPosition.BottomRight, Brushes.RoyalBlue,
                      fontPositive, Brushes.RoyalBlue, Brushes.RoyalBlue, 35);
                      }
                      if(Position.GetUnrealizedProfitLoss(PerformanceUni t.Currency, Close[0]) < 0.0){
                      Draw.TextFixed(this, "tag3", "OPEN PNL $ " + Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]).ToString(), TextPosition.BottomRight, Brushes.Red,
                      fontNegative, Brushes.Red, Brushes.Red, 35);
                      }
                      #endregion​
                      }
                      }

                      Comment


                        #12
                        Hello tkaboris,

                        Strategies only observe the trades they make, a strategy won't know about previous instances of the strategy or manual trading. If you are just trying to make a display which shows the account values and not what the strategy sees you can output the account positions pnl value.

                        Comment


                          #13
                          never mind again
                          its this line
                          Account.Get(AccountItem.GrossRealizedProfitLoss, Currency.UsDollar)

                          Comment


                            #14
                            Hi again.
                            With the code above object doesnt get removed and i get other objects on top of each other. When i add remove object it compains that tag1 doesnt existin current context. maybe i dont need to remove objecct at all? I need to make sure taht when switching from positive to negative objects also change and previous object is not displayed..

                            if (Position.MarketPosition == MarketPosition.Flat){
                            Draw.TextFixed(this, "tag1", "DAILY PNL $ " + Account.Get(AccountItem.GrossRealizedProfitLoss, Currency.UsDollar), TextPosition.BottomRight, Brushes.White,
                            fontNeutral, Brushes.RoyalBlue, Brushes.RoyalBlue, 35);
                            RemoveDrawObject(tag1);
                            }

                            Code:
                            #region PNL on the chart
                                            NinjaTrader.Gui.Tools.SimpleFont fontNeutral = new NinjaTrader.Gui.Tools.SimpleFont("Verdana", 12) { Size = 20, Bold = true };
                                            NinjaTrader.Gui.Tools.SimpleFont fontPositive = new NinjaTrader.Gui.Tools.SimpleFont("Verdana", 12) { Size = 20, Bold = true };
                                            NinjaTrader.Gui.Tools.SimpleFont fontNegative = new NinjaTrader.Gui.Tools.SimpleFont("CVerdana", 12) { Size = 20, Bold = true };
                            
                                            if (Position.MarketPosition == MarketPosition.Flat){                    
                                                Draw.TextFixed(this, "tag1", "DAILY PNL $ " + Account.Get(AccountItem.GrossRealizedProfitLoss, Currency.UsDollar), TextPosition.BottomRight, Brushes.White,
                                                  fontNeutral, Brushes.RoyalBlue, Brushes.RoyalBlue, 35);
                                                RemoveDrawObject(tag1);
                                            }
                                            else if (Position.MarketPosition != MarketPosition.Flat){
                                                if(Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]) >= 0.1){
                            
                                                Draw.TextFixed(this, "tag2", "OPEN PNL $ " + Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]).ToString(), TextPosition.BottomRight, Brushes.RoyalBlue,
                                                  fontPositive, Brushes.RoyalBlue, Brushes.RoyalBlue, 35);
                                                }
                                            }
                                            else if(Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]) < 0.0){
                                                Draw.TextFixed(this, "tag3", "OPEN PNL $ " + Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]).ToString(), TextPosition.BottomRight, Brushes.Red,
                                                  fontNegative, Brushes.Red, Brushes.Red, 35);
                                                }
                                            #endregion​

                            Comment


                              #15
                              Hello tkaboris,

                              If you are using the same corner you should have only 1 tag being used, you have 3 different tags meaning you could have potentially 3 different objects in the corner. You just need to use 1 tag, calling the draw method again will update the existing object.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Yesterday, 05:17 AM
                              0 responses
                              54 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              130 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              72 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              44 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              49 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X