NexusFi: Find Your Edge


Home Menu

 





Share Data between two Charts


Discussion in NinjaTrader

Updated
    1. trending_up 4,544 views
    2. thumb_up 14 thanks given
    3. group 3 followers
    1. forum 20 posts
    2. attach_file 4 attachments




 
Search this Thread

Share Data between two Charts

  #11 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425

And always, always, always remember that global data connections are lost every time you recompile anything, all charts need to be reloaded. Pain in the neck but compared to development times when I was a boy... still luxury.

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Build trailing stop for micro index(s)
Psychology and Money Management
Better Renko Gaps
The Elite Circle
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Are there any eval firms that allow you to sink to your …
Traders Hideout
NexusFi Journal Challenge - April 2024
Feedback and Announcements
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
36 thanks
NexusFi site changelog and issues/problem reporting
22 thanks
The Program
20 thanks
GFIs1 1 DAX trade per day journal
19 thanks
  #12 (permalink)
user10
Dresden + Germany
 
Posts: 21 since Feb 2018
Thanks Given: 11
Thanks Received: 5

I tried to implement your message; Unfortunately, only the current data is transmitted.

Ninjatrader Support does not support static methods. However, I have received the following notice from the forum:

"The strategies you have provided do not reference each other in any way and do not share data in any way.
*The arrays created are within the scope of the instance of the class and can only be accessible in that class."

The suggested method is the use of a shared method. I also tried to implement these.
Unfortunately without success. I only ever get the realtime data ....

Enclosed the current zip file.

Is there really only the solution via streamwriter / streamreader?

Many thanks for the support!

Attached Files
Elite Membership required to download: WriteRead1.zip
Reply With Quote
Thanked by:
  #13 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425


Hi @user10

It's not so hard! NinjaTrader don't support it because it needs care if you are in a development/compile cycle where it is easy to forget to refresh the sharers, but when trading this shouldn't be the case anyway. I have many NT7 projects that reliably use this mechanism in far more complex ways.

I have quickly created a simple demonstration of the concept for you and attached it here, a simple writer that puts the current price into the array, indexed by CurrentBar (with the % modifier to ensure safe wrap-around).

Note where the shared array is declared in the code file.

If you put rfkWriter into a chart, then put rfkReader into another chart (obviously more useful if same time bars but not essential) then you can see the following example with YM prices displayed as an indicator in an ES chart. The value can of course be anything you want it to be.



Of course the reader chart will only see historical data if the writer was loaded first.

Cheers

Travel Well
Attached Files
Elite Membership required to download: rfkWriteRead.zip
Visit my NexusFi Trade Journal Reply With Quote
  #14 (permalink)
user10
Dresden + Germany
 
Posts: 21 since Feb 2018
Thanks Given: 11
Thanks Received: 5

I bow to the pro!
You made my day!!!
Thank you very much

Reply With Quote
Thanked by:
  #15 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425


user10 View Post
I bow to the pro!
You made my day!!!
Thank you very much

Great!

You can improve it in many ways, e.g add rfkSDT.array[(CurrentBar + 1) % 1000)] = 0; to the writer so it forward clears a buffer slot, then the reader can check for zero (or any magic number of your choice) to see whether to update the plot or not.

There are lock issues to be considered between threads, but most of these can be bypassed if you use simple action variable + incrementing sequencer counters.

Have fun

Cheers

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
  #16 (permalink)
user10
Dresden + Germany
 
Posts: 21 since Feb 2018
Thanks Given: 11
Thanks Received: 5

Hello ratfink,

In the meantime, I have rewritten my program and it works flawlessly during operation.
When I program, there are occasional program crashes.

When I activate the strategy, I get the error message:
"Error calling the 'OnStateChange' method: The object reference was not set to an instance of an object."
I tried to catch the error with the following code:
if (Write.WriteArray [CurrentBar]! = null) ReadArray [0] = Write.WriteArray [CurrentBar];
Unfortunately that is not successful.

NinjaTrader.Cbi.Log.Process gives me no further information ...

Do you have an idea how I can solve the problem?

Many Thanks!

Reply With Quote
  #17 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425


user10 View Post
Do you have an idea how I can solve the problem?

I always use simple

Print("x happened value is " + value);

type statements first off, sometimes with counters/flags to limit unnecessary output

and try/catch blocks next, often good practice to leave these in anyway, e.g.

try
{
// put my dodgy code in here
}
catch (Exception ex)
{
Print("my code failed");
Print (ex.ToString();
}

Puts output to the Ninja Output window.

Cheers

p.s. I notice you are using CurrentBar with no wrap around, you will need very big arrays if you have lots of bars of data, check the values there, and that your arrays are as you would expect them to be allocated. This sort of stuff is non-trivial to get right.

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #18 (permalink)
user10
Dresden + Germany
 
Posts: 21 since Feb 2018
Thanks Given: 11
Thanks Received: 5

Thank you for your support!

I found the mistake:
else if(State == State.Terminated)
{
if (Position.MarketPosition == MarketPosition.Long) {ExitLong();}
if (Position.MarketPosition == MarketPosition.Short) {ExitShort();}
}

Actually, I just wanted to clear all orders and positions when the strategy ended.

What do you mean by wrap around?

Reply With Quote
  #19 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425


user10 View Post
Thank you for your support!

I found the mistake:
else if(State == State.Terminated)
{
if (Position.MarketPosition == MarketPosition.Long) {ExitLong();}
if (Position.MarketPosition == MarketPosition.Short) {ExitShort();}
}

Actually, I just wanted to clear all orders and positions when the strategy ended.

What do you mean by wrap around?

Good news, and good work!

By wrap around I mean using the '%' operator to compress an incrementing counter into a fixed range to use as an indexer, e.g.

 
Code
value = array[count % 128];   // gets us a 0 - 127 subscript

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #20 (permalink)
user10
Dresden + Germany
 
Posts: 21 since Feb 2018
Thanks Given: 11
Thanks Received: 5


Thanks for the hint!
I save historical and real-time data.
The number of historical dates is known;
if I limit the array to the number of historical data with%, will the realtime data be transferred correctly?

Reply With Quote
Thanked by:




Last Updated on July 3, 2018


© 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