Help with a Multi-Instrument Indicator - NinjaTrader Programming | futures io social day trading
futures io futures trading


Help with a Multi-Instrument Indicator
Updated: Views / Replies:2,261 / 12
Created: by ECI Ed Attachments:4

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
 4  
 
Thread Tools Search this Thread
 

Help with a Multi-Instrument Indicator

  #1 (permalink)
Trading Apprentice
Seminole, FL
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: ES
 
Posts: 17 since Oct 2011
Thanks: 9 given, 1 received

Help with a Multi-Instrument Indicator

I have written several NinjaScript indicators, but this is the first time I've tried to write one that requires multi-instruments and arrays. I have attached the code. I added a print statement to verify that the data was being accessed correctly and got results that perplex me. It appears that its loading the correct data for the TICK on every other bar and ES data (incorrect data) on the opposite bars.

This is what the output window looks like:
plArray[0] = 1553 phArray[0] = 1553.25 tlArray[0] = 1553 thArray[0] = 1553.25
plArray[0] = 1553 phArray[0] = 1553.75 tlArray[0] = 180 thArray[0] = 584
plArray[0] = 1553 phArray[0] = 1553.75 tlArray[0] = 1553 thArray[0] = 1553.75
plArray[0] = 1553.25 phArray[0] = 1554 tlArray[0] = 395 thArray[0] = 638
plArray[0] = 1553.25 phArray[0] = 1554 tlArray[0] = 1553.25 thArray[0] = 1554
plArray[0] = 1553 phArray[0] = 1553.75 tlArray[0] = -34 thArray[0] = 395
plArray[0] = 1553 phArray[0] = 1553.75 tlArray[0] = 1553 thArray[0] = 1553.75
plArray[0] = 1553.5 phArray[0] = 1554 tlArray[0] = 190 thArray[0] = 504
plArray[0] = 1553.5 phArray[0] = 1554 tlArray[0] = 1553.5 thArray[0] = 1554
plArray[0] = 1553.5 phArray[0] = 1554.5 tlArray[0] = 437 thArray[0] = 814
plArray[0] = 1553.5 phArray[0] = 1554.5 tlArray[0] = 1553.5 thArray[0] = 1554.5
plArray[0] = 1554 phArray[0] = 1554.75 tlArray[0] = 645 thArray[0] = 911
plArray[0] = 1554 phArray[0] = 1554.75 tlArray[0] = 1554 thArray[0] = 1554.75

Can someone please take a look at this and help me to understand what is going on?

Thanks

Attached Files
Register to download File Type: cs TickDivSigsES.cs (20.9 KB, 16 views)

Last edited by ECI Ed; April 7th, 2013 at 01:57 PM.
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
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,599 received
Forum Reputation: Legendary


@ECI Ed: I think that you need to examine the BarsInProgress property. It is important to know, whether the bars that are currently processed are NYSE TICK bars or ES 06-13 bars. NinjaTrader processes the primary bar series (NYSE TICK) first and then the secondary bar series, if the bars have identical time stamps.

The way you have written the indicator, the entire code will be processed for each incoming tick of each of the two bar series. For example "FirstTickOfBar" can mean first tick of an ES 06-13 minute bar, or first tick of a NYSE TICK bar.

Please divide the OnBarUpdate() code section into one piece which is executed when BarsInProgress == 0 (primary NYSE TICK bars are being called) and another code section which is executed when BarsInProgress == 1 (secondary ES 06-13 bars are being called).

Also for better understanding you should not use Time[0], but Times[0][0] - which designates the time stamp of a NYSE TICK bar - and Times[1][0] - which calls the time stamp of the current ES 06-13 bar.

Also avoid something like thArray[0] = Low[1]. Please make a decision to either store Lows[0][1] or Lows[1][1].

What do you need those arrays for?

Reply With Quote
The following 2 users say Thank You to Fat Tails for this post:
 
  #4 (permalink)
Trading Apprentice
Seminole, FL
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: ES
 
Posts: 17 since Oct 2011
Thanks: 9 given, 1 received

Fat Tails wrote:
What do you need those arrays for?

That is a good question. This indicator is a conversion from esignal code, and in esignal I found that by storing data in an Array once then pulling the data out of the array instead of using High and Low, which required a response from the server, allowed the indicator to run faster, putting less stress on the processor.

