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 1,962 views
    2. thumb_up 3 thanks given
    3. group 3 followers
    1. forum 9 posts
    2. attach_file 0 attachments




 
Search this Thread

bypass Onstartup code when no connection

  #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?
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
need some ninjascript help
Traders Hideout
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Futures True Range Report
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 

  #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
 
Experience: Intermediate
Platform: Other
Trading: ES, YM, 6E
Posts: 2,668 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
 
Experience: Intermediate
Platform: Other
Trading: ES, YM, 6E
Posts: 2,668 since Feb 2013
Thanks Given: 5,101
Thanks Received: 6,558

See OnConnectionStatus no suitable method found to override - [AUTOLINK]NinjaTrader[/AUTOLINK] 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,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425



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


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