This message I see a couple times a day in my error log.
6/27/2023 1:07:42 PM FomoTrain : - ES 09-23 - Path = c:\users\public\nt_daily-ES.txt - Error = System.UnauthorizedAccessException: Access to the path 'c:\users\public\nt_daily-ES.txt' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost) at System.IO.StreamReader..ctor(String path) at NinjaTrader.NinjaScript.Indicators.ADS.ADSFomo.Fom oGetMACD(String WhatType)
My code is this.
private bool FomoGetMACD(string WhatType)
{
string mySymbol = Instrument.FullName.Substring(0, 2); // easy and simple way to find out in which one we are
var path = @"c:\users\public\nt_"; // [email protected]";
bool retValue = false;
string line;
switch (mySymbol)
{
case "MY":
case "YM":
path = path + WhatType + "-YM.txt";
break;
case "ME":
case "ES":
path = path + WhatType + "-ES.txt";
break;
case "RT":
case "M2":
path = path + WhatType + "-RT.txt";
break;
case "NQ":
case "MN":
path = path + WhatType + "-NQ.txt";
break;
}
// Checks to see if the file exists
if (File.Exists(path))
{
// now we open the daily and get the results
/* The try-catch block is used for error handling.
In this case it is used to ensure you only have one stream object operating on the same file at any given moment. */
try
{
// Sets the file the StreamReader will read from
sr = new System.IO.StreamReader(path);
line = sr.ReadLine(); // this reads it as a text string with the 'newline'
retValue = bool.Parse(line); // and convert it to a boolean
}
catch (Exception e)
{
// Outputs the error to the log
Log("Path = " + path, NinjaTrader.Cbi.LogLevel.Error);
myPrint("Path = " + path + " - Error = " + e.ToString(), false, true);
}
finally
{
}
}
else
{
}
if (sr != null)
{
sr.Dispose();
sr = null;
}
return retValue; // default when we cannot find the file
}
Any inside would be appreciated, thanks -- Ronald
​

Comment