In Ninjascript however, though I have found the documentation to be very limited and at times confusing, it looks like the DataSeries is essentially the same as an array. I assume that is what you were referring to. Is the DataSeries stored localy like an array? Is the same true of High and Low or do these variables require a response from the server, like in esignal? Any references you could provide me with to better understand DataSeries would be greatly appreciated.

As I understand the DataSeries method however, it only applies to data where there is a corresponding value for each bar, and the Pivot arrays do not, therefore I need to use an Array, don't I?

I'm currently trying to use the same divergence code on 24 hour instruments, and something is causing the code to stop processing after the array is full, Could this be the way I'm copying the array? or something else? And if it is, can you suggest a way to get around this?

Thanks for your help.

Reply With Quote
 
  #5 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,599 received
Forum Reputation: Legendary


ECI Ed View Post
Fat Tails wrote:
What do you need those arrays for?

That is a good question. This indicator is a conversion from esignal code, and in esignal I found that by storing data in an Array once then pulling the data out of the array instead of using High and Low, which required a response from the server, allowed the indicator to run faster, putting less stress on the processor.

In Ninjascript however, though I have found the documentation to be very limited and at times confusing, it looks like the DataSeries is essentially the same as an array. I assume that is what you were referring to. Is the DataSeries stored localy like an array? Is the same true of High and Low or do these variables require a response from the server, like in esignal? Any references you could provide me with to better understand DataSeries would be greatly appreciated.

As I understand the DataSeries method however, it only applies to data where there is a corresponding value for each bar, and the Pivot arrays do not, therefore I need to use an Array, don't I?

I'm currently trying to use the same divergence code on 24 hour instruments, and something is causing the code to stop processing after the array is full, Could this be the way I'm copying the array? or something else? And if it is, can you suggest a way to get around this?

Thanks for your help.


NinjaTrader is not a front end connected to any backend that is running on a server. It is a stand-alone application. All data can be downloaded to the historical data base and will be stored as daily data, minute data or tick data in Ninja tickfile format.

To download historical data, you can either use the historical data manager or simply open a chart when connected. NinjaTrader will then complement existing historical data by downloading missing data.

The DataSeries object can be considered as an array that can hold one value of the type double for each bar on your chart. The index 0 is used to access the value for the last bar, the highest index in the DataSeries object lets you access the value of the first bar on your chart.

When an indicator is set to CalculateOnBarClose = true, the last bar indexed with 0 is the last complete bar. With CalculateOnBarClose = false, the index 0 will collect the unstable value from the current bar in progress, when connected.

Reply With Quote
 
  #6 (permalink)
Trading Apprentice
Seminole, FL
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: ES
 
Posts: 17 since Oct 2011
Thanks: 9 given, 1 received

You make some good points, and your basic description of the process would be useful in the DataSeries section of the Ninjascript manual. I lost sight of how the programs handle the data. But the problem with many applicatons that store data locally is that they have to read and write from the hard drive instead of directly from memory. I assume that the DataSeries would be stored in memory for faster access, right?
Though you expanded on the basics nicely, what has been my struggle is understanding the syntax. I couldn't find very many samples of DataSeries syntax, expecially with multi-instrument applications. I don't want to put you on the spot or be too demanding, but perhaps you could demonstrate how to change my posted code using arrays into code using DataSeries?

Reply With Quote
 
  #7 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,599 received
Forum Reputation: Legendary


ECI Ed View Post
You make some good points, and your basic description of the process would be useful in the DataSeries section of the Ninjascript manual. I lost sight of how the programs handle the data. But the problem with many applicatons that store data locally is that they have to read and write from the hard drive instead of directly from memory. I assume that the DataSeries would be stored in memory for faster access, right?

When a chart is opened the first time, the chart is built from historical data loaded from the historical data base. For example for a 15 min chart the single bars will be assembled from 1-minute data by using the selected session template. This takes some time. NinjaTrader stores the assembled bars in the directory Documents -> NinjaTrader 7 -> db -> cache. When you open that same chart a second time, NinjaTrader does not need to do the assembling but loads the ready bars from this directory.

