• 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.


No announcement yet.

Partner 728x90


How to expose an Array

  • Filter
  • Time
  • Show
Clear All
new posts

    How to expose an Array

    So how do I expose and array value so it does something.
    I do not want to declare an array value to a Var
    I want to extract its text version and have do directly what the text code is.
    In other words say I wrote in an external " Print("I came from a external file");

    I want to bring this in and actually perform.
    For instance code below works but when I try to return it say can not use on bar update.

    I understand it is protected by override void, but then how to expose outside code Snippet into a compiled strategy .

    { // Open the text file using a stream reader.
    // using (StreamReader sr = new StreamReader(path))
    sr = new System.IO.StreamReader(path);

    string line ;

    // Read the stream to a string, and write the string to the console.
    while ((line = sr.ReadLine()) != null) {

    string[] split = line.Split(new char[] {','});

    SetProfitTarget(CalculationMode.Ticks, 14);
    SetStopLoss(CalculationMode.Ticks, 12);

    // return split[0];



    How to Expose an Array Value Part 2

    Explained another way.

    I have a compiled program where every now and then I want to pull custom Snippet via a file.
    I can read the string data and print the data no problem, but how do expose/return it to perform its action.

    Example say I wrote in a text file

    // Begin Snippet

    if (CrossAbove(EMA(3), EMA(21), 1)) EnterLong();

    // End Snippet

    Read it from file, Print it to output window all no problem.
    But when I try to return it, will not work.

    How can an outside Snippet be imported / expose / returned,/ perform action / Execute

    Hope this is clearer now. I do not want to compile a strategy or indicator for small code changes when the main program works fine, So I want to do this externally.via a
    Snippet ,
    just want to add it via a text file and have it perform
    I can print the content now I want it to actually execute and I know console.write does not work as Ninja Trader works with window framework.

    thanks for the help to simple process that I can not figure out.


      Hello nettony,

      Thank you for the post.

      Reflection would need to be used to achieve late binding and to get metadata from other assemblies to execute their methods:

      https://docs.microsoft.com/en-us/dot...pts/reflection - C# Reflection Class

      If you do not want to use reflection, you would need to enter the code from the snippets into your script and decide in the code to run that snippet or not.

      Please let me know if I can assist further.
      Chris L.NinjaTrader Customer Service


        I having issue getting the concept of reflections. I can read strings using stream reader no problem, but say I have stored in the text file a line of code, say I wrote If (a==b){enterlong();}
        I can do this
        sr = new System.IO.StreamReader(path);
        filecontent = sr.ReadToEnd();
        Print (filecontent);

        But I can not do
        return filecontent;
        method.Invoke(filecontent, null);

        So can I get filecontent to be treated as code ?


          Hello nettony,

          Thank you for the reply.

          Assisting with reflection would be beyond the scope of support that I can provide. Using reflection would be considered an advanced topic in C#. This post will remain available for the community to assist. I have also attached a simple example of how reflection would be used to call a print function to help you get started.

          Below is a public link to the System.Reflection.Invoke method.

          Attached Files
          Chris L.NinjaTrader Customer Service


          Latest Posts


          Topics Statistics Last Post
          Started by cutzpr, Today, 05:22 PM
          0 responses
          1 view
          Last Post cutzpr
          by cutzpr
          Started by ATMtrader0001, Today, 01:13 PM
          1 response
          Last Post NinjaTrader_ChelseaB  
          Started by NtFan, Today, 04:18 PM
          0 responses
          Last Post NtFan
          by NtFan
          Started by kaseipds, Today, 01:29 PM
          1 response
          Last Post NinjaTrader_ChelseaB  
          Started by kaseipds, Today, 12:04 PM
          1 response
          Last Post NinjaTrader_ChelseaB