public static void DrawVerticalLineBlinking(NinjaTrader.NinjaScript.NinjaScriptBase indi_or_strat, int idx)
        {
            try{
                int rand = new Random().Next(100000);
                RemoveDrawObject(indi_or_strat, "Debugger_CurrentBarVLine" + randLast);
                int  clicked_Bar = indi_or_strat.CurrentBars[0] - idx + (indi_or_strat.BarsPeriod.BarsPeriodType == BarsPeriodType.Day ? 1 : 0);                //don't know, on daily was displaced
                Bars bars        = indi_or_strat.BarsArray[0];
                if (clicked_Bar + 1 >= indi_or_strat.Bars.Count)
                {
                    return;                     //I donno, I couldn't make it work on last bar, so just hide it
                }
                //NinjaTrader.NinjaScript.DrawingTools.Draw.VerticalLine(indi_or_strat, "Debugger_CurrentBarVLine"+rand, idx, Brushes.Orange, DashStyleHelper.DashDot, 2);
                var time = bars.GetTime(clicked_Bar).AddSeconds(-ChartInSeconds(indi_or_strat) / 6);
                NinjaTrader.NinjaScript.DrawingTools.Draw.VerticalLine(indi_or_strat, "Debugger_CurrentBarVLine" + rand, time, Brushes.Orange, DashStyleHelper.DashDot, 2);

                // in 5 seconds, remove it
                System.Threading.Timer timer = null;
                timer = new System.Threading.Timer(
                    (object state) => {
                    RemoveDrawObject(indi_or_strat, "Debugger_CurrentBarVLine" + rand);
                    timer.Dispose();
                }
                    , null                    // no state required
                    , TimeSpan.FromSeconds(5) // Do it in x seconds
                    , TimeSpan.FromMilliseconds(-1)
                    );                        // don't repeat

                randLast = rand;
            }
            catch (Exception ex)
            {
                indi_or_strat.Print(ex.ToString());
            }
        }
Beispiel #2
0
        public void init_or_deinit(object indi_or_strat_, bool init)
        {
            if (init && indi_or_strat == null)
            {
                indi_or_strat = (NinjaTrader.NinjaScript.NinjaScriptBase)indi_or_strat_;

                if (indi_or_strat_ is NinjaTrader.NinjaScript.IndicatorBase)
                {
                    indi         = (NinjaTrader.NinjaScript.Indicators.Indicator)indi_or_strat_;
                    chartControl = indi.ChartControl;
                    chartPnl     = indi.ChartControl.ChartPanels[0];
                    chartBars    = indi.ChartBars;
                }
                else if (indi_or_strat_ is NinjaTrader.NinjaScript.Strategies.Strategy)
                {
                    strat        = (NinjaTrader.NinjaScript.Strategies.Strategy)indi_or_strat_;
                    chartControl = strat.ChartControl;
                    chartPnl     = strat.ChartControl.ChartPanels[0];
                    chartBars    = strat.ChartBars;
                }

                if (chartControl == null || chartPnl == null)
                {
                    enabled = false; return;
                }

                enabled = true;
                registerEventHandlers();
            }
            else
            {
                checkForDeregister();
            }
        }
        public static int ChartInSeconds(NinjaTrader.NinjaScript.NinjaScriptBase NS_)
        {
            int final_val = 0;

            if (NS_.BarsPeriod.BarsPeriodType == BarsPeriodType.Second)
            {
                final_val = NS_.BarsPeriod.Value;
            }
            else if (NS_.BarsPeriod.BarsPeriodType == BarsPeriodType.Minute)
            {
                final_val = NS_.BarsPeriod.Value * 60;
            }
            else if (NS_.BarsPeriod.BarsPeriodType == BarsPeriodType.Day)
            {
                final_val = NS_.BarsPeriod.Value * 60 * 60 * 24;
            }
            else if (NS_.BarsPeriod.BarsPeriodType == BarsPeriodType.Week)
            {
                final_val = NS_.BarsPeriod.Value * 60 * 60 * 24 * 7;
            }
            else if (NS_.BarsPeriod.BarsPeriodType == BarsPeriodType.Month)
            {
                final_val = NS_.BarsPeriod.Value * 60 * 60 * 24 * 7 * 30;
            }
            else if (NS_.BarsPeriod.BarsPeriodType == BarsPeriodType.Year)
            {
                final_val = NS_.BarsPeriod.Value * 60 * 60 * 24 * 7 * 365;
            }
            return(final_val);
        }
Beispiel #4
0
 public static string barIdentifier(object NinjaScript_, int idx)
 {
     NinjaTrader.NinjaScript.NinjaScriptBase obj = (NinjaTrader.NinjaScript.NinjaScriptBase)NinjaScript_;
     if (obj.CurrentBars[0] < 1)
     {
         return("");
     }
     return(sanitize_filename(getNinjaScriptIdentifier(obj, true) + "--" + obj.BarsArray[0].GetTime(obj.CurrentBars[0] - idx).ToString("yyyy-MM-dd_HH-mm-ss"), ""));
 }
Beispiel #5
0
 public static string getNinjaScriptIdentifier(object NinjaScript_, bool include_script_name)
 {
     NinjaTrader.NinjaScript.NinjaScriptBase obj = (NinjaTrader.NinjaScript.NinjaScriptBase)NinjaScript_;
     return(sanitize_filename((include_script_name ? obj.Name + "_" : "") + obj.Instrument.FullName + "--" + obj.BarsArray[0].BarsPeriod.BarsPeriodType.ToString() + "-" + obj.BarsArray[0].BarsPeriod.Value.ToString(), ""));
 }