Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

lost connection then email using OnConnectionStatus()

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

    lost connection then email using OnConnectionStatus()

    I have created a strategy using OnConnectionStatus() to monitor connection status and to email when lost connection , and attached it to 1minute as strategy
    unfortunately it does not seems to be working, no email when lost connection. Anyone can look at the code below?


    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class CONNECTION : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    private ConnectionStatus dataFeed = ConnectionStatus.ConnectionLost;
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>






    protected override void OnOrderUpdate(IOrder order)
    {
    if (dataFeed != ConnectionStatus.ConnectionLost)
    {
    // email when connectionlost
    SendMail("[email protected]", "[email protected]", "lost connection", "lost connection");


    }
    }



    protected override void OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus)
    {
    dataFeed = priceStatus;
    }

    #2
    Hello trdmark,

    Thanks for your post and welcome to the NinjaTrader forums!

    You need to change the logical operator in the if statement from != to == because you want to send the e-mail when the datafeed is equal to Connection.Lost. As is the code (with the operator !=) would send e-mail on every OnOrderUpdate(). Since your strategy is not yet placing orders, the OnOderUpdate() is not called and would be why you are not getting e-mails. You can move your condition check and e-mail sending to the OnConnectionStatus() so you get the e-mail when the connection is lost.

    protected override void OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus)
    {
    dataFeed = priceStatus;

    if (dataFeed == ConnectionStatus.ConnectionLost)
    {
    // email when connectionlost
    SendMail(fromaddress, toaddress, "lost connection", "lost connection");
    }
    }


    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    81 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    66 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    54 views
    0 likes
    Last Post CarlTrading  
    Working...
    X