View Full Version : Checking for cross over conditions and generating an alert
NinjaTrader_Ray
01-31-2007, 10:52 AM
Attached is an indicator that will check for a cross over condition of two simple moving averages. It will:
- Plot a dot on the bar of the cross over condition
- Generate an an alert to the "Alerts" window and play a sound on a cross over condition on real-time data only
To use or reviewthe code for this indicator:
- Unzip the contents of this file to "My Documents\NinjaTrader 6\bin\Custom\Indicator"
- Start NT
- Tools > Edit NinjaScript > Open CrossAlert
- Compile from within the NinjaScript Editor by pressing the F5 key
- Apply to a chart
Ray
randyjb
02-20-2007, 07:54 PM
Oddly, I have downloaded this crossover custom indicator zip file and extracted the crossover.cs fileto the exact directory and folder in NT 6 as noted (and even gone to that folder to note that it is the only custom indicator file there) but when I then load up NT6 and go to Tools, Edit Ninja Script and try to then find the CrossOver indicator.. it is nowhere to be found in the list.
Any idea what I am doing wrong? I had no problem with the NT 5 custom indicators but I can't seem to get this to work at all. I have also noticed, that unlike in NT5, the file I extracted and put in that folder, is not preceded by an @, not that it has anything to do with it. Can you suggest a work around or is there a glitch in NT6 yet to be fixed such that we should not be trying to download custom indicators into the latest beta version yet.
Thanks in advance for any help you can provide...
Randy
NinjaTrader_Ray
02-21-2007, 02:46 AM
If you are on the latest beta (7), its located under My Documents\NinjaTrader 6\bin\Custom\Indicator
randyjb
02-21-2007, 01:05 PM
Thanks.. I tried that. First I went and deleted it from the prior location to which I had extracted it. Then downloaded the original again and extracted it to that new location that is under MyDocuments instead of ProgramFiles. When I opened up NT V6 and clicked on tools, the indicator was listed this time. However, when I clicked ok and then went to compile, I got the following error message instead of the "ok" check box:
'NinjaTrader.Cbi.Globals' does not contain a definition for 'InstallDir' File: Indicator/CrossAlert.cs Line: 53 Column: 92
and a second instance of that same exact error message right below that but this one showed location of Line: 62 Column:92
If you have a solution, do please let me know.
Thanks...
NinjaTrader_Ray
02-21-2007, 01:09 PM
Open up the file via Tools > Edit NinjaScript > Indicator
Replace "Cbi.Globals.InstallDir"
with "Cbi.Core.InstallDir"
and recompile. This should take care of it.
Ray
ezduzzit
02-21-2007, 03:19 PM
Ray.. Thanks for the prompt turnaround.. it now loads up just fine. I edited it to use the much faster hull moving averages and it seems to be very accurate. Thanks again. It also mentions that this indicator provides an alert box and alert sound. I frankly had no idea thatNT Version 6 had those capabilities at this stage. Does it or are those something still to come in the future?
Thanks,
Randy
NinjaTrader_Ray
02-22-2007, 01:52 AM
It has Alert capabilitiesat this stage ;)
crosscreek
06-11-2010, 12:09 PM
I can't get this to appear on NT7. Is it possible/ Thanks.
NinjaTrader_RyanM
06-11-2010, 12:28 PM
Hello CrossCreak,
I've changed it so that it now works in version 7.
To Import
1. Download the attached file to your desktop
2. From the Control Center window select the menu File > Utilities > Import NinjaScript
3. Select the downloaded file
crosscreek
06-11-2010, 12:35 PM
Fantastic! Many thanks.
crosscreek
06-15-2010, 11:12 AM
Works great, but the alert1 sound is rather jarring. I changed the code to alert4, but it still generates alert1 sound. Is there a way to do this, or it can't be changed?
Thanks again.
NinjaTrader_RyanM
06-15-2010, 12:11 PM
Hi Crosscreek,
You should just be able to change the .wav file used to whatever you like. There are two alert statements. One plays Alert1 and the other plays Alert2.
If it hasn't responded to your changes, make sure you compile and then add and remove the indicator.
crosscreek
06-28-2010, 09:16 PM
Hi Crosscreek,
You should just be able to change the .wav file used to whatever you like. There are two alert statements. One plays Alert1 and the other plays Alert2.
If it hasn't responded to your changes, make sure you compile and then add and remove the indicator.
Thanks again. One last question, if I may. I tried to change the code to ema cross but when I load it back in the indicator file it does not show up. What am I doing wrong?
NinjaTrader_Bertrand
06-29-2010, 06:30 AM
Did you compile by pressing F5 after putting your changes in?
http://www.ninjatrader-support.com/HelpGuideV6/Overview18.html
crosscreek
06-29-2010, 11:42 AM
Getting error code CS0101, clicked for info then get:
Unfortunately we do not have NinjaScript context based Help information on this specific error code. You can check the Microsoft MSDN site section on error codes for futher information.
NinjaTrader_RyanM
06-29-2010, 11:53 AM
Hi Crosscreek,
Unfortunately we can't assist with just an error code #. Let us know the offending line of code and the descriptive text found under the Error column. You can also attach the indicator file and I'll take a look.
crosscreek
06-29-2010, 11:57 AM
Line 20, column 18
public class CrossAlert : Indicator
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
///
/// </summary>
[Description("")]
[Gui.Design.DisplayName("")]
public class CrossAlert : Indicator
{
#region Variables
// Wizard generated variables
private int fast = 5; // Default setting for Fast
private int slow = 15; // Default setting for Slow
// User defined variables (add any user defined variables below)
#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()
{
Fast = 5;
Slow = 15;
CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (CrossAbove(EMA(Fast), EMA(Slow), 1))
{
// Mark the cross above bar with a green dot
DrawDot("Dot1 " + CurrentBar, true, 0, High[0] + TickSize, Color.Green);
// Only generate an alert on real-time data
if (!Historical)
Alert(Time[0].ToString(), NinjaTrader.Cbi.Priority.Medium, "Cross Above", Cbi.Core.InstallDir + @"\sounds\Alert1.wav", 0, Color.Black, Color.Yellow);
}
else if (CrossBelow(EMA(Fast), EMA(Slow), 1))
{
// Mark the cross below bar with a red dot
DrawDot("Dot2 " + CurrentBar, true, 0, Low[0] - TickSize, Color.Red);
// Only generate an alert on real-time data
if (!Historical)
Alert(Time[0].ToString(), NinjaTrader.Cbi.Priority.Medium, "Cross Below", Cbi.Core.InstallDir + @"\sounds\Alert2.wav", 0, Color.Yellow, Color.Black);
}
}
#region Properties
[Description("Fast period")]
[Category("Parameters")]
public int Fast
{
get { return fast; }
set { fast = Math.Max(1, value); }
}
[Description("Slow period")]
[Category("Parameters")]
public int Slow
{
get { return slow; }
set { slow = 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 CrossAlert[] cacheCrossAlert = null;
private static CrossAlert checkCrossAlert = new CrossAlert();
/// <summary>
///
/// </summary>
/// <returns></returns>
public CrossAlert CrossAlert(int fast, int slow)
{
return CrossAlert(Input, fast, slow);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public CrossAlert CrossAlert(Data.IDataSeries input, int fast, int slow)
{
if (cacheCrossAlert != null)
for (int idx = 0; idx < cacheCrossAlert.Length; idx++)
if (cacheCrossAlert[idx].Fast == fast && cacheCrossAlert[idx].Slow == slow && cacheCrossAlert[idx].EqualsInput(input))
return cacheCrossAlert[idx];
lock (checkCrossAlert)
{
checkCrossAlert.Fast = fast;
fast = checkCrossAlert.Fast;
checkCrossAlert.Slow = slow;
slow = checkCrossAlert.Slow;
if (cacheCrossAlert != null)
for (int idx = 0; idx < cacheCrossAlert.Length; idx++)
if (cacheCrossAlert[idx].Fast == fast && cacheCrossAlert[idx].Slow == slow && cacheCrossAlert[idx].EqualsInput(input))
return cacheCrossAlert[idx];
CrossAlert indicator = new CrossAlert();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.Fast = fast;
indicator.Slow = slow;
Indicators.Add(indicator);
indicator.SetUp();
CrossAlert[] tmp = new CrossAlert[cacheCrossAlert == null ? 1 : cacheCrossAlert.Length + 1];
if (cacheCrossAlert != null)
cacheCrossAlert.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheCrossAlert = tmp;
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>
///
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.CrossAlert CrossAlert(int fast, int slow)
{
return _indicator.CrossAlert(Input, fast, slow);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public Indicator.CrossAlert CrossAlert(Data.IDataSeries input, int fast, int slow)
{
return _indicator.CrossAlert(input, fast, slow);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
///
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.CrossAlert CrossAlert(int fast, int slow)
{
return _indicator.CrossAlert(Input, fast, slow);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public Indicator.CrossAlert CrossAlert(Data.IDataSeries input, int fast, int slow)
{
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.CrossAlert(input, fast, slow);
}
}
}
#endregion
NinjaTrader_RyanM
06-29-2010, 12:01 PM
What is the error message and what line is causing it?
crosscreek
06-29-2010, 12:26 PM
Getting
Line 20, column 18
line 20 is "public class CrossAlert : Indicator"
error code CS0101, clicked for info then get:
"Unfortunately we do not have NinjaScript context based Help information on this specific error code. You can check the Microsoft MSDN site section on error codes for futher information."
NinjaTrader_RyanM
06-29-2010, 12:39 PM
Hi Crosscreek,
Below are not valid statement in the Initialize() method:
Fast = 5;
Slow = 15;
Generally NinjaTrader does not provide debugging or custom coding service. We are glad to guide in the right direction or assist if there is any particular issue, but cannot resolve all types of coding errors.
If you have further issues with this indicator, please see the link below for a NinjaScript consultant who can be hired to debug for you.
http://www.ninjatrader.com/webnew/partners_onlinetrading_NinjaScript.htm
crosscreek
06-29-2010, 12:57 PM
Ok, thanks. It's a little confusing because that is exactly the line of code that is in the original, which works fine. I don't get why changing sma to ema does not work, but I guess there is nothing I can do about this.
crosscreek
06-29-2010, 10:21 PM
I figured out what was wrong, I did not change the title in the line of code to a new name.
julian nisbett
09-25-2010, 11:44 AM
when i try to complie it i get error .can u help get it work i use ninja 7
// Mark the cross below bar with a red dot
DrawDot(Time[0].ToString(), 0, Low[0] - TickSize, Color.Red);
NinjaTrader_Austin
09-25-2010, 01:23 PM
Julian, there is an extra parameter with all the drawing objects for NinjaTrader 7: the autoscale parameter.
Please try this line instead:
DrawDot(Time[0].ToString(), true, 0, Low[0] - TickSize, Color.Red)
The "true" is the additional parameter needed.