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

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");
    }
    }


    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by fx.practic, 10-15-2013, 12:53 AM
    5 responses
    5,406 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by Shai Samuel, 07-02-2022, 02:46 PM
    4 responses
    98 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by DJ888, Yesterday, 10:57 PM
    0 responses
    8 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by MacDad, 02-25-2024, 11:48 PM
    7 responses
    160 views
    0 likes
    Last Post loganjarosz123  
    Started by Belfortbucks, Yesterday, 09:29 PM
    0 responses
    9 views
    0 likes
    Last Post Belfortbucks  
    Working...
    X