Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Text in a Textbox with Hyperlink

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

    Text in a Textbox with Hyperlink

    Hi There,

    Is there any sample for a strategy or indicator that shows how to create a text box which exposes a hypertext(html link).
    The idea is to give a link in the text box which is the guide for the strategy/indicator.

    #2


    In order to make a hyperlink you would need to manually code the strategy, this would not be an option when using the builder. To do this you would have to create new PropertyEditor in the addon folder, this is the code to do that.

    Code:
    namespace NinjaTrader.NinjaScript.AddOns
    {
    public class HyperLinkAddon : PropertyEditor
    {
    public HyperLinkAddon()
    {
    InlineTemplate = CreateTemplate();
    }
    
    DataTemplate CreateTemplate()
    {
    const string xamlTemplate = @"
    <DataTemplate >
    <Grid>
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width=""30""/>
    <ColumnDefinition Width=""*""/>
    </Grid.ColumnDefinitions>
    
    <TextBlock>
    <Hyperlink NavigateUri=""[URL="http://www.google.com%22%22/"]http://www.google.com""[/URL]
    Command =""pg:PropertyEditorCommands.ShowDialogEditor""
    CommandParameter=""{Binding}"">
    Click here
    </Hyperlink>
    </TextBlock>
    
    
    </Grid>
    </DataTemplate>
    ";
    
    
    ParserContext context = new ParserContext();
    context.XmlnsDictionary.Add("", "[URL="http://schemas.microsoft.com/winfx/2006/xaml/presentation%22"]http://schemas.microsoft.com/winfx/2006/xaml/presentation"[/URL]);
    context.XmlnsDictionary.Add("x", "[URL="http://schemas.microsoft.com/winfx/2006/xaml%22"]http://schemas.microsoft.com/winfx/2006/xaml"[/URL]);
    context.XmlnsDictionary.Add("pg", "[URL="http://schemas.denisvuyka.wordpress.com/wpfpropertygrid%22"]http://schemas.denisvuyka.wordpress.com/wpfpropertygrid"[/URL]);
    DataTemplate template = (DataTemplate)XamlReader.Parse(xamlTemplate, context);
    return template;
    }
    
    public override void ClearValue(PropertyItemValue propertyValue, IInputElement commandSource)
    {
    if (propertyValue == null || propertyValue.IsReadOnly)
    {
    return;
    }
    propertyValue.StringValue = string.Empty;
    }
    
    public override void ShowDialog(PropertyItemValue propertyValue, IInputElement commandSource)
    {
    PropertyGrid propGrid = commandSource as PropertyGrid;
    if (propGrid == null) return;
    
    System.Diagnostics.Process.Start("[URL="http://google.com%22/"]http://google.com"[/URL]);
    
    propertyValue.StringValue = "success"; // change this string and compile, the ui does not see this change
    propGrid.DoReload();
    propGrid.RaiseEvent(new PropertyValueChangedEventArgs(PropertyGrid.Propert yValueChangedEvent, propertyValue.ParentProperty, ""));
    }
    }
    }​

    You can then use the following code from a script to have a hyper link in its properties

    Code:
    [Display(Name = "TestProperty", GroupName = "Test")]
    [PropertyEditor("NinjaTrader.NinjaScript.AddOns.Hyp erLinkAddon")]
    public string TestProperty { get; set; }​

    Comment


      #3
      Thanks Jesse. However Above Addon Code is giving compilation error. It will be a huge favor if you could create a working example for this.

      Comment


        #4
        Originally posted by FossilBlade View Post
        Thanks Jesse. However Above Addon Code is giving compilation error. It will be a huge favor if you could create a working example for this.
        This is what I use for all of my indicators providing a link to my website.

        Code:
        [XmlIgnore]
        [PropertyEditor("NinjaTrader.Gui.Tools.UrlEditor")]
        [Display(Name = "Some property", GroupName = "Some group...", Order = 1)]
        public Uri InfoLink
        {
        get { return infoLink; }
        set { }
        }
        private readonly Uri infoLink = new Uri(@"https://ninjatrader.com");
        ​
        Last edited by StevenL; 09-30-2024, 07:51 PM.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        50 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X