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

Type casts and errors

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

    Type casts and errors

    I am having an issue with an object error and I can't figure out why

    public class FileNameList : TypeConverter
    {

    public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
    {
    if (context == null)
    {
    return null;
    }
    ArrayList fileList = new ArrayList();
    string[] dirs = Directory.GetFiles(Path.Combine(Environment.Expand EnvironmentVariables("%userprofile%"), "Documents\\myFiles\\"));
    string[] separatingChars = {Path.Combine(Environment.ExpandEnvironmentVariabl es("%userprofile%"), "Documents\\myFiles\\"), ".csv" };

    fileList.Add("Choose");
    foreach (string dir in dirs)
    {
    string[] words = dir.Split(separatingChars, System.StringSplitOptions.RemoveEmptyEntries);
    fileList.Add(words[0]);

    }

    return new TypeConverter.StandardValuesCollection(fileList);
    }

    public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
    {
    return true;
    }
    }

    private string sTradeFiles = "";
    [GridCategory("Parameters")]
    [TypeConverter(typeof(FileNameList))]
    public string TradeFiles
    {get;set;}


    THIS WORKS GOOD

    NOW LOOK A THIS

    public class ResFileNameList : TypeConverter
    {

    public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
    {
    if (context == null)
    {
    return null;
    }
    ArrayList resFileList = new ArrayList();
    string[] dirs = Directory.GetFiles(Path.Combine(Environment.Expand EnvironmentVariables("%userprofile%"), "Documents\\myFiles\\"));
    string[] separatingChars = {Path.Combine(Environment.ExpandEnvironmentVariabl es("%userprofile%"), "Documents\\myFiles\\"), ".csv" };

    resFileList.Add("Choose");
    foreach (string dir in dirs)
    {
    string[] words = dir.Split(separatingChars, System.StringSplitOptions.RemoveEmptyEntries);
    resFileList.Add(words[0]);

    }

    return new TypeConverter.StandardValuesCollection(resFileList );
    }

    public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
    {
    return true;
    }
    }


    private string sResTradeFiles = "";
    [GridCategory("Parameters")]
    [TypeConverter(typeof(ResFileNameList))]
    public string ResTradeFiles
    {get;set;}



    THIS doesn't work. it is doing the same thing. I initially tried a different file and I had this error so I decided to search the same files and it still doesn't work.

    I created a dropdown lists of files but it just won't work if i have 2 typecasts

    #2
    Hello ballboy11,

    Have you started with the SampleIndicatorTypeConverter and adapted this to your needs?


    What are the exact errors you are getting?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      When I add the second type cast my indicator will not work but it does compile

      Comment


        #4
        Hello ballboy11,

        Are you getting an error message?

        If so, what is the exact full error message?

        What line is causing the error? (Use prints to find the line of code that is causing the error)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Object reference not set to an instance of an object.

          that is in the trace but Which object


          private string sResTradeFiles = "";
          [GridCategory("Parameters")]
          [TypeConverter(typeof(ResFileNameList))]
          public string ResTradeFiles
          {get;set;}

          when I activate the parameter it gives the error

          Comment


            #6
            It looks like the typecast is not set

            Comment


              #7
              Hello ballboy11,

              If the error occurs when the value of ResTradeFiles is set, the error is likely in the custom TypeConverter code.

              Have you added prints to find which line in the TypeConverter code is causing the error?

              The error indicates there is a variable with a null value being called.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                I am close to my solution what I found out it was GridCatagory


                private string sTradeFiles = "";
                [GridCategory("Parameters")]
                [TypeConverter(typeof(FileNameList))]
                public string TradeFiles
                {get;set;}


                //private string sTradeFiles = "";
                [TypeConverter(typeof(SoundManagerConverter))]
                public string myFiles
                {get;set;}

                //private string sTradeFiles = "";
                //[GridCategory("Parameters")]
                [TypeConverter(typeof(ResNameList))]
                public string ResTradeFiles
                {get;set;}


                Grid Category works on the first one but i add grid categories to any others it will give me an object error for some reason if I don't add it It groups in Misc. Do you know why it won't allow grid category on the 2nd or third
                Last edited by ballboy11; 11-20-2017, 11:03 AM.

                Comment


                  #9
                  Hello ballboy11,

                  As a heads up, custom type converters are not supported for NinjaTrader 7 and are outside of the realm of NinjaTrader Support.

                  This thread will remain open for any community members that would like to assist.

                  You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.


                  That said, there is a working example I can share that uses a TypeConverter (and also uses the [GridCategory()] attribute tag.


                  When you mention "I created a dropdown lists of files but it just won't work if i have 2 typecasts", are you saying that you are trying to cast the object twice to two different object types?

                  Are you saying you are using two different type converters?
                  Attached Files
                  Last edited by NinjaTrader_ChelseaB; 11-21-2017, 08:19 AM.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks the sound one works
                    I actually deleted my code and started from scratch.
                    I looked at the code comparison and it is the same. I think when the indicator was created it was buggy. 2 days down the drain but thank you.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by xiinteractive, 04-09-2024, 08:08 AM
                    2 responses
                    10 views
                    0 likes
                    Last Post xiinteractive  
                    Started by Irukandji, Today, 09:34 AM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by RubenCazorla, Today, 09:07 AM
                    1 response
                    5 views
                    0 likes
                    Last Post RubenCazorla  
                    Started by TraderBCL, Today, 04:38 AM
                    3 responses
                    25 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by WeyldFalcon, 08-07-2020, 06:13 AM
                    11 responses
                    1,423 views
                    0 likes
                    Last Post jculp
                    by jculp
                     
                    Working...
                    X