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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X