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

Custom share service

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

    Custom share service

    Hi,
    I am trying to create a basic share service that is just sharing the text (no auth or usernames, etc) of an alert to standard output (instead of twitter,etc). I'm trying to use the existing shares to go by, but they are too complex for me (non programmer) to compare with. Can anyone show me how to do that?
    TIA,
    JA

    EDIT: I may have been running into Windows permission problem, so have to figure out how to handle that first.
    Last edited by JAtrades; 08-07-2019, 07:13 AM.

    #2
    Hello JAtrades, thanks for your post.

    If you just want to print data to the output window, use the Print method in a NinjaScript indicator or a strategy. It will require you to know NinjaScript to do this, for a comprehensive intro to NinjaScript, see this forum post. NinjaScript is a C# framework, so familiarizing yourself with C# and object-oriented programming is imperative for learning NinjaScript. Otherwise, an Alert can be created and you can use the condition builder to play a sound, show a pop up window, etc.

    Kind regards.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chris,

      Does Print method work with the alert? How about and Alert to send message output to an external process - printing would be fine?

      I'm actually trying to do more of what I described in the OP. In this case I am using a python script to process the shared message text. I believe the problem may lie in my python being installed for a single user and NT not, causing permission issue.

      As far as the NT code, how does this look to you?:

      namespace NinjaTrader.NinjaScript.ShareServices
      {
      public class MyShare : ShareService
      {
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"text alert";
      Name = "MyShare";
      //UseOAuth = false;
      IsConfigured = true;
      }
      //else if (State == State.Configure)
      {
      }
      }

      public override async Task OnShare(string text, string imgFilePath)
      {

      string python = @"C:\Program Files path to python.exe";
      string script_path = @"NT_alert.py";
      string working_dir = @"C:\Program Files (x86)\NinjaTrader 8\bin64";

      ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(python);


      myProcessStartInfo.UseShellExecute = false;
      myProcessStartInfo.RedirectStandardOutput = true;
      myProcessStartInfo.ErrorDialog = true;
      myProcessStartInfo.Arguments = script_path + "test " + text;
      myProcessStartInfo.WorkingDirectory = working_dir;

      Process myProcess = new Process();

      myProcess.StartInfo = myProcessStartInfo;

      myProcess.Start();

      StreamWriter writer = myProcess.StandardInput;

      }
      }
      }


      Thanks,

      Jon
      Last edited by JAtrades; 08-07-2019, 09:13 AM.

      Comment


        #4
        Sorry if this isn't the best way to share code - I noticed I lost indents.... I'm new here ;-)

        Comment


          #5
          Hello Jon, thanks for your reply.

          What specific Windows permission are you running into? Does the behavior change if you run NinjaTrader as Administrator?
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            That is only a guess at this point. I am going to try to get the above custom share code to do anything else, like save the alert to text file. Any input would be appreciated.

            Comment


              #7
              Hi JAtrades,

              I am not very familiar with Python, it would go beyond the scope of support I could provide to get that working. If you can gather any information on what happens when the share service initiates OnShare we could look at that together. Using the Print statement could also prove invaluable for debugging this.
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                Chris,

                I would like to create a custom share (already started) and instead of it printing an alert to twitter, I would like it to print to a text file or a console window on a windows pc. Any ideas how to do that?

                Thanks,

                Jon
                Last edited by JAtrades; 08-08-2019, 05:15 AM.

                Comment


                  #9
                  Hello JATrades,

                  Chris is currently out of the office.

                  The Print method will output to the NinjaScript Output window. You can also use a StreamWriter to write to a file. We have an example indicator which implements a StreamWriter which can offer some further direction.

                  SampleStreamWriter - https://ninjatrader.com/support/help...o_write_to.htm

                  Please let us know if we can be of further assistance.
                  JimNinjaTrader Customer Service

                  Comment


                    #10
                    Jim,

                    Awesome, thanks! I'll check that out. Maybe I can figure out how to convert this script example over to a Custom Share.
                    Last edited by JAtrades; 08-08-2019, 10:49 AM.

                    Comment


                      #11
                      Jim,

                      Bless you, sir... your advice has put me in the right direction....this should give me a good start to build from.

                      Jon

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by cre8able, Today, 01:01 PM
                      0 responses
                      1 view
                      0 likes
                      Last Post cre8able  
                      Started by manitshah915, Today, 12:59 PM
                      0 responses
                      2 views
                      0 likes
                      Last Post manitshah915  
                      Started by ursavent, Today, 12:54 PM
                      0 responses
                      2 views
                      0 likes
                      Last Post ursavent  
                      Started by Mizzouman1, Today, 07:35 AM
                      3 responses
                      17 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by RubenCazorla, Today, 09:07 AM
                      2 responses
                      13 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Working...
                      X