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


Ninjatrader Threading issue with Custom columns, can anyone help?
Updated: Views / Replies:1,153 / 15
Created: by KhaosTrader Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • 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.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Ninjatrader Threading issue with Custom columns, can anyone help?

  #1 (permalink)
Elite Member
San Jose
 
Futures Experience: Intermediate
Platform: NinjaTrader, Esignal
Favorite Futures: Stocks
 
Posts: 107 since Jan 2012
Thanks: 40 given, 21 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
 
  #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.

 
  #3 (permalink)
Elite Member
Pretoria Gauteng
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: Emini ES, Crude CL
 
Popsicle's Avatar
 
Posts: 214 since May 2016
Thanks: 2,014 given, 462 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:
 
  #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, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,464 since Sep 2013
Thanks: 1,691 given, 3,657 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
 
  #5 (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,

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
 
  #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, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,464 since Sep 2013
Thanks: 1,691 given, 3,657 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
 
  #7 (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 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
 
  #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, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,464 since Sep 2013
Thanks: 1,691 given, 3,657 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
 
  #9 (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 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
 
  #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, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,464 since Sep 2013
Thanks: 1,691 given, 3,657 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 > > > > > 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)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

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 09:25 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@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 2017-12-11 in 0.12 seconds with 19 queries on phoenix via your IP 54.226.227.175