Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with displaying fixed text

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

    #16
    ok but it still says tag1 doesnt exist in current context. i have all this code insdie OnMarketData.

    Comment


      #17
      Ok i removed remove object and it probably should work

      Comment


        #18
        Hello tkaboris,

        You need to surround strings with quotes in C#. "tag1".

        We highly suggest using external C# learning resources if you plan on doing manual coding as that will greatly help with small hiccups like forgetting quotes around a string.

        As a side note you don't need to use RemoveDrawObject if you are updating the text, you just call the method to draw the text again with the same tag. RemoveDrawObject is only used to permanently remove an object so its no longer displayed and is not used when updating an objects text or appearance.

        Comment


          #19
          ok. thank you
          I dont understand what I do wrong but when in positive it diplays correct text, however when psition is in negative it doenst display correct ammount, nor ammount nor color. I have attached code before. is it something special to display negative number?

          Code:
          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("Verdana", 12) { Size = 20, Bold = true };
          
                          if (Position.MarketPosition != MarketPosition.Flat){
                              if(Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]) >= 0.1){
          
                              Draw.TextFixed(this, "tag1", "OPEN PNL $ " + Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]).ToString(), TextPosition.BottomRight, Brushes.RoyalBlue,
                                fontPositive, Brushes.RoyalBlue, Brushes.RoyalBlue, 0);
                              }
                          }
                          else if (Position.MarketPosition != MarketPosition.Flat){
                              if (Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]) <= 0.0){
                              Draw.TextFixed(this, "tag1", "OPEN PNL $ " + Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]).ToString(), TextPosition.BottomRight, Brushes.Red,
                                fontNegative, Brushes.Red, Brushes.Red, 0);
                              }
                      }
                          else if (Position.MarketPosition == MarketPosition.Flat){                    
                              Draw.TextFixed(this, "tag1", "DAILY PNL $ " + Account.Get(AccountItem.GrossRealizedProfitLoss, Currency.UsDollar), TextPosition.BottomRight, Brushes.White,
                                fontNeutral, Brushes.White, Brushes.White, 0);
                          }
          
          
          
                          #endregion​
          }}

          Click image for larger version

Name:	image.png
Views:	103
Size:	148.7 KB
ID:	1264872

          Comment


            #20
            Never mind I had to move th closing bracket to the end of the second condition. Thank you

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            73 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            39 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            63 views
            2 likes
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            63 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            53 views
            0 likes
            Last Post CarlTrading  
            Working...
            X