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

Little issue using SendMail() to know when a Strategy is disabled

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

  • sagetrade
    replied
    Thank you. Works well!

    Leave a comment:


  • pstrusi
    replied
    Originally posted by sagetrade View Post
    Would it also work if I use a bool? Like the above?
    I don't see why not, Just make sure that variable's value does not change unwillingly in the code. That was just a simple example to do it but you can create a more refined one with more functions.

    Leave a comment:


  • sagetrade
    replied
    Originally posted by pstrusi View Post
    No problem, here you can see an easy workaround.
    Previously declare an Integer variable called "a" in this example, then it follows like this:

    private bool Realtime = false;

    Code:
    protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				.......			     		
    			}
    			else if (State == State.Configure)
    			{
    				.......
    			}
    			else if (State == State.Realtime)
    			{
    			    [COLOR="Red"]Realtime = true[/COLOR];
    			}
    			else if (State == State.Terminated)
    			{
    				[COLOR="red"]if ( Realtime == true )[/COLOR]
    				{
    					SendMail ("[email protected]", "STRATEGY DISABLED ! ", " Review " );
    				}
    			}
    		}
    Would it also work if I use a bool? Like the above?

    Leave a comment:


  • pstrusi
    replied
    No problem, here you can see an easy workaround.
    Previously declare an Integer variable called "a" in this example, then it follows like this:

    Code:
    protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				.......				
    			}
    			else if (State == State.Configure)
    			{
    				.......
    			}
    			else if (State == State.Realtime)
    			{
    			    a=1;
    			}
    			else if (State == State.Terminated)
    			{
    				if ( a > 0 )
    				{
    					SendMail ("[email protected]", "STRATEGY DISABLED ! ", " Review " );
    				}
    			}
    		}
    Last edited by pstrusi; 11-06-2017, 01:10 PM.

    Leave a comment:


  • sagetrade
    replied
    Originally posted by pstrusi View Post
    Thanks Jim, excellent suggestion!

    In fact, I can confirm to you that was the cause of the error in the log. With a few lines checking first the state was the solution.

    Regards!
    Dear pstrusi,

    I face the same issue. Would you mind to share how you did rewrite the code?

    Leave a comment:


  • pstrusi
    replied
    Thanks Jim, excellent suggestion!

    In fact, I can confirm to you that was the cause of the error in the log. With a few lines checking first the state was the solution.

    Regards!
    Last edited by pstrusi; 09-28-2017, 01:00 PM.

    Leave a comment:


  • NinjaTrader_Jim
    replied
    Hello pstrusi,

    Thanks for opening the thread.

    I am not sure if you are receiving a null reference exception elsewhere in OnStateChange(), but you should not have issue sending an email from State.Terminated.

    I would suggest to add some additional code to control your email so it is triggered after State.Terminated happens after the strategy has reached State.Realtime or State.Historical, since State.Terminated is reached after you open a strategy dialog window. This is outlined in the documentation page linked below.

    NinjaScript Lifecycle - https://ninjatrader.com/support/help...fecycle_of.htm

    Leave a comment:


  • Little issue using SendMail() to know when a Strategy is disabled

    Since I like to know if my Strategy was disabled, I use the email sharing service; so I put this basic instruction:

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    ........
    }
    else if (State == State.Configure)
    {
    ........
    }
    else if (State == State.Terminated)
    {
    SendMail ("[email protected]", "STRATEGY DISABLED ! ", " Review " );
    }
    }
    Whenever I set the Strategy from the Tab "Strategy", a "light error, non-disruptive" pops up in the log:
    Strategy 'PRS': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.

    It seems NOT to have serious consequences of any kind, it even works as thought but since I don't like to see errors, I'd like to know if perhaps there's some restriction to use sendmail() from state.Terminated, if so, please indicate me another way to send the alert.

    Thanks

Latest Posts

Collapse

Topics Statistics Last Post
Started by Barry Milan, Yesterday, 10:35 PM
5 responses
18 views
0 likes
Last Post Barry Milan  
Started by DanielSanMartin, Yesterday, 02:37 PM
2 responses
13 views
0 likes
Last Post DanielSanMartin  
Started by DJ888, 04-16-2024, 06:09 PM
4 responses
13 views
0 likes
Last Post DJ888
by DJ888
 
Started by terofs, Today, 04:18 PM
0 responses
12 views
0 likes
Last Post terofs
by terofs
 
Started by nandhumca, Today, 03:41 PM
0 responses
8 views
0 likes
Last Post nandhumca  
Working...
X