• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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?
    https://ninjatrader.com/support/foru...ad.php?t=97919

    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, 10: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, 07: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 akuntysh, Today, 09:21 PM
                    0 responses
                    1 view
                    0 likes
                    Last Post akuntysh  
                    Started by goldfly, 08-27-2007, 07:05 PM
                    12 responses
                    11,506 views
                    0 likes
                    Last Post nkhoi
                    by nkhoi
                     
                    Started by jrm999, Today, 07:44 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post jrm999
                    by jrm999
                     
                    Started by Iargo, Today, 05:53 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post Iargo
                    by Iargo
                     
                    Started by kadan, Today, 05:24 PM
                    1 response
                    5 views
                    0 likes
                    Last Post kadan
                    by kadan
                     
                    Working...
                    X