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

Strategy is not sending mail or playing sound

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

    Strategy is not sending mail or playing sound

    Hello there,

    I've been trying to create a simple strategy to test sending emails. I added my email to the share services tab and when I send a test email everything works fine. So I started programming the strategy, however when I run my program it actually submits an order but it doesn't send a mail or play the sound. I uploaded 2 pictures. 1 of the code and 1 of the log showing the order. I don't get why it doens't send an email. I did scrap my mailadress but there is a valid mail adress in there

    Greetings,
    Sebastiaan

    #2
    Hello SebastiaanR,

    Thanks for your post.

    SendMail and PlaySound will only function with realtime data. I would suggest to first test PlaySound and SendMail in a test script that checks if (State == State.Realtime) { //Your logic here }

    Once you have confirmed this is working, you will know that your code will work when your logic is processing realtime data and hits the SendMail or PlaySound call.

    Please also note that PlaySound will only work for 16bit PCM Wav files. I would suggest first testing with the Wav files from C:\Program Files (x86)\NinjaTrader 8\sounds to confirm the logic is working. This can help to confirm if your sounds need to be reformatted.

    For SendMail, it does not appear that you are hitting any errors. Please ensure you are testing this method when the strategy is processing realtime data and double check for any typos in the To parameter for the destination email address. If you find that your test mail works and the email address is properly entered for the To destination email address, I would suggest checking the spam folders of that email's inbox to see if the email message got sent to a spam folder.

    I look forward to being of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hello jim,

      Thanks for the quick response. So I tried adding the check for realtime. I think I did it correctly. Its in the picture I added. I do have a connection with my broker and I should have real time data. I can actually hear the program say "order submitted" when starting the strategy on the stocks that I choose. If I check the log, I can also read "On starting a real-time strategy-etc. I also checked my spam folder and there is sadly enough no mail.

      Greetings,
      Sebastiaan

      Comment


        #4
        Hello Sebastiaan,

        In your code, you are checking for State.Realtime and then returning from code execution.

        Please test the following in a new indicator or strategy using the same email address you have sent the test message to:

        Code:
        protected override void OnBarUpdate()
        {
            if (State == State.Historical)
                return; // return from historical processing. All code below will only execute when the script is processing realtime data.
            SendMail("[email protected]", "Test Subject", "Test body");
        }
        We look forward to being of further assistance.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hi jim,

          I did this and I did not recieve an email. This means I actually don't have real time data right ? If so how can I check this and what can I do. I see the message
          Enabling NinjaScript strategy 'MyCustomStrategy1/152551122' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=By strategy position ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On price change IsUnmanaged=False MaxRestarts=4 in 5 minutes" On the log.

          Comment


            #6
            Hello SebastiaanR,

            Thank you for your reply.

            Jim is out of the office today, but have you set up an Email Sharing Service under Tools > Options > General > Sharing Services? SendMail won't function unless you've got an outgoing email set up, and you won't get a log error if you try to send a mail in the latest version of the platform without one set up.

            Here's a link to our help guide that shows how to set one up if you haven't:


            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Hi kate,

              I got it working. I was logged in in the wrong account of broker.. Thanks for the help.
              Now I have another question.. Can I change a stoploss within a strategy: example initial target and stoploss are : 6% and 2% Now I'm in a long trade an currently I have an unrealized profit of 4%. I would like to change the stoploss to 2% below the 4%. Basicly like a trailing stop. However I've read in the manual that it is impossible to change from setstoploss to settrailingstop. Any way I can do this ?

              Comment


                #8
                Hello SebastiaanR,

                Thanks for your question.

                Please see the example below for how SetStopLoss can be called dynamically within OnBarUpdate. Note that SetStopLoss must be called when the strategy is flat, before the next entry to ensure that the stop loss is reset to an initial level for the next entry execution.

                SamplePriceModification - https://ninjatrader.com/support/help...of_stop_lo.htm

                If you have any additional inquiries, please do not hesitate to open a new thread. It can help other users browsing the forum to open a new thread for new inquiries as it helps to make questions and answers more browsable.

                We look forward to being of any further assistance.
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by gravdigaz6, Yesterday, 11:40 PM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by MarianApalaghiei, Yesterday, 10:49 PM
                3 responses
                10 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by XXtrader, Yesterday, 11:30 PM
                0 responses
                4 views
                0 likes
                Last Post XXtrader  
                Started by love2code2trade, 04-17-2024, 01:45 PM
                4 responses
                28 views
                0 likes
                Last Post love2code2trade  
                Started by funk10101, Yesterday, 09:43 PM
                0 responses
                9 views
                0 likes
                Last Post funk10101  
                Working...
                X