I am trying to code a strategy so it can read from a text file which contains date and time for entry signals.
This is the content of the text file that contains entry signal's date and time:
2008-10-7 8:18:32
2008-10-7 8:22:03
2008-10-7 8:50:17
2008-10-7 9:41:41
2008-10-7 9:58:14
2008-10-7 10:16:15
2008-10-7 10:46:51
When I tested it, it looks like only read the even lines from the text file while skipping the odd lines, so only the following signals were entered.
2008-10-7 8:22:03
2008-10-7 9:41:41
2008-10-7 10:16:15
My programming knowledge is very limited, so can anyone help me to find out what's the cause?
Thank you!
Code:
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
using System.IO;
namespace NinjaTrader.Strategy
{
public class MyCustomStrategy : Strategy
{
#region Variables
private string myInput0 = @"0"; // Default setting for MyInput0
private string path = Cbi.Core.UserDataDir.ToString() + "test.txt";
private System.IO.StreamReader sr;
#endregion
protected override void Initialize()
{
CalculateOnBarClose = true;
}
protected override void OnBarUpdate()
{ if (File.Exists(path))
{try
{
sr = new System.IO.StreamReader(path);
string line;
while ((line = sr.ReadLine()) != null)
{
myInput0 = sr.ReadLine();
if (myInput0==(Time[0]).ToString())
{
DrawArrowUp("My up arrow" + CurrentBar, false, 0, Close[0] + -3 * TickSize, Color.Yellow);
}
}
}
catch (Exception e)
{
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;
}
}
else
Print("File does not exist.");
}
public override void Dispose()
{
if(sr != null)
{
sr.Dispose();
sr = null;
}
base.Dispose();
}
Comment