• 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

Sending E-mail upon order execution

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

    Sending E-mail upon order execution

    Hi.
    I have had some great support from you guys trying to get the email function working upon order execution for live simulated trading using the Ninjascript. To ensure e-mails are not sent continuously upon order execution I am using the 'MarketPosition.Flat/Long' function filter. However, one issue I am noting is that when specific entry/exit conditions are met, 4-5 e-mails are sent prior to the order being filled/flattened. How is it possible to restrict the number of e-mails sent to just one per entry exit ??

    thx
    David

    #2
    You would need to custom code this in your strategy by setting/resetting a flag variable to indicate that as mail has been sent.
    DierkNinjaTrader Customer Service

    Comment


      #3
      thx - where do I look in the help guide for developing such flags?

      Comment


        #4
        There is no documentation on this since this is not NinjaScript specific but programming concept.

        For example:

        bool sentMail = false;

        if (sentMail == false)
        {
        SendMail();
        sentMail = true;
        }
        RayNinjaTrader Customer Service

        Comment


          #5
          thx - I will try this out & get back to you

          Comment


            #6
            tried this & it dsoes work - thx for your help
            David

            Comment


              #7
              Hi ----

              Although this strategy woks in principle, I often receive a number of e-mails per single order execution - I am assuming this is because there is a lag between conditions being met & order being executed. How is it possible to ensure that only a single e-mail is sent per order execution.

              I have attached the custom NT strategy for your reference.

              Many thx for your help.
              David

              Attached Files

              Comment


                #8
                Sorry due to bandwith reasons we are unable to provide support to the level of actually coding or reviewing strategies.

                Quick hint:
                Your condition
                Code:
                                bool sentMail=false;
                                if(sentMail==false)
                always (!) triggers -> the filter you put in place is not effective.

                You might consider contacting a NinjaScript consultant for further C#/NinjaScript coding support: http://www.ninjatrader.com/webnew/pa...injaScript.htm
                DierkNinjaTrader Customer Service

                Comment


                  #9
                  Hi.
                  Now I am confused. I was only implementing the advice given by Ray earlier in the thread - which appears to contradict your hint below.

                  in the on bar update section, I am struggling to understand how to do anything just the once............ for example, the following just continues to print NT in the output window - I presume this is because everything is reset for every update.

                  int x = 0;
                  if (x == 0)


                  {
                  Print(
                  "NT");

                  }

                  All options on pages 353-356 in your help manual print repeatedly the same item, nothing happens just the once.

                  How for example in NT do you ensure the order is executed only once & not for every bar update - surely this is just the same thing that I am trying to repeat??

                  I would appreciate your advice - I am not convinced that this is a C# programming issue.

                  thx in advance
                  David

                  Comment


                    #10
                    The problem is that you are declaring variables whose scope is only relevant for the OnBarUpdate() method. This means that its lifetime is only valid for each call to the OnBarUpdate() method.

                    Put the sentMail variable outside of the OnBarUpdate() method.

                    Such as:

                    private bool sentMail = false;

                    Please google "Scope and lifetime of a variable" for additional resources in understanding this topic.
                    RayNinjaTrader Customer Service

                    Comment


                      #11
                      thx - that moves things in the right direction when printing to the output window - I can get this to happen just once using the simulated datafeed.
                      When replacing the print function with sendmail function, the mail is not sent. I am hoping that this is due to the fact that I am using the simulated datafeed function rather than real-time data feed - pls could you confirm this......

                      thx
                      David

                      Comment


                        #12
                        This will work in any real-time streaming data. It will not work in Historical.

                        You will need to check your program logic and debug why it does not work in a simulated data feed environment.
                        RayNinjaTrader Customer Service

                        Comment


                          #13
                          thx Ray, but still struggling........this to me should be simple.

                          I have a

                          privatebool x=false;

                          & then the following on OnBarUpdate().................

                          // Condition set 1

                          if(x == false)

                          {Print(
                          "BUY BUY BUY");
                          x=
                          true;
                          }

                          this prints once (as expected) to the Output Window.
                          However, if I replace the Print function with the SendMail function (with the appropriate info after), no e-mail is sent & nothing is recorded in the log. Pls could you try the same................

                          this i don't understand.

                          thx in advance
                          DG

                          Comment


                            #14
                            The likely issue is that your SMTP server is not working or configured correctly. You can test this in the Tools > Options area.

                            If it prints the message, then for sure the code block is executing. Also check your log tab for any further errors.
                            RayNinjaTrader Customer Service

                            Comment


                              #15
                              Hi Ray.

                              1/ The message does print to the Output Window once as expected.
                              2/ e-mail / SMTP is OK with test message (checked via Tools -> Options.....)
                              3/ continuous e-mails sent with placing a ';' after: if (x==false);
                              4/ no ';' ...... no e-mail sent.

                              Have you tried this yourself ?

                              thx
                              David

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cirzonorkecv, Yesterday, 11:52 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post cirzonorkecv  
                              Started by rickyblah12, Yesterday, 01:01 PM
                              1 response
                              12 views
                              0 likes
                              Last Post Erwin Beckers  
                              Started by dadarara, Yesterday, 12:18 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post dadarara  
                              Started by joemiller, Yesterday, 07:33 AM
                              2 responses
                              12 views
                              0 likes
                              Last Post joemiller  
                              Started by TheGameOfProbabilities, 07-18-2019, 06:56 AM
                              7 responses
                              38 views
                              0 likes
                              Last Post DaveS
                              by DaveS
                               
                              Working...
                              X