I am sometimes getting an error while using my indicator which says "Error on calling 'OnMarketData' method on bar 1589: writeFile() error: The process cannot access the file 'C:\full path' because it is being used by another process"
Now for writeFile() method I am using below:
public static void writeFile()
{
try
{
string slFilePath = NinjaTrader.Core.Globals.UserDataDir.ToString() + @"\Directory";
if (!System.IO.Directory.Exists(slFilePath))
{
System.IO.Directory.CreateDirectory(slFilePath);
}
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(slFilePath+ System.IO.Path.DirectorySeparatorChar + "filename.csv", false))
{
lock(Globals.dZoneLockObject)
{
foreach (Zone box in Globals.Boxes)
{
sw.WriteLine(box.serialize());
}
}
}
}
catch (Exception e)
{
throw new Exception("writeFile() error: " + e.Message);
}
}
Any suggestion will be appreciated around why am I getting this massage. Thanks in advance.
Comment