Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

separate actions from disable()

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

    separate actions from disable()

    How would one separate the disable() so it sends mail prior to disabling?


    if ( x0 > y0)

    {
    SendMail());
    }
    {

    Disable();

    #2
    You can create a custom bool to track when the condition where SendMail is being called has been ran

    Code:
    			bool mailSent = false;
    			
    			if( 1 > 2)
    			{
    				SendMail();
    				mailSent = true;
    			}
    Then when your bool is true, you can call Disable()
    Code:
    			
    			if(mailSent)
    			{
    				Disable();
    			}
    MatthewNinjaTrader Product Management

    Comment


      #3
      Originally posted by deathstar View Post
      How would one separate the disable() so it sends mail prior to disabling?


      if ( x0 > y0)

      {
      SendMail());
      }
      {

      Disable();
      I would have to assume that you want to be sure that the SendMail() function actually functioned, before you Disable(). Whether the end mail server actually sent the mail is a different issue.

      However, the SendMail() method does not return a value, so you have to come at it laterally; checking instead if the method threw an exception, then Disable() only if the method did not throw an exeption.
      Use a try ... catch block.
      1. In the exception block, set a string variable
      2. Compare the string variable to the value that would be set by the exception, and if it is not set, then Disable().

      Comment


        #4
        Originally posted by NinjaTrader_Matthew View Post
        You can create a custom bool to track when the condition where SendMail is being called has been ran

        Code:
        			bool mailSent = false;
        			
        			if( 1 > 2)
        			{
        				SendMail();
        				mailSent = true;
        			}
        Then when your bool is true, you can call Disable()
        Code:
        			
        			if(mailSent)
        			{
        				Disable();
        			}
        I tried this but it seems to disable prior to sending mail. I had tried previously with a if x = 0 /x = 1

        It works great if I just remove disable() from it but then my email gets tons of emails.

        koganam, I like this idea, I will put this in.

        Comment


          #5
          This is my last attempt I can ether get it so send one on every bar update or it closes BEFORE sending. My test mail come though everytime.


          protected override void OnBarUpdate()
          {
          // Condition set 1
          if (x >= y)
          {
          Disable();
          c0 = true;
          }

          }
          protected override void OnTermination()
          {if (c0 == true)
          {
          SendMail("email1", "email2", "543", "your breaking my balls here");
          }
          }

          Any ideas are accepted.
          Last edited by deathstar; 02-19-2014, 09:26 PM.

          Comment


            #6
            As a test, please try the following which I know will work

            Code:
            private bool mailSent = false;
            private bool onlyOnce = false;
            
                   protected override void OnBarUpdate()
                    {
                                    // sends mail when strategy is real-time, and will only fire once
            			if(!Historical && !onlyOnce)
            			{
            				
            				SendMail(fromMe, toYou, "disableTest", "sent!");
            			
            				mailSent = true;
            				onlyOnce = true;
            			}
            			
            			if (mailSent == true)
            			{
            				Disable();
            			}
                    }
            MatthewNinjaTrader Product Management

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Jimmyk, 01-26-2018, 05:19 AM
            6 responses
            834 views
            0 likes
            Last Post emuns
            by emuns
             
            Started by jxs_xrj, 01-12-2020, 09:49 AM
            6 responses
            3,290 views
            1 like
            Last Post jgualdronc  
            Started by Touch-Ups, Today, 10:36 AM
            0 responses
            10 views
            0 likes
            Last Post Touch-Ups  
            Started by geddyisodin, 04-25-2024, 05:20 AM
            11 responses
            62 views
            0 likes
            Last Post halgo_boulder  
            Started by Option Whisperer, Today, 09:55 AM
            0 responses
            8 views
            0 likes
            Last Post Option Whisperer  
            Working...
            X