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

Go Back   futures.io

> Futures Trading, News, Charts and Platforms > Platforms and Indicators > NinjaTrader > NinjaTrader Programming


Ninjatrader Threading issue with Custom columns, can anyone help?
Started:October 17th, 2016 (11:15 AM) by KhaosTrader Views / Replies:664 / 15
Last Reply:October 21st, 2016 (09:29 AM) 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?

Old October 17th, 2016, 11:15 AM   #1 (permalink)
Elite Member
San Jose
 
Futures Experience: Intermediate
Platform: NinjaTrader, Esignal
Favorite Futures: Stocks
 
Posts: 101 since Jan 2012
Thanks: 40 given, 10 received

Ninjatrader Threading issue with Custom columns, can anyone help?

Hi,

I am writing a custom column, where use my own indicator.

When I grab data from my indicator, I get a ThreadingLockRecursionException.

I get the data as follows...

Suggestions Please...

Thank you in advance...

 
Code
protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
		{

			
				if (!IsFirstTickOfBar)
				{
					return;
				}
			
			
			enuColumnAlertAction ColumnAlertAction = enuColumnAlertAction.None;
			enuTradeDirection TradeDirection = enuTradeDirection.Unknown;
			

		
			double InfoVal = Khaos_QuantumCalc.Market_Analyzer_Setup_Info[1]; // <-- problem

Reply With Quote
     

Old October 17th, 2016, 11:15 AM   #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

     

Old October 17th, 2016, 01:01 PM   #3 (permalink)
 Vendor: www.algoworx.com 
Pretoria Gauteng
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: Emini ES, Crude CL
 
Popsicle's Avatar
 
Posts: 180 since May 2016
Thanks: 944 given, 393 received

Locking resource


Hi @KhaosTrader,

Try providing a lock for the indicator call you are making. At the top of the class (or anywhere outside a method) declare a variable that you can use as a lock:

 
Code
private static object _syncLock = new object();
Then change this line of code:

 
Code
double InfoVal = Khaos_QuantumCalc.Market_Analyzer_Setup_Info[1];
to:

 
Code
double InfoVal = 0.0d;
lock(_syncLock)
{
      InfoVal = Khaos_QuantumCalc.Market_Analyzer_Setup_Info[1];
}
//Use the value in the InfoVal variable here....
This will ensure that only one thread at a time can call that piece of code. Please just note that this may have a bit of a performance impact on your code as it effectively creates a "one call at a time queue" basically into that call. It does correctly ensure that only one thread at a time calls the code though.

If this does not fix the issue, you might have code in your indicator that recursively calls itself which is a totally different beast to solve.

Hope this helps,
Popsicle

Reply With Quote
     
The following 2 users say Thank You to Popsicle for this post:
     

Old October 17th, 2016, 01:03 PM   #4 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6N, 6S, ES, CL, ZB
 
rleplae's Avatar
 
Posts: 1,550 since Sep 2013
Thanks: 1,123 given, 2,353 received
Forum Reputation: Legendary


KhaosTrader View Post
Hi,

I am writing a custom column, where use my own indicator.

When I grab data from my indicator, I get a ThreadingLockRecursionException.

I get the data as follows...

Suggestions Please...

Thank you in advance...

 
Code
protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
		{

			
				if (!IsFirstTickOfBar)
				{
					return;
				}
			
			
			enuColumnAlertAction ColumnAlertAction = enuColumnAlertAction.None;
			enuTradeDirection TradeDirection = enuTradeDirection.Unknown;
			

		
			double InfoVal = Khaos_QuantumCalc.Market_Analyzer_Setup_Info[1]; // <-- problem

Probably there is (already) a lock in that code ?

Can you dig deeper ?

what is behind Khaos_QuantumCalc.Market_Analyzer_Setup_Info[1] ?

Reply With Quote
     

Old October 17th, 2016, 02:21 PM   #5 (permalink)
Elite Member
San Jose
 
Futures Experience: Intermediate
Platform: NinjaTrader, Esignal
Favorite Futures: Stocks
 
Posts: 101 since Jan 2012
Thanks: 40 given, 10 received

Futures Edge on FIO
Hi,

Thank you guys for your help..

I didnt put any locks in any of my code prior to this point...

I added the locks, and I still got errors, but not as many errors...

Here is my modified code...

I put the following line outside the scope of the method...

 
Code
private static object _syncLock = new object();
And here is the modified code in the method...

 
Code
		protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)

		{

	if (!IsFirstTickOfBar)
			{
				return;
			}
			
			if (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];
		}

Reply With Quote
     

Old October 17th, 2016, 02:28 PM   #6 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6N, 6S, ES, CL, ZB
 
rleplae's Avatar
 
Posts: 1,550 since Sep 2013
Thanks: 1,123 given, 2,353 received
Forum Reputation: Legendary

I don't think it's a good idea to put a lock and serialize the 'on market data' event
this will create a single bottle neck in your system

If you read your indicator, that does not come from OnMarketData anyway

It would be good to know, what is happening when you are reading the value
of your indicator... and why there is a conflict

Normaly (according to my understanding)
you need a lock, when two threads are accessing the same data
and more precisely, if at least one of the two threads is changing
the data. If two thread are 'reading' the data, that is not a concurrency
issue.

Here i think you are doing something in the code for 'reading' your indicator
i would be interested to see your 'getter' piece of code, what happens there..

Reply With Quote
     

Old October 17th, 2016, 02:34 PM   #7 (permalink)
Elite Member
San Jose
 
Futures Experience: Intermediate
Platform: NinjaTrader, Esignal
Favorite Futures: Stocks
 
Posts: 101 since Jan 2012
Thanks: 40 given, 10 received

Hi rleplae,

Thank you for your helping.. I really appreciate it.

The code calls my indicator that is quite complex, it datamines various bar patterns and uses all sorts of intelligent filtering to come up with setups. I like to use it to trade forex, and I basically have about 17 or so pairs I trade. I have the custom column on the market analyzer such that it will act as a scanner and tell me how many bars ago the setup was, what direction the setup is, and a rating of the setup.

The cool thing is I can put in several columns with different time frames, thereby having my scanner show me my setups on dozens of charts, and its really quite handy.

Reply With Quote
     

Old October 17th, 2016, 02:47 PM   #8 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6N, 6S, ES, CL, ZB
 
rleplae's Avatar
 
Posts: 1,550 since Sep 2013
Thanks: 1,123 given, 2,353 received
Forum Reputation: Legendary


KhaosTrader View Post
Hi rleplae,

Thank you for your helping.. I really appreciate it.

The code calls my indicator that is quite complex, it datamines various bar patterns and uses all sorts of intelligent filtering to come up with setups. I like to use it to trade forex, and I basically have about 17 or so pairs I trade. I have the custom column on the market analyzer such that it will act as a scanner and tell me how many bars ago the setup was, what direction the setup is, and a rating of the setup.

The cool thing is I can put in several columns with different time frames, thereby having my scanner show me my setups on dozens of charts, and its really quite handy.

Something must be there in that code...

Just on another direction, if you only have one single column for one single instrument, are you also running into the same issue ? or is it only, when multiple columns for multiple instruments are updating simultaneously ?

Reply With Quote
     

Old October 17th, 2016, 03:30 PM   #9 (permalink)
Elite Member
San Jose
 
Futures Experience: Intermediate
Platform: NinjaTrader, Esignal
Favorite Futures: Stocks
 
Posts: 101 since Jan 2012
Thanks: 40 given, 10 received

i checked it with one column with 18 instruments... I didnt check with 1 column with 1 instrument, should I try that? it might take a while for the problem to come up , if it will come up with just 1 instrument...

Reply With Quote
     

Old October 17th, 2016, 03:59 PM   #10 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6N, 6S, ES, CL, ZB
 
rleplae's Avatar
 
Posts: 1,550 since Sep 2013
Thanks: 1,123 given, 2,353 received
Forum Reputation: Legendary



KhaosTrader View Post
i checked it with one column with 18 instruments... I didnt check with 1 column with 1 instrument, should I try that? it might take a while for the problem to come up , if it will come up with just 1 instrument...

if it never comes up with 1 column 1 instrument
then it's the indicator that is not thread safe

it's worth doing the test to eliminate that possibility

Reply With Quote
     

Reply



futures.io > Futures Trading, News, Charts and Platforms > Platforms and Indicators > NinjaTrader > NinjaTrader Programming > 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)
 

NinjaTrader 8: Features and Enhancements, Tips and Tricks

Dec 6
 

Al Brooks: Stop Losing when a Good Trade goes Bad, Correcting Mistakes

Elite only
 

Trading Technologies: Algo Design Lab hands-on

Dec 13
     

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


All times are GMT -4. The time now is 12:32 PM.

Copyright © 2016 by futures.io. 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.
 
no new posts

Page generated 2016-12-05 in 0.12 seconds with 19 queries on phoenix via your IP 54.205.150.215