NexusFi: Find Your Edge


Home Menu

 





NinjaTrader custom indicator problem with multiple data series - freezing


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one TraderOfFortune with 7 posts (1 thanks)
    2. looks_two Fat Tails with 6 posts (0 thanks)
    3. looks_3 vegasfoster with 2 posts (0 thanks)
    4. looks_4 Zondor with 1 posts (0 thanks)
    1. trending_up 10,963 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 17 posts
    2. attach_file 5 attachments




 
Search this Thread

NinjaTrader custom indicator problem with multiple data series - freezing

  #1 (permalink)
TraderOfFortune
Rostov-on-Don, Russia
 
Posts: 7 since Dec 2011
Thanks Given: 0
Thanks Received: 1

Hi everybody,

I'm trying to develop an indicator that would calculate over multiple data series.

The main issue I'm having here is that after some time the indicator freezes and not only the indicator, but the whole application. Seldom it recovers from the frozen state, but most of the time it doesn't.
I can't see what I'm doing wrong.

Here's the indicator's Initialize() code:
 
Code
 Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Plot0"));
			
			Add("MSFT", PeriodType.Second, 1, MarketDataType.Last);
			Add("ADBE", PeriodType.Second, 1, MarketDataType.Last);
			Add("GOOG", PeriodType.Second, 1, MarketDataType.Last);
			Add("IBM", PeriodType.Second, 1, MarketDataType.Last);
			
            Overlay				= false;

and this is the OnBarUpdate() code:


 
Code
			if 	(CurrentBars.Length < 5)
				return;

			double average = 0, val1 = 0, val2 = 0, val3 = 0, val4 = 0;

			var count = Math.Min(Math.Min(CurrentBars[1],CurrentBars[2]), 
								 Math.Min(CurrentBars[3], CurrentBars[4]));	
			if (count > 0)
			{
				val1+= BarsArray[1][0];
				val2+= BarsArray[2][0];
				val3+= BarsArray[3][0];
				val4+= BarsArray[4][0];
				average = (val1 + val2 + val3+ val4)/4;

				Log("Avg(" + val1 + "+" + val2 + "+" + val3+ "+"+ val4 + ")=" + average,  NinjaTrader.Cbi.LogLevel.Information);
			
				Plot0.Set(average);
			}
			else
			{
				Log("Avg(???)=undef",  NinjaTrader.Cbi.LogLevel.Information);
			
				Plot0.Set(0);
			}
Nothing too fancy, few lines of simple code.
I did try on a different PCs, and it seems that CPU speed and available memory do not affect much. In fact, memory consumption is pretty negligible.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Deepmoney LLM
Elite Quantitative GenAI/LLM
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Exit Strategy
NinjaTrader
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
Battlestations: Show us your trading desks!
26 thanks
The Program
18 thanks
  #3 (permalink)
 vegasfoster 
las vegas
 
Experience: Intermediate
Platform: Sierra Chart
Broker: Velocity/IB
Trading: 6E
Posts: 1,145 since Feb 2010
Thanks Given: 304
Thanks Received: 844


Only thing I see is that you are pulling second data. I would have the input the same as the time frame you are trading off of, so if you are trading using a 5-minute chart, then try using 5-minute data as the input. I believe this will lessen the load and not have any effect on what you are seeing. If that doesn't help or you are using a second chart to trade and need second input, then try loading fewer days.

Reply With Quote
  #4 (permalink)
TraderOfFortune
Rostov-on-Don, Russia
 
Posts: 7 since Dec 2011
Thanks Given: 0
Thanks Received: 1

Thanks for the post, vegasfoster.
All data series have the same time-frame with the series on the chart. As of loading fewer days, it helps for some time, but eventually the result is the same.

Reply With Quote
  #5 (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 need to use the BarsInProgress criterion to set the values of the different dataseries.

if(BarsInProgress==1) value of first ADDed data series = Closes [1][0]
if(BarsInProgress==2) value of second ADDed data series = Closes [2][0]

 
Code
      
      if(BarsInProgress==1) val1+= BarsArray[1][0];
      if(BarsInProgress==2) val2+= BarsArray[2][0];
      if(BarsInProgress==3) val3+= BarsArray[3][0];
      if(BarsInProgress==4) val4+= BarsArray[4][0];
You should be using try{ }catch blocks with diagnostic Print statements to show you what is going wrong during development.

You can get the value of each added data series only when the value of BarsInProgress is the one associated with that data series.

There are some examples on the Ninjatrader forum. Search it for "BarsInProgress".

etc

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102

@ Zondor: BIP is not required. I do not systematically use it for my MTF indicators as it introduces a lag. We can discuss this via private message, if you are interested.

@ TraderOfFortune:

I cannot see any real problems with your code. I have just produced a small MTF indicator, which is attached, and which runs well and without any problems on my side. It basically uses your code.

The only thing that I have added is a check for CurrentBars[0], which represents the primary bar series of the chart.

Maybe you are running into trouble because you have a slow internet connection. The indicator that I have attached is running well and without any problems here.

Chart and indicator attached.

Are you working for MultiCharts?

Attached Thumbnails
Click image for larger version

Name:	ES 03-12 (Second)  14_12_2011.jpg
Views:	270
Size:	67.9 KB
ID:	57318  
Attached Files
Elite Membership required to download: TestMTF4.zip
Reply With Quote
  #7 (permalink)
TraderOfFortune
Rostov-on-Don, Russia
 
Posts: 7 since Dec 2011
Thanks Given: 0
Thanks Received: 1

Zondor, Fat Tails - many thanks for your feedback!

@Zondor: Fat Tails is right, using BIP gave the same result. Plus, it changes the logic a bit.
I did use try-catch though, as you've suggested to catch possible exceptions (not that I expected any, just to be sure) - none.


@Fat Tails: looked at your indicator - yeap, pretty close. I'm puzzled why your code works all right and mine doesn't... May be it's because you've limited the MaximumBarsLookBack?
My connection is rather fast, never had related issues before.

I'm converting indicators from EasyLanguage/PowerLanguage to Ninja and the opposite.

Reply With Quote
  #8 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


TraderOfFortune View Post
@ Fat Tails: looked at your indicator - yeap, pretty close. I'm puzzled why your code works all right and mine doesn't... May be it's because you've limited the MaximumBarsLookBack?
My connection is rather fast, never had related issues before.

I'm converting indicators from EasyLanguage/PowerLanguage to Ninja and the opposite.

I do not think that it is linked to MaximumBarsLookBack.

You did not publish the entire code of your indicator, so I cannot tell you where the difference lies.

Reply With Quote
  #9 (permalink)
TraderOfFortune
Rostov-on-Don, Russia
 
Posts: 7 since Dec 2011
Thanks Given: 0
Thanks Received: 1


Fat Tails View Post
I do not think that it is linked to MaximumBarsLookBack.

You did not publish the entire code of your indicator, so I cannot tell you where the difference lies.

Well, it's pretty much the indicator itself, the rest of the code is auto-generated.

Reply With Quote
  #10 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102



TraderOfFortune View Post
Well, it's pretty much the indicator itself, the rest of the code is auto-generated.

Why don't you publish your indicator, so that somebody else can test it?

Reply With Quote




Last Updated on December 22, 2011


© 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