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

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.

          Attached Files
          Chris L.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Javierw.ok, Today, 04:12 PM
          0 responses
          4 views
          0 likes
          Last Post Javierw.ok  
          Started by timmbbo, Today, 08:59 AM
          2 responses
          10 views
          0 likes
          Last Post bltdavid  
          Started by alifarahani, Today, 09:40 AM
          6 responses
          40 views
          0 likes
          Last Post alifarahani  
          Started by Waxavi, Today, 02:10 AM
          1 response
          18 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by Kaledus, Today, 01:29 PM
          5 responses
          15 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X