Ninjatrader Threading issue with Custom columns, can anyone help? - NinjaTrader Programming | futures io social trading
futures io futures trading


Ninjatrader Threading issue with Custom columns, can anyone help?
Started: by KhaosTrader Views / Replies:855 / 15
Last Reply: Attachments:0

Welcome to futures io.

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.


You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

-- Big Mike

Reply
 
Thread Tools Search this Thread
 

Ninjatrader Threading issue with Custom columns, can anyone help?

  #11 (permalink)
Elite Member
San Jose
 
Futures Experience: Intermediate
Platform: NinjaTrader, Esignal
Favorite Futures: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Ok I will test this overnight on Forex 5 minute interval and get back to you.. thank you


Sent from my iPad using futures.io futures trading

Reply With Quote
The following user says Thank You to KhaosTrader for this post:
 
  #12 (permalink)
Market Wizard
Portland Oregon, United States
 
Futures Experience: Beginner
Platform: Ninjatrader®
Broker/Data: CQG, Kinetick
Favorite Futures: Gameplay Klownbine® Trading of Globex
 
Zondor's Avatar
 
Posts: 1,317 since Jul 2009
Thanks: 1,233 given, 2,607 received

suggestion to use a reference to a single durable instance of indicator

Try this, if it works it should eliminate the need for the lock.

