NexusFi: Find Your Edge


Home Menu

 





bypass Onstartup code when no connection


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one vantojo with 6 posts (0 thanks)
    2. looks_two choke35 with 2 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 ratfink with 1 posts (3 thanks)
    1. trending_up 2,794 views
    2. thumb_up 3 thanks given
    3. group 3 followers
    1. forum 9 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

Sometimes I don't automatically connect to a provider when Ninja starts up.

But I still have workspaces that open charts with indicators.

In this case I would like to bypass some code in OnStartup. (when there is no connection, or ninja starts with no connection)

Any ideas?


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Topstep Acquires The Futures Desk -- Prop Firm Consolida …
Funded Trading Evaluation Firms
The 50/50 Paradox: Peace and Invasion Each at 20% -- Ira …
Prediction Markets & Event Contracts
Iran Peace Expired NO: Ceasefire on Life Support, OPEC a …
Prediction Markets & Event Contracts
TradingView Opens Volume Footprint Data to Pine Script - …
TradingView
The Backwardation Signal: How the CL Futures Curve Tells …
Commodities
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #3 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012


this is for NT7


Started this thread Reply With Quote
  #4 (permalink)
 choke35 
Germany
Market Wizard
 
Experience: Intermediate
Platform: Other
Trading: ES, YM, 6E
Posts: 2,622 since Feb 2013
Thanks Given: 5,101
Thanks Received: 6,558

See the OnConnectionStatus() method.
You can switch your code on/off accordingly.


Reply With Quote
  #5 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

OK, it looks like it should work, but I get this compile message... (it is in a working indicator that otherwise compiles normally)

'NinjaTrader.Indicator.AANews.OnConnectionStatus(NinjaTrader.Cbi.ConnectionStatus, NinjaTrader.Cbi.ConnectionStatus)': no suitable method found to override

===============================================================================

bool connected = false;


#region OnConnectionStatus
protected override void OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus)
{
if (priceStatus = ConnectionStatus.Connected)
connected = true;
else
connected = false;
}
#endregion

===========================================================================

not finding much on the web for this error


Started this thread Reply With Quote
  #6 (permalink)
 choke35 
Germany
Market Wizard
 
Experience: Intermediate
Platform: Other
Trading: ES, YM, 6E
Posts: 2,622 since Feb 2013
Thanks Given: 5,101
Thanks Received: 6,558

See OnConnectionStatus no suitable method found to override - NinjaTrader Support Forum .

P.S.: It boils down to the fact that you have to trigger your indicators from a strategy.


Reply With Quote
  #7 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

Ok, then that method won't work for me because these are chart indicators not used in any strategy....

any other ideas?


Started this thread Reply With Quote
  #8 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

this is not instantiated in OnStartUp when there is no connection....

Bars.MarketData.Connection.Options.Provider

if I check it for null, it tells me it is a non-nullable field....

how can I tell if it is instantiated (I'm not a C# guru...)

If it is not instantiated then I know there is no connection and I can bypass the code I want...

Thanks!


Started this thread Reply With Quote
  #9 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

OK, it can be compared to null....

but it is not instantiated so I get a run error "Object reference not set to an instance of an object" when comparing (==) to null

ideas?


Started this thread Reply With Quote
  #10 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,550 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,430



vantojo View Post
OK, it looks like it should work, but I get this compile message... (it is in a working indicator that otherwise compiles normally)

'NinjaTrader.Indicator.AANews.OnConnectionStatus(NinjaTrader.Cbi.ConnectionStatus, NinjaTrader.Cbi.ConnectionStatus)': no suitable method found to override

In an indicator you have to attach your own callback in OnStartup to get access to the same functionality:

 
Code
NinjaTrader.Cbi.Globals.Connections.ConnectionStatus += new ConnectionStatusEventHandler(OnConnection);

Check the 'private void OnConnection' code in the 'Accounts and Executions' section of ChartMinder if needed, but a cut down example is:

 
Code
		private void OnConnection (object sender, ConnectionStatusEventArgs e)
		{
				if (e.Status == ConnectionStatus.Connecting)
				{

				}
				else if (e.Status == ConnectionStatus.Connected)
				{

				}
				else if (e.Status == ConnectionStatus.ConnectionLost || e.Status == ConnectionStatus.Disconnected)
				{

				}
		}

You also need to disconnect the handler in OnTermination:

 
Code
NinjaTrader.Cbi.Globals.Connections.ConnectionStatus -= new ConnectionStatusEventHandler(OnConnection);

Cheers


Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on January 16, 2016


© 2026 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 - Downloads - Top
no new posts