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,112 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?

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

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

Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
What broker to use for trading palladium futures
Commodities
Cheap historycal L1 data for stocks
Stocks and ETFs
REcommedations for programming help
Sierra Chart
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
  #12 (permalink)
 
Zondor's Avatar
 Zondor 
Portland Oregon, United States
 
Experience: Beginner
Platform: Ninjatrader®
Broker: CQG, Kinetick
Trading: Gameplay Klownbine® Trading of Globex
Posts: 1,333 since Jul 2009
Thanks Given: 1,246
Thanks Received: 2,731

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



 
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
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #13 (permalink)
 KhaosTrader 
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
Posts: 107 since Jan 2012
Thanks Given: 40
Thanks Received: 21


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.

Started this thread Reply With Quote
  #14 (permalink)
 KhaosTrader 
San Jose
 
Experience: Intermediate
Platform: NinjaTrader, Esignal
Trading: Stocks
Posts: 107 since Jan 2012
Thanks Given: 40
Thanks Received: 21

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.

Started this thread Reply With Quote
Thanked by:
  #15 (permalink)
 
Zondor's Avatar
 Zondor 
Portland Oregon, United States
 
Experience: Beginner
Platform: Ninjatrader®
Broker: CQG, Kinetick
Trading: Gameplay Klownbine® Trading of Globex
Posts: 1,333 since Jul 2009
Thanks Given: 1,246
Thanks Received: 2,731

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

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 - [AUTOLINK]NinjaTrader[/AUTOLINK] 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.

Started this thread 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