• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom Column Question

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Custom Column Question

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


    Code:
    		protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
    		{
    
    			
    				if (!IsFirstTickOfBar)
    				{
    					return;
    				}
    			
    			
    			enuColumnAlertAction ColumnAlertAction = enuColumnAlertAction.None;
    			enuTradeDirection TradeDirection = enuTradeDirection.Unknown;
    			
    		
    
    			int MaxBarsBack = MaxBarsLookBackForSetup;
    			
    			BackColor = Brushes.Transparent;
    	
    			
    			
    			
    			string WriteSting;
    		
    			double InfoVal = Khaos_QuantumCalc.Market_Analyzer_Setup_Info[1];

    #2
    Hello KhaosTrader,

    Thank you for your post.

    I recommend reviewing the details on Multi-Threading in NinjaTrader 8 at the following link: http://ninjatrader.com/support/helpG...-threading.htm

    In addition, refer to the Dispatcher information on MSDN: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Well, can you give me an example, of some sort of a custom column calling an indicator like this where thread safety is dealt with?

      Comment


        #4
        Hi,

        I tried this lock , but still errors, (not as many errors though)

        Please help.

        Code Below

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

        Comment


          #5
          Hello KhaosTrader,

          Thank you for your patience.

          What errors are you receiving? Can you details these in your response or provide a screenshot of the Log tab where the errors are listed?

          In addition, can you advise what you are attempting to build for the Market Analyzer that requires calling an indicator in your Column?
          Patrick H.NinjaTrader Customer Service

          Comment


            #6
            Hi,

            Ok what am I attempting to build:

            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.


            log file with error:

            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.TryEnterWrit eLockCore(TimeoutTracker timeout)
            at System.Threading.ReaderWriterLockSlim.TryEnterWrit eLock(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)
            Last edited by KhaosTrader; 10-18-2016, 12:23 PM.

            Comment


              #7
              *** Also note, it seems that when I refresh, I really get errors, I just put into testing on a 10 second interval with about 18 or so instruments, when I hit refresh, and while it is refreshing, i refresh 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.TryEnterWrit eLockCore(TimeoutTracker timeout)
              at System.Threading.ReaderWriterLockSlim.TryEnterWrit eLock(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; 10-18-2016, 12:39 PM. Reason: update the info

              Comment


                #8
                Hello KhaosTrader,

                Thank you for your responses.
                Originally posted by KhaosTrader View Post
                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.
                I would recommend just doing this in the indicator or another indicator that calls this indicator. Then use the Indicator column in the Market Analyzer. There is not an option to set how many bars are needed in a column unless we use the Indicator column. So no need to reinvent the wheel using a Column that generally are reserved for Market Data and Fundamental Data events.
                Last edited by NinjaTrader_PatrickH; 10-18-2016, 02:09 PM.
                Patrick H.NinjaTrader Customer Service

                Comment


                  #9
                  Hi,

                  The problem of placing an indicator in a column, is that I cannot format a text string in the column, i have to rely on cell conditions, and as there are many permutations, the list gets super long and its difficult.

                  ...

                  Also I have this working... it just makes errors. Basically what I do is have logic that looks back at the two series values X bars, and then looks for the latest setup, and rates that setup, and then it will write in text, in the cell, how many bars back the setup was, what direction, and how good that setup is..

                  So I have a setting in the custom column, for maximum bars to look back for a setup.. and then uses a loop to find the most recent one...

                  Its all doable -- I successfully have achieved in making it work.. i just have a threading issue, and frankly, it shouldnt be there. So there should be some way to fix it, ..

                  I think that if I do a reload ninjascript, that is where errors come often, especially if i click on reload ninjascript twice in rapid succession.. It "walks over itself" or something. Perhaps this is an issue in the indicator, and there should be a way to fix this i think.,

                  Maybe I need to see if is there a way to make sure an indicator's objects are completely destroyed upon a reload ninjascript and then they will be re-instantiated...? Does this make sense? how would I do that?

                  Perhaps there are other reasons for the thread error, but lets not give up on it.
                  Last edited by KhaosTrader; 10-18-2016, 01:17 PM. Reason: refresh should be reload

                  Comment


                    #10
                    Ok,

                    I might be making progress...

                    I did several things...

                    First I set all objects I use to null in the (state - configure) section on the OnStateChange,

                    Second, I put a state variable in called IsReloading. I initialize this to false, and when the code goes into the state configure I use this variable to make sure the execution cant walk over itself..

                    I still got errors, so I decided to do a try catch block and just throw away the exception so the logic will continue on...

                    I now get this error sometimes if i do reload ninjascript a few times over itself:

                    "A hosted indicator tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state."


                    Here is the log:

                    2016-10-18 15:41:02:953|2|4|Session Break (Version 8.0.0.14)
                    2016-10-18 15:41:05:118|1|4|Verifying license at primary server...
                    2016-10-18 15:41:05:386|1|4|Type=Simulation State=Verified Start Date=12/31/2004 End Date=11/30/2099
                    2016-10-18 15:41:05:495|1|4|Global simulation mode enabled
                    2016-10-18 15:41:05:568|1|4|Vendor assembly 'System.Speech' version='4.0.0.0' loaded.
                    2016-10-18 15:41:06:190|1|2|Using IS (is-us-003.ninjatrader.com/31658)
                    2016-10-18 15:41:06:225|1|4|Automated trading disabled
                    2016-10-18 15:41:06:226|1|4|Auto connecting 'My FXCM'...
                    2016-10-18 15:41:06:229|1|2|My FXCM: Primary connection=Connecting, Price feed=Connecting
                    2016-10-18 15:41:06:436|1|32|Order entry hot keys disabled
                    2016-10-18 15:41:06:436|1|4|Auto close enabled=False
                    2016-10-18 15:41:13:970|1|2|My FXCM: Primary connection=Connected, Price feed=Connected
                    2016-10-18 15:41:13:981|1|2|Time to auto close position='00:00:00', Enabled=False
                    2016-10-18 15:41:13:981|1|2|Using HDS (hds-us-003.ninjatrader.com/31655)
                    2016-10-18 15:44:38:036|3|4|A hosted indicator tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state.
                    2016-10-18 15:45:03:652|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.TryEnterWrit eLockCore(TimeoutTracker timeout)
                    at System.Threading.ReaderWriterLockSlim.TryEnterWrit eLock(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)

                    Comment


                      #11
                      Hello KhaosTrader,

                      The message on the DataSeries indicates the indicator is not loading data as needed.

                      So you need a string output on the Market Analyzer column? Can you provide a screenshot of what you are referring to?
                      Patrick H.NinjaTrader Customer Service

                      Comment


                        #12
                        The cell content will be as follows, where N = number of bars back

                        [ N ]
                        ~ N ~
                        => N <=
                        .(dot no setup)

                        The color is either red or green, depending if its long or short.

                        I can put in cell Condition logic that is true, and then save it as a preset.

                        Doing this will require the following number of cell conditionals:Number of Bars Back) *(number of conditions) * ( directional , long or short) +1 (for no setup)

                        so for 10 bars back it would be 10*3*2+1 = 61.

                        I guess thats ok, if i can make it a preset.

                        So i assume the best way of doing it would be to make an new indicator called KhaosQuantumColum which would instantiate KhaosQuantumCalc, and just pass through the appropriate settings and also just have 1 plot exposed where the plot value would always be one of the 51 values that conditional logic can read and paint nicely in the cell.

                        I rather just have a custom column, but if there are serious threading issues that cant be addressed, perhaps I have no choice.

                        Is this what you suggest?
                        Last edited by KhaosTrader; 10-18-2016, 03:00 PM. Reason: clarification

                        Comment


                          #13
                          Hello 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.
                          Patrick H.NinjaTrader Customer Service

                          Comment


                            #14
                            Yes that would be awesome to have that, I sure hope they will implement that....

                            Comment


                              #15
                              Below is a screenshot of how I am using the indicator in Market Analyzer....
                              It shows results of a 2000 Tick and a 60 minute chart.

                              If I could have it so that I could have a text field with unique font codes that would be great because I would be able to combine standard text with wingding icons or something, which would allow even more flexibility. That is have a text field that could have multiple fonts inside it.

                              I am not sure if this is possible, but it would be fantastic if it was possible.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NinjaCustomer, Today, 12:29 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post NinjaCustomer  
                              Started by Steve L, Today, 11:32 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Steve L
                              by Steve L
                               
                              Started by prabbala, Today, 10:41 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post prabbala  
                              Started by bebbus, Today, 10:36 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post bebbus
                              by bebbus
                               
                              Started by edmata1109, Today, 10:18 AM
                              0 responses
                              8 views
                              0 likes
                              Last Post edmata1109  
                              Working...
                              X