View Full Version : ReloadNinjaScript()
rcsingleton
04-21-2008, 12:02 PM
Hello.
I've got a request for a new NT function. I'd like to be able to do the following :
if (FirstTickofBar)
{
ReloadNinjaScript()
}
It would be great to have an automated way of reloading the active Ninjascript running on the chart.
Regards,
R. C.
NinjaTrader_Ray
04-21-2008, 12:30 PM
Thanks for the suggestion.
rcsingleton
04-30-2008, 11:39 AM
Hello.
Not sure if you have the ReloadNinjaScript() function on your 'to do' list for NT 7, but either way, that's a long way off.
So, I would like to create a 'user defined function' that contains the code under 'F5 - Reload NinjaScript'.
Then I could assign that code to a function called ReloadNinjaScript().
And then use that function in an indicator.
Could you let me see the code under 'F5 - Reload NinjaScript' ?
NinjaTrader_Josh
05-01-2008, 01:53 AM
Unfortunately that is not supported.
Brutus
08-31-2009, 11:14 AM
I would also like to suggest an improvement for NT7
As a real time chart may have several ninjascripts running. when you do a reload you lose all the calculated data for the chart display.
Under inidicators I would like the ability to individually reload any indicator.
ie add a button RELOAD alongside ADD & REMOVE so you dont have to relaod every indicator and lose data.
Thank you
NinjaTrader_Josh
08-31-2009, 11:37 AM
Thank you for voicing your thoughts. I have forwarded them to development.
hemlock
09-01-2009, 06:55 PM
You could try this.
using System.Windows.Forms;
.
.
.
if (FirstTickOfBar)
{
SendKeys.Send("{F5}");
}
Light
03-13-2010, 08:15 AM
Thanks guys... I've been thinking about something similar and didn't know F5 would reinitialize the code ;-) -- thanks for the tip...
rcsingleton
03-31-2010, 03:40 PM
Hello.
Is there any way to do the following :
Every 120 seconds
{
SendKeys.Send("{F5}");
}
How do I set up a timer here to hit F5 every 120 seconds?
Thanks
NinjaTrader_Josh
03-31-2010, 03:47 PM
rcsingleton,
Please see here for creating your own custom events: http://www.ninjatrader-support2.com/vb/showthread.php?t=5965
rcsingleton
03-31-2010, 05:44 PM
I've got it. Thanks..
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
using System.Windows.Forms;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// This script will call the F5 key to reload the NT indicators
/// </summary>
[Description("This script will call the F5 key to reload the NT indicators")]
public class ReloadNinjaScript : Indicator
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
private int timeDelay = 120000;
private Timer myTimer = new Timer();
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar == 0)
{
// Initialize Timer object with an interval of timeDelay ms (timeDelay / 1000 = seconds)
myTimer.Tick += new EventHandler(TimerEventProcessor);
myTimer.Interval = timeDelay;
myTimer.Start();
}
}
// Timer's tick event handler. Called at every tick of timeDelay
private void TimerEventProcessor(Object myObject, EventArgs myEventArgs)
{
TriggerCustomEvent(MyCustomHandler, myTimer.Interval);
}
private void MyCustomHandler(object state)
{
SendKeys.Send("{F5}");
}
// Cleaning up
public override void Dispose()
{
base.Dispose(); // Needed when Dispose() is overriden
myTimer.Dispose();
}
#region Properties
[Description("")]
[Category("Parameters")]
public int TimeDelay
{
get { return timeDelay; }
set { timeDelay = Math.Max(1, value); }
}
#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 ReloadNinjaScript[] cacheReloadNinjaScript = null;
private static ReloadNinjaScript checkReloadNinjaScript = new ReloadNinjaScript();
/// <summary>
/// This script will call the F5 key to reload the NT indicators
/// </summary>
/// <returns></returns>
public ReloadNinjaScript ReloadNinjaScript(int timeDelay)
{
return ReloadNinjaScript(Input, timeDelay);
}
/// <summary>
/// This script will call the F5 key to reload the NT indicators
/// </summary>
/// <returns></returns>
public ReloadNinjaScript ReloadNinjaScript(Data.IDataSeries input, int timeDelay)
{
checkReloadNinjaScript.TimeDelay = timeDelay;
timeDelay = checkReloadNinjaScript.TimeDelay;
if (cacheReloadNinjaScript != null)
for (int idx = 0; idx < cacheReloadNinjaScript.Length; idx++)
if (cacheReloadNinjaScript[idx].TimeDelay == timeDelay && cacheReloadNinjaScript[idx].EqualsInput(input))
return cacheReloadNinjaScript[idx];
ReloadNinjaScript indicator = new ReloadNinjaScript();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.TimeDelay = timeDelay;
indicator.SetUp();
ReloadNinjaScript[] tmp = new ReloadNinjaScript[cacheReloadNinjaScript == null ? 1 : cacheReloadNinjaScript.Length + 1];
if (cacheReloadNinjaScript != null)
cacheReloadNinjaScript.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheReloadNinjaScript = 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
{
/// <summary>
/// This script will call the F5 key to reload the NT indicators
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.ReloadNinjaScript ReloadNinjaScript(int timeDelay)
{
return _indicator.ReloadNinjaScript(Input, timeDelay);
}
/// <summary>
/// This script will call the F5 key to reload the NT indicators
/// </summary>
/// <returns></returns>
public Indicator.ReloadNinjaScript ReloadNinjaScript(Data.IDataSeries input, int timeDelay)
{
return _indicator.ReloadNinjaScript(input, timeDelay);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// This script will call the F5 key to reload the NT indicators
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.ReloadNinjaScript ReloadNinjaScript(int timeDelay)
{
return _indicator.ReloadNinjaScript(Input, timeDelay);
}
/// <summary>
/// This script will call the F5 key to reload the NT indicators
/// </summary>
/// <returns></returns>
public Indicator.ReloadNinjaScript ReloadNinjaScript(Data.IDataSeries input, int timeDelay)
{
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.ReloadNinjaScript(input, timeDelay);
}
}
}
#endregion