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 charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    59 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    143 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    161 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    97 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    283 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X