#region Using declarations using System; 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.Gui.Chart; using System.IO; #endregion // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { /// /// zLOGget retrieve indicator values from work file and plot /// [Description("zLOGget")] [Gui.Design.DisplayName("zLOGget")] public class zLOGget : Indicator { #region Variables private string sFileSuffix = "0"; // Default setting private bool bDirFound = false; private bool bFileFound = false; private int iLoop = 0; private int iLen = 0; private string sPathLeft = "C:\\$NinjaTrader65\\zLOGput"; private string sPathDir = "x"; private string sPath = "C:\\$NinjaTrader65\\zLOGputXXII MM-YY\\MMDD.txt"; //XX replaced w/minutes at run time // ES 06-08 instrument symbol month year //private string sPathLastGood = ""; //save last good sPath private string sDate = ""; private string sTime = ""; private string sHH = "XX"; private string sMM = "XX"; private string sSS = "XX"; private int iMM = 0; private string sLine = ""; #endregion /// /// This method is used to configure the indicator and is called once before any bar data is loaded. /// protected override void Initialize() { Add(new Plot(Color.Blue, PlotStyle.Line, "Plot0")); Add(new Plot(Color.Maroon, PlotStyle.Line, "Plot1")); Add(new Plot(Color.Black, PlotStyle.Line, "Plot2")); Add(new Plot(Color.Yellow, PlotStyle.Line, "Plot3")); Add(new Plot(Color.Gray, PlotStyle.Line, "Plot4")); Add(new Plot(Color.Gray, PlotStyle.Line, "Plot5")); Add(new Plot(Color.Red, PlotStyle.Line, "Plot6")); Add(new Plot(Color.Gray, PlotStyle.Line, "Plot7")); Add(new Plot(Color.Gray, PlotStyle.Line, "Plot8")); CalculateOnBarClose = true; Overlay = true; PriceTypeSupported = false; PaintPriceMarkers = false; } /// /// Called on each bar update event (incoming tick) /// protected override void OnBarUpdate() { if (sFileSuffix == "0") return; if(CurrentBar < 20) return; if(bDirFound == false) { if(CurrentBar > 30) return; //no use to keep on looking sPathDir = sPathLeft + sFileSuffix + Instrument.FullName; if (Directory.Exists(sPathDir)) { //Print("The dir sPath found, " + sPathDir); bDirFound = true; } else { //Print("no dir sPath found, " + sPathDir); return; } } sDate = "" + ToDay(Time[0]); //YYYYMMDD sDate = sDate.Substring(4,4); //MMDD sTime = "" + ToTime(Time[0]); //time at midnight is 0 for (iLoop=0;iLoop<9;iLoop++) { // assure time is hhmmss iLen = sTime.Length; if (iLen < 6) { sTime = "0" + sTime; } else { break; } } sHH = sTime.Substring(0,2); sMM = sTime.Substring(2,2); sSS = sTime.Substring(4,2); sPath = sPathDir + "\\" + sDate + "x" + sHH + sMM + "00" + ".txt"; bFileFound = false; if (File.Exists(sPath)) { bFileFound = true; } else { //this is necessary because the lower time frame chart may fire before the higher sHH = sTime.Substring(0,2); // and the needed file will not be available yet, sMM = sTime.Substring(2,2); //so, get it on the next pass sSS = sTime.Substring(4,2); for (iLoop=0;iLoop<9;iLoop++) { iMM = Int32.Parse(sMM); if (iMM > 0) { iMM = iMM - 1; } else { break; } if (iMM < 10) { sMM = "0" + iMM; } else { sMM = "" + iMM; } sPath = sPathDir + "\\" + sDate + "x" + sHH + sMM + "00" + ".txt"; if (File.Exists(sPath)) { bFileFound = true; //Print("adjusted path is :" + sPath ); break; } } } // if (bFileFound == false) { //Print("get path not fnd: " + sPath); return; } try { sLine = File.ReadAllText(sPath); } catch (Exception ax) { Print("ax, " + ax.ToString()); } //split the line at every comma. Places each part into the string array string [] sArray = sLine.Split(new Char [] {','}); int iSplitCounter = 0; //For every string inside the newly created string array... foreach (string sOne in sArray) { if (sOne == "x") break; iSplitCounter++; if (iSplitCounter == 1) Plot0.Set(Double.Parse(sOne)); if (iSplitCounter == 2) Plot1.Set(Double.Parse(sOne)); if (iSplitCounter == 3) Plot2.Set(Double.Parse(sOne)); if (iSplitCounter == 4) Plot3.Set(Double.Parse(sOne)); if (iSplitCounter == 5) Plot4.Set(Double.Parse(sOne)); if (iSplitCounter == 6) Plot5.Set(Double.Parse(sOne)); if (iSplitCounter == 7) Plot6.Set(Double.Parse(sOne)); if (iSplitCounter == 8) Plot7.Set(Double.Parse(sOne)); if (iSplitCounter == 9) Plot8.Set(Double.Parse(sOne)); } return; } #region Properties [Description("input file suffix")] [Category("Parameters")] public string SFileSuffix { get { return sFileSuffix; } set { sFileSuffix = value; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties diaput, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries Plot0 { get { return Values[0]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties diaput, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries Plot1 { get { return Values[1]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties diaput, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries Plot2 { get { return Values[2]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties diaput, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries Plot3 { get { return Values[3]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties diaput, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries Plot4 { get { return Values[4]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties diaput, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries Plot5 { get { return Values[5]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties diaput, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries Plot6 { get { return Values[6]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties diaput, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries Plot7 { get { return Values[7]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties diaput, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries Plot8 { get { return Values[8]; } } #endregion } } #region NinjaScript generated code. Neither change nor remove. // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { public partial class Indicator : IndicatorBase { private zLOGget[] cachezLOGget = null; private static zLOGget checkzLOGget = new zLOGget(); /// /// zLOGget /// /// public zLOGget zLOGget(string sFileSuffix) { return zLOGget(Input, sFileSuffix); } /// /// zLOGget /// /// public zLOGget zLOGget(Data.IDataSeries input, string sFileSuffix) { checkzLOGget.SFileSuffix = sFileSuffix; sFileSuffix = checkzLOGget.SFileSuffix; if (cachezLOGget != null) for (int idx = 0; idx < cachezLOGget.Length; idx++) if (cachezLOGget[idx].SFileSuffix == sFileSuffix && cachezLOGget[idx].EqualsInput(input)) return cachezLOGget[idx]; zLOGget indicator = new zLOGget(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; indicator.Input = input; indicator.SFileSuffix = sFileSuffix; indicator.SetUp(); zLOGget[] tmp = new zLOGget[cachezLOGget == null ? 1 : cachezLOGget.Length + 1]; if (cachezLOGget != null) cachezLOGget.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cachezLOGget = tmp; Indicators.Add(indicator); return indicator; } } } // This namespace holds all market analyzer column definitions and is required. Do not change it. namespace NinjaTrader.MarketAnalyzer { public partial class Column : ColumnBase { /// /// zLOGget /// /// [Gui.Design.WizardCondition("Indicator")] public Indicator.zLOGget zLOGget(string sFileSuffix) { return _indicator.zLOGget(Input, sFileSuffix); } /// /// zLOGget /// /// public Indicator.zLOGget zLOGget(Data.IDataSeries input, string sFileSuffix) { return _indicator.zLOGget(input, sFileSuffix); } } } // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { public partial class Strategy : StrategyBase { /// /// zLOGget /// /// [Gui.Design.WizardCondition("Indicator")] public Indicator.zLOGget zLOGget(string sFileSuffix) { return _indicator.zLOGget(Input, sFileSuffix); } /// /// zLOGget /// /// public Indicator.zLOGget zLOGget(Data.IDataSeries input, string sFileSuffix) { if (InInitialize && input == null) throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method"); return _indicator.zLOGget(input, sFileSuffix); } } } #endregion