NexusFi: Find Your Edge


Home Menu

 





lost connection then email using OnConnectionStatus()


Discussion in NinjaTrader

Updated
    1. trending_up 1,229 views
    2. thumb_up 5 thanks given
    3. group 2 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 jayson 
p.dickson
 
Experience: Intermediate
Platform: NT,MC,MT
Trading: ES,CL,GC,6E,
Posts: 6 since Dec 2017
Thanks Given: 12
Thanks Received: 1

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

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
What a Cool Draw/Markup Tool!
Traders Hideout
TOS inspired trading simulator
ThinkOrSwim
IBD Accumulation/Distribution Rating
NinjaTrader
Creating global variables for Ninjatrader
Traders Hideout
DOM in QTrader vs Bookmap
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Fighting Addiction and Stops
17 thanks
Big Mike in Ecuador
6 thanks
Just another trading journal: PA, Wyckoff & Trends
6 thanks
Crossing the Abyss: An Adventure Guide by Snax
4 thanks
Want your NinjaTrader indicator created, free?
4 thanks
  #3 (permalink)
 s2los 
Bergen
 
Experience: Beginner
Platform: ninjatrader
Trading: ES
Posts: 3 since Feb 2018
Thanks Given: 0
Thanks Received: 6


Hi there!

I'm assuming your mail-server is tested and is operational. Otherwise you should see some errors popping up in the log.

You should avoid running the script in OnOrderUpdate. How would this be triggered if you have no connection?

Anyway, here is something that have worked for me:


protected override void OnConnectionStatusUpdate(ConnectionStatusEventArgs connectionStatusUpdate)
{
if(connectionStatusUpdate.Status == ConnectionStatus.Connected)
{
SendMail("post@****.com" , " Connection status OK" , "Connected at " + DateTime.Now );

}

else if(connectionStatusUpdate.Status == ConnectionStatus.ConnectionLost)
{
SendMail("post@****.com" , " Connection Lost" , "Connection lost at " + DateTime.Now );

}
}


I also use this code for checking if the AC-power to the laptop is lost:

//AC-power check
if( SystemInformation.PowerStatus.PowerLineStatus == System.Windows.Forms.PowerLineStatus.Online) mailSent =false;

if ((BarsInProgress == 1 && mailSent == false) && SystemInformation.PowerStatus.PowerLineStatus != System.Windows.Forms.PowerLineStatus.Online)
{
SendMail("post@*****.com" , " !! Battery Alert !! " , " This is an auto generated email. Computer is running on battery power. Possible AC-power loss ");
mailSent = true;
}

- s2los

Reply With Quote
  #4 (permalink)
 jayson 
p.dickson
 
Experience: Intermediate
Platform: NT,MC,MT
Trading: ES,CL,GC,6E,
Posts: 6 since Dec 2017
Thanks Given: 12
Thanks Received: 1

thanks , it appears coding is for NT8, unfortunately still using NT7 which does not use OnConnectionStatusUpdate ?

Started this thread Reply With Quote
  #5 (permalink)
 s2los 
Bergen
 
Experience: Beginner
Platform: ninjatrader
Trading: ES
Posts: 3 since Feb 2018
Thanks Given: 0
Thanks Received: 6


jayson View Post
thanks , it appears coding is for NT8, unfortunately still using NT7 which does not use OnConnectionStatusUpdate ?

Ah, this is NT7. Sorry about that.
Have you tried just performing the check inside the OnConnectionStatus? Something like this:


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

if (dataFeed != ConnectionStatus.ConnectionLost)
{
// email when connectionlost
SendMail("[email protected]", "[email protected]", "lost connection", "lost connection");
}

}

Reply With Quote
Thanked by:




Last Updated on October 18, 2018


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Sitemap - Downloads - Top
no new posts