Announcement

Collapse
No announcement yet.

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.

    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.

        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.
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment


                  #9
                  Originally posted by NinjaTrader_ChrisL View Post
                  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.
                  Hi Chris,
                  In 1 chart, I have 2 panels, each showing a different instrument. Unfortunately, there is only 1 chart trader.

                  I wish to select the ATM strategy for each chart from the properties of an indicator loaded on each chart instead of the chart trader.

                  Your code above simply outputs a string. Please advise how do I convert the string type to the type NinjaTrader.NinjaScript.AtmStrategy?

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  571 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  330 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  101 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  548 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  549 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X