NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 04-04-2012, 03:06 AM   #1
daglas
Senior Member
 
Join Date: Mar 2011
Location: Ukraine
Posts: 146
Thanks: 19
Thanked 2 times in 2 posts
Default saving last bar data using stram writer

Dear friends.
I have create strategy which save last bar data to file (only one row OHCL data), but it working slow and unstable. I move code from this strategy to indicator and indicator works better. Than I find sample stream writer indicator which write ohcl data to file. But I need only one row in file only last bar data, I don't need all history from chart. So how should I fix stream writer indicator for saving only last bar data?
daglas is offline  
Reply With Quote
Old 04-04-2012, 03:44 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,567
Thanks: 261
Thanked 1,016 times in 997 posts
Default

daglas, using System IO here would be liklely better performing for your task - http://www.ninjatrader.com/support/f...ad.php?t=48902

You can simply move the if (Historical) return; statement you see, so it would only save current realtime data going forward for example, currently it would store all historical data as well in the sample and then output the RT saved data to the output window.
NinjaTrader_Bertrand is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Bertrand for this post:
Old 04-04-2012, 08:07 AM   #3
daglas
Senior Member
 
Join Date: Mar 2011
Location: Ukraine
Posts: 146
Thanks: 19
Thanked 2 times in 2 posts
Default

I prefer such solution
if (CurrentBar>Bars.Count-100)
{

File.WriteAllText(path, Open[0]);

}
daglas is offline  
Reply With Quote
Old 04-11-2012, 12:41 PM   #4
daglas
Senior Member
 
Join Date: Mar 2011
Location: Ukraine
Posts: 146
Thanks: 19
Thanked 2 times in 2 posts
Default

Now I have such trouble. If my program which periodically read this file cause collision (read the file when nt7 try to save data to this file), indicator stops and I have error message in log windows. Something like indicator can't access to file ****. How can I write some exception in body of indicator, to retry reading file after collision or something also which help to write data even after errors.
daglas is offline  
Reply With Quote
Old 04-12-2012, 04:37 AM   #5
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,567
Thanks: 261
Thanked 1,016 times in 997 posts
Default

daglas, you would need to look into locking the file to ensure no concurrent access is possible - for ideas you can check into this link - http://stackoverflow.com/questions/7...ed-environment
NinjaTrader_Bertrand is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
saving quotes to file at each new bar daglas General Programming 4 07-22-2011 11:53 AM
Looking for independant ninjascript writer Johnnyninja Strategy Development 1 09-28-2010 10:33 AM
DX Indicator - Need C Sharp writer nelsonnelson Indicator Development 0 07-29-2010 05:00 PM
To: CalculateValueArea : writer T2020 Charting 1 12-21-2008 08:52 AM
code writer needed upwardtrade ATM Strategies (Discretionary Trading) 1 05-05-2008 04:41 PM


All times are GMT -6. The time now is 09:38 AM.