Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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.
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?
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.
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.
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 ...
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.
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.
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?