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 funk10101, Today, 09:43 PM
    0 responses
    4 views
    0 likes
    Last Post funk10101  
    Started by pkefal, 04-11-2024, 07:39 AM
    11 responses
    36 views
    0 likes
    Last Post jeronymite  
    Started by bill2023, Yesterday, 08:51 AM
    8 responses
    44 views
    0 likes
    Last Post bill2023  
    Started by yertle, Today, 08:38 AM
    6 responses
    26 views
    0 likes
    Last Post ryjoga
    by ryjoga
     
    Started by algospoke, Yesterday, 06:40 PM
    2 responses
    24 views
    0 likes
    Last Post algospoke  
    Working...
    X