NexusFi: Find Your Edge


Home Menu

 





Ninjatrader Threading issue with Custom columns, can anyone help?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one KhaosTrader with 8 posts (2 thanks)
    2. looks_two rleplae with 4 posts (0 thanks)
    3. looks_3 Zondor with 2 posts (1 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 4,093 views
    2. thumb_up 5 thanks given
    3. group 3 followers
    1. forum 15 posts
    2. attach_file 0 attachments




 
Search this Thread

Ninjatrader Threading issue with Custom columns, can anyone help?

  #1 (permalink)
 KhaosTrader 
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
Posts: 107 since Jan 2012
Thanks Given: 40
Thanks Received: 21

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

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Cheap historycal L1 data for stocks
Stocks and ETFs
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
What is Markets Chat (markets.chat) real-time trading ro …
77 thanks
Spoo-nalysis ES e-mini futures S&P 500
55 thanks
Just another trading journal: PA, Wyckoff & Trends
38 thanks
Bigger Wins or Fewer Losses?
24 thanks
The Program
17 thanks
  #3 (permalink)
 
Popsicle's Avatar
 Popsicle 
Pretoria Gauteng
 
Experience: Intermediate
Platform: Sierra Charts
Trading: NQ
Posts: 250 since May 2016
Thanks Given: 2,448
Thanks Received: 550


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

Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


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] ?

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
 KhaosTrader 
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
Posts: 107 since Jan 2012
Thanks Given: 40
Thanks Received: 21

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

Started this thread Reply With Quote
  #6 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863

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..

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #7 (permalink)
 KhaosTrader 
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
Posts: 107 since Jan 2012
Thanks Given: 40
Thanks Received: 21

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.

Started this thread Reply With Quote
  #8 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


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 ?

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #9 (permalink)
 KhaosTrader 
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
Posts: 107 since Jan 2012
Thanks Given: 40
Thanks Received: 21

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...

Started this thread Reply With Quote
  #10 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863



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

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote




Last Updated on October 21, 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