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

Creating Properties, with drop-down list of all available ATM strategies

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

    Creating Properties, with drop-down list of all available ATM strategies

    I am developing a strategy in NinjaScript NT8, and would like to have "ATM Strategy" as a property. That field would contains a drop-down list showing "Active" and all my available ATM strategies. The thought is I would use this value when executing an order basing it on either the current active strategy in the Chart Trader, or the ATM strategy chosen from the drop-down list.

    In addition, is there a technique to get the "Active" ATM strategy, i.e., the one currently displayed under ATM Strategy in the Chart Trader?

    Do you have code samples to achieve this?

    #2
    Hello epete,

    Thank you for your post.

    I have attached an example that demonstrates how to create a custom ATM selector in your script. To import the script, go to Tools>Import.

    First, you add a TypeConverter class within the Strategy class that scans the Documents\NinjaTrader 8\templates\AtmStrategy directory.

    Code:
    public class FriendlyAtmConverter : TypeConverter
    {  
        // Set the values to appear in the combo box
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            List<string> values = new List<string>();
            string[] files = System.IO.Directory.GetFiles(System.IO.Path.Combine(NinjaTrader.Core.Globals.UserDataDir, "templates", "AtmStrategy"), "*.xml");  
    
            foreach(string atm in files)
            {
                values.Add(System.IO.Path.GetFileNameWithoutExtension(atm));
                NinjaTrader.Code.Output.Process(System.IO.Path.GetFileNameWithoutExtension(atm), PrintTo.OutputTab1);
            }
            return new StandardValuesCollection(values);
        }
    
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            return value.ToString();
        }
    
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            return value;
        }
    
        // required interface members needed to compile
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        { return true; }
    
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        { return true; }
    
        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        { return true; }
    
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        { return true; }}
    Then use that class as a property in the script:

    Code:
    [TypeConverter(typeof(FriendlyAtmConverter))] // Converts the found ATM template file names to string values
    [PropertyEditor("NinjaTrader.Gui.Tools.StringStandardValuesEditorKey")] // Create the combo box on the property grid
    [Display(Name = "Atm Strategy", Order = 1, GroupName = "AtmStrategy")]
    public string AtmStrategy
    { get; set; }
    It looks like there is currently not a way to access the active ATM strategy from within a script. I will need to look into this further.

    Please let me know if I can assist any further.
    Attached Files
    Last edited by NinjaTrader_ChrisL; 04-08-2019, 02:21 PM.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      I know this has been out here a while now, hopefully this is still open. How could this be made into a standalone class so that it could be called from any strategy so that we don't have to replicate the code over and over into each strategy in which we want to use this capability?

      Comment


        #4
        Hello EminiTrader, thanks for your question.

        There could be a few ways to do this. One way that works is to put it in its own .cs file within the Addons folder, and include it as an Addon.

        Code:
        //using statements here
        
        namespace NinjaTrader.NinjaScript.Addons
        {
           //Paste FriendlyAtmConverter class here
        }
        then, in the script that needs it:

        Code:
        using NinjaTrader.NinjaScript.Addons;
        
        [TypeConverter(typeof(FriendlyAtmConverter))] // Converts the found ATM template file names to string values
        [PropertyEditor("NinjaTrader.Gui.Tools.StringStanda rdValuesEditorKey")] // Create the combo box on the property grid
        [Display(Name = "Atm Strategy", Order = 1, GroupName = "AtmStrategy")]
        public string AtmStrategy
        { get; set; }
        Please let me know if I can assist any further.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Thanks Chris!! Just what I was looking for.

          Comment


            #6
            Is this still currently best way to set atm strategy into code? Or is there way to use the selection from chart trader while script is running now? THx

            Comment


              #7
              Yes, you can see which ATM is selected in chart trader. Search the forum - there is already a code example of how to do this.

              As a start you could begin with this snippet: https://forum.ninjatrader.com/forum/...s-not-template
              Bruce DeVault
              QuantKey Trading Vendor Services
              NinjaTrader Ecosystem Vendor - QuantKey

              Comment


                #8
                Hello metical1,

                Thanks for your notes.

                Yes, this would be the best approach for seeing which ATM Strategy template is selected in Chart Trader.

                QuantKey_Bruce is correct with the information they provided.

                Please see the forum thread that QuantKey_Bruce linked in post # 7 and please see the sample code NinjaTrader_ChrisL shared on post # 2 of this forum thread.
                Brandon H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by algospoke, Yesterday, 06:40 PM
                2 responses
                23 views
                0 likes
                Last Post algospoke  
                Started by ghoul, Today, 06:02 PM
                3 responses
                14 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                45 views
                0 likes
                Last Post jeronymite  
                Started by Barry Milan, Yesterday, 10:35 PM
                7 responses
                21 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by AttiM, 02-14-2024, 05:20 PM
                10 responses
                181 views
                0 likes
                Last Post jeronymite  
                Working...
                X