#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Indicator; using NinjaTrader.Gui.Chart; using NinjaTrader.Strategy; #endregion // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { /// <summary> /// Enter the description of your strategy here /// </summary> [Description("read the file")] public class MyCustomStrategy : Strategy { // Variables // Order private double long_entry = 0; // This sets the path in which the text file will be created. private string path = "d:\ninjatest\order.txt"; // Creates a StreamReader object private System.IO.StreamReader sr; // This method is used to configure the strategy and is called once before any strategy method is called. protected override void Initialize() { CalculateOnBarClose = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (Historical) return; // Checks to see if the file exists else if (File.Exists(path)) { try { // Sets the file the StreamReader will read from sr = new System.IO.StreamReader(path); string line; // Read lines and calculate the current day's OHLC from the file. While loop will go through the whole file. while ((line = sr.ReadLine()) != null) { string [] split = line.Split(new Char [] {' '}); if ( line.startsWith("long_entry") ) long_entry = double.Parse( split[1] ); } //Print( "entry: " + long_entry + " target: " + long_target + " stop: " + long_stop ); } catch (Exception e) { // Outputs the error to the log Log("You cannot write and read from the same file at the same time. Please remove SampleStreamWriter.", NinjaTrader.Cbi.LogLevel.Error); Print(e.ToString()); throw; } } // If file does not exist, let the user know else Print("File does not exist."); EnterLongLimit(DefaultQuantity, long_entry, ""); } //end OnBarUpdate // Necessary to call in order to clean up resources used by the StreamReader object protected override void OnTermination() { // Disposes resources used by the StreamReader if (sr != null) { sr.Dispose(); sr = null; } } } }
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
reading out a file
Collapse
X
-
reading out a file
i want nt to use information out of a file. i read the reading example and copy the relevant part to the strategy but it wont do as intended. whats wrong?
Code:Tags: None
-
Hello lifetime,
Welcome to the forum and I am happy to assist you.
I suspect the path is not correct. Instead of writing the code as
Code:private string path = "d:\ninjatest\order.txt";
Code:private string path = @"d:\ninjatest\order.txt";
JoydeepNinjaTrader Customer Service
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by ETFVoyageur, 04-30-2024, 02:04 PM
|
7 responses
43 views
0 likes
|
Last Post
by eDanny
Today, 11:45 AM
|
||
Started by f.saeidi, Today, 07:07 AM
|
5 responses
14 views
0 likes
|
Last Post Today, 11:40 AM | ||
Started by Creamers, 04-27-2024, 05:32 AM
|
9 responses
60 views
0 likes
|
Last Post
by Creamers
Today, 11:33 AM
|
||
Decrease the size of the RegionHIghLightY on each tick when the price touches it
by cmtjoancolmenero
Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
|
19 responses
59 views
0 likes
|
Last Post Today, 11:31 AM | ||
Started by samish18, 04-17-2024, 08:57 AM
|
26 responses
116 views
0 likes
|
Last Post
by samish18
Today, 11:30 AM
|
Comment