When the chart is open, all data including the price data and the DataSeries values of the indicators is loaded into RAM, such that they can be quickly accessed. Indicator values are not stored on the hard disk, but are recalculated from price data each time that a chart is opened. The only thing that can be saved as a template are the indicator settings.


ECI Ed View Post
Though you expanded on the basics nicely, what has been my struggle is understanding the syntax. I couldn't find very many samples of DataSeries syntax, expecially with multi-instrument applications. I don't want to put you on the spot or be too demanding, but perhaps you could demonstrate how to change my posted code using arrays into code using DataSeries?

I think you simply need to read through the help files and the samples shown on the NinjaTrader forum. For a multi-timeframe series it is necessary to understand how the bars are being processed by OnBarUpdate(). Below are some references.

Indicator: Using a DataSeries object to store calculations - NinjaTrader Support Forum
Strategy: Synchronizing a DataSeries object to a secondary time frame - NinjaTrader Support Forum

Reply With Quote
The following user says Thank You to Fat Tails for this post:
 
  #8 (permalink)
Trading Apprentice
Seminole, FL
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: ES
 
Posts: 17 since Oct 2011
Thanks: 9 given, 1 received

Fat Tails,

Glad you confirmed the data is held in RAM, but I'm still struggling to understand the proper syntax for DataSeries. Attached is my latest attempt to implement a Data Series and although it compiles without error, when I run it I get:
Error on calling 'OnBarUpdata' method for indicator 'SMIwDiv' on bar 6209. Object reference not set to an instance of object.
Can you help me with what I'm doing wrong here?

Thanks.

Attached Files
Register to download File Type: cs SMIwDiv.cs (17.4 KB, 9 views)
Reply With Quote
 
  #9 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,599 received
Forum Reputation: Legendary


ECI Ed View Post
Fat Tails,

Glad you confirmed the data is held in RAM, but I'm still struggling to understand the proper syntax for DataSeries. Attached is my latest attempt to implement a Data Series and although it compiles without error, when I run it I get:
Error on calling 'OnBarUpdata' method for indicator 'SMIwDiv' on bar 6209. Object reference not set to an instance of object.
Can you help me with what I'm doing wrong here?

Thanks.

There is a bug in lines 89 to 95, as you have initialized the same DataSeries twice and not initialized another one.

Further, I do not understand, why you use plArray, phArray and indArray. You can access Low, High and smis in the same way, no need to create new objects with identical values.

Reply With Quote
The following 2 users say Thank You to Fat Tails for this post:
 
  #10 (permalink)
Trading Apprentice
Seminole, FL
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: ES
 
Posts: 17 since Oct 2011
Thanks: 9 given, 1 received


Fat Tails:
There is a bug in lines 89 to 95, as you have initialized the same DataSeries twice and not initialized another one.

Big DUH on my part, thank you for pointing that out.

Fat Tails:
Further, I do not understand, why you use plArray, phArray and indArray. You can access Low, High and smis in the same way, no need to create new objects with identical values.

Good point, but I'm going to keep the indArray for portability.

Now as I edge closer to the solution when I add the necessary commands to make the arrays work properly, the editor comes up with numerous errors on the Data Series syntax that weren't problems before. Can you please help me figure out why this is happening, and how to fix it?

TIA

Attached Files
Register to download File Type: cs SMIwDiv.cs (19.2 KB, 12 views)
Reply With Quote
The following user says Thank You to ECI Ed for this post:

Reply



futures io > > > > > Help with a Multi-Instrument Indicator

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
Indicator triggering trades on another instrument. easyLanguage ascr EasyLanguage Programming 2 December 29th, 2011 08:49 PM
NT Multi Timeframe and multi indicator review eurostoxx NinjaTrader 3 August 29th, 2011 01:07 PM
Instrument multiplier/divider by other instrument, name of that? raffu NinjaTrader Programming 4 August 24th, 2011 03:37 AM
Multi Timeframe EMA indicator kulu NinjaTrader Programming 3 November 14th, 2010 06:10 PM
First Multi-series indicator vegasfoster NinjaTrader Programming 10 March 11th, 2010 06:37 PM


All times are GMT -4. The time now is 03:12 PM.

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.15 seconds with 20 queries on phoenix via your IP 54.226.172.30