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

Font type and size on Draw.Text not working

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

    Font type and size on Draw.Text not working

    Hi,
    I am trying to add the SimpleFont font type and size to my Draw.Text line where I call the current bar length. Unfortunately I am getting the error message: No overloaded method Text uses this number of arguments (11) (CS1501).
    I have tried various approaches but I can´t get it work.
    I have used part of the SampleChangeFont Inidcator and included it in my code. There the font type etc. works, but not on my Draw.Text line.

    Code:
        public class EMABarLength : Indicator
    {
            // private NinjaTrader.Gui.Tools.SimpleFont myFont;
    
            private SimpleFont    largeFont;        // This variable holds the large font.  
    
            [Range(1, int.MaxValue), NinjaScriptProperty]
            public int TextOffset { get; set; }
    
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
            Name = "EMA Bar Length";
            IsOverlay = true;
            TextOffset = 10;
            largeFont = new Gui.Tools.SimpleFont("Arial", 12);
            Calculate = Calculate.OnPriceChange;
    
    
        }
        //    myFont = new NinjaTrader.Gui.Tools.SimpleFont("Arial", 12) { Size = 10, Bold = false };
        //    Instrument.MasterInstrument.PriceChange += OnPriceChange;
        }
            protected override void OnBarUpdate()
        {
            if (CurrentBar == Bars.Count -1)
            {
    
            Draw.Text(this, "BarLength" + CurrentBar, Math.Round((High[0] - Low[0]) / TickSize).ToString(), 0, Low[0] - (TickSize * TextOffset),  Brushes.Gray);
            }    
    
    
            if (CurrentBar < Bars.Count - 5) return;
            // Draw.Text(this, "BarLength" + CurrentBar, Math.Round((High[0] - Low[0]) / TickSize).ToString(), 0, Low[0] - (TickSize * TextOffset),  0, Brushes.LightSeaGreen, myFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 100);
            // Draw.Text(this, "highText", true, High[0].ToString(), 1, High[0] + 2 * TickSize, 0, Brushes.Green, largeFont, TextAlignment.Justify, Brushes.Transparent, Brushes.Transparent, 0);
            Draw.Text(this, "BarLength" + CurrentBar, Math.Round((High[0] - Low[0]) / TickSize).ToString(), 0, Low[0] - (TickSize * TextOffset),  Brushes.Gray, largeFont, TextAlignment.Justify, Brushes.Transparent, Brushes.Transparent, 0);
    
            }
        }
    }​
    Hope anybody can help me get this line right?

    Thanks!
    Peter

    #2
    Hello cyberpete76,

    The error means that the number of parameters being used are incorrect.

    You can see a sample of using a SimpleFont with the correct number of parameters here:



    All of the possible ways that you can use Draw.Text can be found here:

    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you Jesse,
      I fixed the error and the indicator is now working as planned.
      But now I am running into another issue when trying to make the Font user definable in the indicator Properties. My code looks like this but under Properties I get only the TextOffset, not the Font properties for "smallFont" nor "largeFont":

      Code:
      namespace NinjaTrader.NinjaScript.Indicators
      {
          public class EMABarLength : Indicator
      {
      
              private SimpleFont    largeFont;        // This variable holds the large font.
              private SimpleFont    smallFont;        // This variable holds the small font.
              private Bars.Count  BarsCount;
      
              [Range(1, int.MaxValue), NinjaScriptProperty]
              public int TextOffset { get; set; }
      
          protected override void OnStateChange()
          {
              if (State == State.SetDefaults)
              {
              Name = "EMA Bar Length";
              BarsCount = 5;
              largeFont = new Gui.Tools.SimpleFont("Arial", 12);
              smallFont = new Gui.Tools.SimpleFont("Arial", 10);    
              TextOffset = 30;
              IsOverlay = true;
              Calculate = Calculate.OnPriceChange;
      
      
              }
                  else if(State == State.Terminated)
                  {
                  largeFont = null;
                  smallFont = null;
                  }
              }
      
              protected override void OnBarUpdate()
              {
      
              string barLengthInTicks = Math.Round((High[0] - Low[0]) / TickSize).ToString();
      
              if (CurrentBar == Bars.Count -1)
              {
      
              // PREVIOUS VERSION w/o SimpleFont: Draw.Text(this, "BarLength" + CurrentBar, Math.Round((High[0] - Low[0]) / TickSize).ToString(), 0, Low[0] - (TickSize * TextOffset),  Brushes.Gray);
              Draw.Text(this, "BarLength" + CurrentBar, false, barLengthInTicks, 0, Low[0] - (TickSize * TextOffset), 0, Brushes.DarkBlue, largeFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
              }    
      
      
              // if (CurrentBar < Bars.Count - 5) return;
              // version w/o SimpleFont: Draw.Text(this, "BarLength" + CurrentBar, barLengthInTicks, 0, Low[0] - (TickSize * TextOffset), Brushes.Gray);
              if (CurrentBar < BarsCount) return;
              Draw.Text(this, "BarLength" + CurrentBar, false, barLengthInTicks, 0, Low[0] - (TickSize * TextOffset), 0, Brushes.LightSlateGray, smallFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
      
      
              }
          }
      }​
      In the example "SampleChangeFont" indicator it works and I used exactly the same logic in my code. But in my indicator it doesn´t work.
      Hope you can help.
      Thanks
      P.

      Comment


        #4
        Hello cyberpete76,

        You need a public property to make user inputs. You can see an example of doing that with a simplefont here:

        https://ninjatrader.com/support/help...oom_highlights ub=simplefont
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by dcriador, Today, 01:43 AM
        1 response
        5 views
        0 likes
        Last Post dcriador  
        Started by louiseruch, Today, 01:11 AM
        0 responses
        1 view
        0 likes
        Last Post louiseruch  
        Started by kujista, Today, 12:39 AM
        0 responses
        5 views
        0 likes
        Last Post kujista
        by kujista
         
        Started by tonynt, 05-21-2019, 06:27 AM
        11 responses
        536 views
        1 like
        Last Post NinjaTrader_Jason  
        Started by fitspressotablettry, Today, 12:36 AM
        0 responses
        1 view
        0 likes
        Last Post fitspressotablettry  
        Working...
        X