Exemplo n.º 1
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description              = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionRangeCounter;
                Name                     = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameRangeCounter;
                Calculate                = Calculate.OnPriceChange;
                CountDown                = true;
                DisplayInDataBox         = false;
                DrawOnPricePanel         = false;
                IsOverlay                = true;
                IsChartOnly              = true;
                IsOverlay                = true;
                IsSuspendedWhileInactive = true;
            }
            else if (State == State.Historical)
            {
                isAdvancedType = BarsPeriod.BarsPeriodType == BarsPeriodType.HeikenAshi || BarsPeriod.BarsPeriodType == BarsPeriodType.Volumetric;
                bool isOtherType = BarsPeriod.ToString().IndexOf("Range") >= 0 || BarsPeriod.ToString().IndexOf(NinjaTrader.Custom.Resource.BarsPeriodTypeNameRange) >= 0;

                if (BarsPeriod.BarsPeriodType == BarsPeriodType.Range ||
                    BarsPeriod.BaseBarsPeriodType == BarsPeriodType.Range && isAdvancedType ||
                    BarsArray[0].BarsType.BuiltFrom == BarsPeriodType.Tick && isOtherType)
                {
                    supportsRange = true;
                }
            }
        }
        protected override void OnBarUpdate()
        {
            if (BarsInProgress != 0 || CurrentBar < BarsRequiredToTrade)
            {
                return;
            }

////////////Instrument Variable Setting/////////
            instrument        = Instrument != null ? Instrument.FullName : "UndefInstrument";
            fileDirectoryPath = ninjaDirectory + instrument;
            barType           = BarsPeriod.ToString();
            barValue          = BarsPeriod.Value.ToString();
            daysLoaded        = ChartBars.Properties.DaysBack;
            strategyInfo      = strategyInfo + "," + instrument + "," + barValue + "," + barType + "," + daysLoaded + "," + LookbackSetting + "," + LookbackSources + "," + SwingStrength + "," + VolOffSetCheck + "," + VolOffsetRatio;
            instrumentType    = instrument + "." + BarsPeriod.ToString();
            pathCSV           = fileDirectoryPath + "/" + instrumentType + daysLoaded + "days" + "." + LookbackSources + LookbackSetting + SwingStrength + "ss" + VolOffsetRatio + "volr" + "." + fileName;                                                  // Define the Path to our test file

            if (!Directory.Exists(fileDirectoryPath))
            {
                Directory.CreateDirectory(fileDirectoryPath);
            }

////////////Data Variable Setting////////////

            dataIndex       = (CurrentBar - 1);
            ntStockData     = CurrentBar + "," + Time[0] + "," + Open[0] + "," + High[0] + "," + Low[0] + "," + Close[0];
            auroraStockData = indiTachAur.TrendPlot.GetValueAt(dataIndex) + "," + indiTachAur.BarsToNextSignal.GetValueAt(dataIndex) + "," + indiTachAur.BarsFromPreviousSignal.GetValueAt(dataIndex) + "," + indiTachAur.SignalPattern.GetValueAt(dataIndex) + "," + indiTachAur.BuySignalStopLine.GetValueAt(dataIndex) + "," + indiTachAur.SellSignalStopLine.GetValueAt(dataIndex) + "," + indiTachAur.DotPrice.GetValueAt(dataIndex) + "," + indiTachAur.OpenPrice.GetValueAt(dataIndex);
            fullPrintOut    = ntStockData + "," + auroraStockData;

////////////Printing area////////////

            if (!File.Exists(pathCSV))
            {
                sw = File.AppendText(pathCSV);
                sw.WriteLine(strategyLabels);
                sw.WriteLine(strategyInfo);
                sw.WriteLine(labels);
                sw.Close();
            }
            else
            {
                Print("string.Format(fullPrintOut)");
                Print(string.Format(fullPrintOut));
                sw = File.AppendText(pathCSV);
                sw.WriteLine(fullPrintOut); // Append a new line to the file
                sw.Close();                 // Close the file to allow future calls to access the file again.
            }
        }