• 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

How to expose an Array

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


    try
    { // 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];

    Print(split[0]);


    }

    #2
    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.

    Comment


      #3
      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

      Comment


        #4
        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;
        nor
        method.Invoke(filecontent, null);

        So can I get filecontent to be treated as code ?

        Comment


          #5
          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.

          https://docs.microsoft.com/en-us/dot...ramework-4.7.2
          Attached Files
          Chris L.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by saltminer, Today, 05:19 PM
          0 responses
          3 views
          0 likes
          Last Post saltminer  
          Started by martyn73, Today, 04:18 PM
          0 responses
          2 views
          0 likes
          Last Post martyn73  
          Started by aprendiz, Today, 03:42 PM
          0 responses
          2 views
          0 likes
          Last Post aprendiz  
          Started by 1001111, Today, 09:10 AM
          1 response
          18 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Started by usero86, Today, 06:02 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Working...
          X