• 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

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 futurestrader7, Today, 11:31 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post futurestrader7  
                      Started by Teebone21, Today, 10:38 AM
                      0 responses
                      6 views
                      0 likes
                      Last Post Teebone21  
                      Started by J_o_s, 03-30-2020, 12:29 AM
                      2 responses
                      16 views
                      0 likes
                      Last Post J_o_s
                      by J_o_s
                       
                      Started by ptpatrader, Today, 10:27 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post ptpatrader  
                      Started by albertokeira, Today, 09:30 AM
                      0 responses
                      8 views
                      0 likes
                      Last Post albertokeira  
                      Working...
                      X