https://futures.io/ninjatrader-programming/3565-anyone-have-any-hints-optimizing-c-code-4.html#post42223

 
Code
        ....   variable declarations...

        private Khaos_QuantumCalc KQC;


        ...     OnStateChange....

        if(State==State.Configure)
               {   KQC=Khaos_QuantumCalc();

               }


        protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)

		{

	if (!IsFirstTickOfBar || CurrentBar < 300) return;			{
				
			
	lock(_syncLock)
        	{   InfoValue =    (int) KQC.Market_Analyzer_Setup_Info[0];
		    SqueezeState = (int) KQC.Market_Analyzer_Squeeze_Info[0];
		}

"If we don't loosen up some money, this sucker is going down." -GW Bush, 2008
“Lack of proof that something is true does not prove that it is not true - when you want to believe.” -Humpty Dumpty, 2014
“The greatest shortcoming of the human race is our inability to understand the exponential function.”
Prof. Albert Bartlett

Last edited by Zondor; October 17th, 2016 at 04:57 PM.
Reply With Quote
The following user says Thank You to Zondor for this post:
 
  #13 (permalink)
Elite Member
San Jose
 
Futures Experience: Intermediate
Platform: NinjaTrader, Esignal
Favorite Futures: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received


Hi Zondor,

I have it this way... and still the problem, I am not sure if I am doing it where i am using the "init" concept in your referenced post.. but here is my code..

please if you have another idea or if i am not employing your suggestion correctly, let me know how to do it.

Thank you..

Code Below:

Declare

 
Code
public class KhaosQuantum : MarketAnalyzerColumn
	{
		
		private Khaos_Quantum_Calculator Khaos_QuantumCalc;
...
...
Reference

 
Code
		else if (State == State.Configure)
			{
		Khaos_QuantumCalc = Khaos_Quantum_Calculator
				(
					9, // BarsLength
					20, // MA Short Length
					50, // MA Medium Length
					200, // MA Long Length
....
....

Method Logic

 
Code
		protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)

		{
			

				
			
			if (!IsFirstTickOfBar || CurrentBar < 300)
			{
				return;
			}
			
				
			int InfoValue = 0;
			int SqueezeState = 0;
		
		lock(_syncLock)
		{
			 InfoValue =  (int) Khaos_QuantumCalc.Market_Analyzer_Setup_Info[0];
			SqueezeState = (int)Khaos_QuantumCalc.Market_Analyzer_Squeeze_Info[0];
		}

...
...

*** Also note, it seems that when I click reload ninjascript, I really get errors, I just put into testing on a 10 second interval with about 18 or so instruments, when I hit reload ninjascript, and while it is already reloadingi again, many errors occur... Here is the log info:

More info....

It seems if I press the "refresh" on the Market Analyzer it triggers these errors...

Here is the log file...
2016-10-18 14:02:56:851|2|4|Session Break (Version 8.0.0.14)
2016-10-18 14:02:59:038|1|4|Verifying license at primary server...
2016-10-18 14:02:59:308|1|4|Type=Simulation State=Verified Start Date=12/31/2004 End Date=11/30/2099
2016-10-18 14:02:59:418|1|4|Global simulation mode enabled
2016-10-18 14:03:03:511|1|4|Vendor assembly 'System.Speech' version='4.0.0.0' loaded.
2016-10-18 14:03:04:319|1|2|Using IS (is-us-003.ninjatrader.com/31658)
2016-10-18 14:03:04:357|1|4|Automated trading disabled
2016-10-18 14:03:04:358|1|4|Auto connecting 'My FXCM'...
2016-10-18 14:03:04:401|1|2|My FXCM: Primary connection=Connecting, Price feed=Connecting
2016-10-18 14:03:04:651|1|32|Order entry hot keys disabled
2016-10-18 14:03:04:653|1|4|Auto close enabled=False
2016-10-18 14:03:12:147|1|2|My FXCM: Primary connection=Connected, Price feed=Connected
2016-10-18 14:03:12:227|1|2|Time to auto close position='00:00:00', Enabled=False
2016-10-18 14:03:12:228|1|2|Using HDS (hds-us-003.ninjatrader.com/31655)
2016-10-18 14:05:54:630|3|4|Failed to call 'Add' method: System.Threading.LockRecursionException: Write lock may not be acquired with read lock held. This pattern is prone to deadlocks. Please ensure that read locks are released before taking a write lock. If an upgrade is necessary, use an upgrade lock in place of the read lock.
at System.Threading.ReaderWriterLockSlim.TryEnterWriteLockCore(TimeoutTracker timeout)
at System.Threading.ReaderWriterLockSlim.TryEnterWriteLock(TimeoutTracker timeout)
at NinjaTrader.Data.BarsSeries.Add(Bars bars, Double open, Double high, Double low, Double close, DateTime time, Int64 volume, Double tickSize, Boolean isBar, Double bid, Double ask)
2016-10-18 14:31:57:361|3|4|Market analyzer column 'KhaosQuantum': Error on calling 'OnMarketData' method on bar -1: Object reference not set to an instance of an object.
2016-10-18 14:31:57:421|3|4|Market analyzer column 'KhaosQuantum': Error on calling 'OnMarketData' method on bar -1: Object reference not set to an instance of an object.
2016-10-18 14:31:57:472|3|4|Market analyzer column 'KhaosQuantum': Error on calling 'OnMarketData' method on bar -1: Object reference not set to an instance of an object.
2016-10-18 14:31:57:537|3|4|Market analyzer column 'KhaosQuantum': Error on calling 'OnMarketData' method on bar -1: Object reference not set to an instance of an object.
2016-10-18 14:31:57:622|3|4|Market analyzer column 'KhaosQuantum': Error on calling 'OnMarketData' method on bar -1: Object reference not set to an instance of an object.
2016-10-18 14:31:57:628|3|4|Market analyzer column 'KhaosQuantum': Error on calling 'OnMarketData' method on bar -1: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
2016-10-18 14:31:57:698|3|4|Market analyzer column 'KhaosQuantum': Error on calling 'OnMarketData' method on bar -1: Object reference not set to an instance of an object.
2016-10-18 14:31:57:723|3|4|Market analyzer column 'KhaosQuantum': Error on calling 'OnMarketData' method on bar -1: Object reference not set to an instance of an object.
2016-10-18 14:31:57:773|3|4|Market analyzer column 'KhaosQuantum': Error on calling 'OnMarketData' method on bar -1: Object reference not set to an instance of an object.
2016-10-18 14:31:57:816|3|4|Market analyzer column 'KhaosQuantum': Error on calling 'OnMarketData' method on bar -1: Object reference not set to an instance of an object.
2016-10-18 14:31:57:844|3|4|Market analyzer column 'KhaosQuantum': Error on calling 'OnMarketData' method on bar -1: Object reference not set to an instance of an object.
2016-10-18 14:31:57:921|3|4|Market analyzer column 'KhaosQuantum': Error on calling 'OnMarketData' method on bar -1: Object reference not set to an instance of an object.
2016-10-18 14:31:57:977|3|4|Market analyzer column 'KhaosQuantum': Error on calling 'OnMarketData' method on bar -1: Object reference not set to an instance of an object.
2016-10-18 14:31:58:010|3|4|Market analyzer column 'KhaosQuantum': Error on calling 'OnMarketData' method on bar -1: Object reference not set to an instance of an object.
2016-10-18 14:31:58:095|3|4|Market analyzer column 'KhaosQuantum': Error on calling 'OnMarketData' method on bar -1: Object reference not set to an instance of an object.
2016-10-18 14:31:58:095|3|4|Market analyzer column 'KhaosQuantum': Error on calling 'OnMarketData' method on bar -1: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
2016-10-18 14:31:58:095|3|4|Market analyzer column 'KhaosQuantum': Error on calling 'OnMarketData' method on bar -1: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.


Last edited by KhaosTrader; October 18th, 2016 at 03:18 PM. Reason: Adding more info.
Reply With Quote
 
  #14 (permalink)
Elite Member
San Jose
 
Futures Experience: Intermediate
Platform: NinjaTrader, Esignal
Favorite Futures: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

I tried with 1 instrument, error comes up.

What I am going to do is put in an indicator column and just have that work for me.

Reply With Quote
The following user says Thank You to KhaosTrader for this post:
 
  #15 (permalink)
Market Wizard
Portland Oregon, United States
 
Futures Experience: Beginner
Platform: Ninjatrader®
Broker/Data: CQG, Kinetick
Favorite Futures: Gameplay Klownbine® Trading of Globex
 
Zondor's Avatar
 
Posts: 1,317 since Jul 2009
Thanks: 1,233 given, 2,607 received

on the wrong track

futures io Member Poll

How many trading buddies do you follow or share with?

 
You did not make the change I suggested, and don't seem to understand what I said.

I don't think that this is a threading issue.

The indicator crashes because it does not have error handling code. If you trapped the errors, it would probably work.

Refer to a C# tutorial to learn about error handling.

To eliminate the Object Reference exceptions, as a first step add this condition to beginning of OnMarketData and OnBarUpdate methods:

if(CurrentBar == -1) return;

If that doesn't get rid of them, something else is wrong - just like it says, failure to have set an object reference to an instance of an object..

That's about all I can offer based on the information you posted since the problems are in code not revealed..

"If we don't loosen up some money, this sucker is going down." -GW Bush, 2008
“Lack of proof that something is true does not prove that it is not true - when you want to believe.” -Humpty Dumpty, 2014
“The greatest shortcoming of the human race is our inability to understand the exponential function.”
Prof. Albert Bartlett

Last edited by Zondor; October 21st, 2016 at 03:43 AM.
Reply With Quote
 
  #16 (permalink)
Elite Member
San Jose
 
Futures Experience: Intermediate
Platform: NinjaTrader, Esignal
Favorite Futures: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 received

Hi Zandor,

---> I did do a try catch block and posted the results follow up on ninjatrader forum. Eventually ninjatrader suggested I make a new indicator that calls the main indicator, and just use an indicator column.

With the suggested approach, it works fine.

In the ninjatrader form thread, the support person said this

" KhaosTrader,

Thank you for your patience.

To sum it up, even if the custom column has the thread of the instrument and indicator locked we still don't have the bars loaded. We could make a bars request but those bars would not be associated with the indicator and thus we would really be re-writing the entire indicator into the column (which may be an approach you wish to take).

However, I am going to make a feature request to allow for Series<T> types to be the value that is used from the Indicator Column Plot option as well. This would resolve your entire scenario as you could just have an indicator that looks for the conditions and sets a Series<string> to the desired string for the column.

"



The thread is located here:

Custom Column Question - NinjaTrader Support Forum

As you can see Ninjatrader is thinking about allowing the return of a string value for a custom indicator column. That would be excellent if they do that.

Thank you for your patience and help Zandor.

Reply With Quote

Reply



futures io > > > > > Ninjatrader Threading issue with Custom columns, can anyone help?

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)
 

Market Analysis w/Dave Forss @ IQFeed

Apr 25
 

Introducing iSystems with Stage 5 Trading

Apr 27

*NEW* FIO Journal Challenge featuring NinjaTrader ($2,000+ of prizes)

May

Prototyping Python Strategies (part 2) w/Ran Aroussi

Elite only

Ask Me Anything w/Raymond Deux @ NinjaTrader

May 3

An Afternoon with FIO member Softsoap

Elite only
 

Machine Learning & Data Mining Bias w/Kris Longmore @ Robot Wealth

Elite only

Brannigan Barrett (TBA)

Elite only

FIO member Gomi (TBA)

Elite only

FuturesTrader71 (TBA)

Elite only

EasyLanguage Programming w/Chris @ ABC Trading Group

Elite only

Portfolio Diversification w/Brendon Delate

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
NinjaTrader 7 VWAP issue grausch NinjaTrader 2 July 22nd, 2016 05:39 AM
TradeDOM columns arroganzmaschine Sierra Chart 5 February 16th, 2015 11:51 AM
Custom Indicator Study Issue... netarchitech ThinkOrSwim 4 January 19th, 2015 01:22 PM
Custom expandable class issue robsol NinjaTrader Programming 1 November 30th, 2014 03:05 AM
Ninjatrader 6.5 june 3rd CME compatibility issue. isarhodes NinjaTrader 5 June 1st, 2011 02:14 AM


All times are GMT -4. The time now is 04:53 PM.

no new posts
Page generated 2017-04-24 in 0.12 seconds with 19 queries on phoenix via your IP 23.20.202.156