NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Sunday May 26th at 12PM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 07-21-2007, 12:11 PM   #1
Jibu V
Member
 
Join Date: Jul 2007
Posts: 32
Thanks: 0
Thanked 0 times in 0 posts
Default CCI w/ Audible Alert

I'm sorry if this has already been covered, but I am trying to create a custom indicator for the CCI that alerts when price crosses above/below +/-180. I am not an expert at programming, but I tried adjusting some previous code for a crossalert that I found here and this is what I came up with. The problem is that when I go to compile it, it gives an error stating that "The namespace 'NinjaTrader.Indicator' already contains a definition for 'CrossAlert'. If anyone could help me refine this, I'd GREATLY appreciate it! Here is my code:

#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
///
/// </summary>
[Description("")]
[Gui.Design.DisplayName("")]
public class CCIAlerts : 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()
{
Period = 45;
Slow = 15;
CalculateOnBarClose = false;
Overlay = true;
PriceTypeSupported = false;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (CrossAbove(CCI(Period), 180))
{
// Mark the cross above bar with a green dot
DrawDot(Time[0].ToString(), 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\Alert4.wav", 0, Color.Black, Color.Yellow);
}
else if (CrossBelow(CCI(Period), -180))
{
// Mark the cross below bar with a red dot
DrawDot(Time[0].ToString(), 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\Alert4.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 CCIAlerts[] cacheCCIAlerts = null;

private static CCIAlerts checkCCIAlerts = new CCIAlerts();

/// <summary>
///
/// </summary>
/// <returns></returns>
public CCIAlerts CCIAlerts(int fast, int slow)
{
return CCIAlerts(Input, fast, slow);
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public CCIAlerts CCIAlerts(Data.IDataSeries input, int fast, int slow)
{
checkCCIAlerts.Fast = fast;
fast = checkCCIAlerts.Fast;
checkCCIAlerts.Slow = slow;
slow = checkCCIAlerts.Slow;

if (cacheCCIAlerts != null)
for (int idx = 0; idx < cacheCCIAlerts.Length; idx++)
if (cacheCCIAlerts[idx].Fast == fast && cacheCCIAlerts[idx].Slow == slow && cacheCCIAlerts[idx].EqualsInput(input))
return cacheCCIAlerts[idx];

CCIAlerts indicator = new CCIAlerts();
indicator.SetUp();
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.Fast = fast;
indicator.Slow = slow;

CCIAlerts[] tmp = new CCIAlerts[cacheCCIAlerts == null ? 1 : cacheCCIAlerts.Length + 1];
if (cacheCCIAlerts != null)
cacheCCIAlerts.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheCCIAlerts = 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>
///
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.CCIAlerts CCIAlerts(int fast, int slow)
{
return _indicator.CCIAlerts(Input, fast, slow);
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public Indicator.CCIAlerts CCIAlerts(Data.IDataSeries input, int fast, int slow)
{
return _indicator.CCIAlerts(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.CCIAlerts CCIAlerts(int fast, int slow)
{
return _indicator.CCIAlerts(Input, fast, slow);
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public Indicator.CCIAlerts CCIAlerts(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.CCIAlerts(input, fast, slow);
}

}
}
#endregion
Jibu V is offline  
Reply With Quote
Old 07-21-2007, 11:58 PM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

You do have multiple implementations of the CrossAlert indiator. Just remove the superfluous ones and you will be good.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 07-22-2007, 04:12 PM   #3
Jibu V
Member
 
Join Date: Jul 2007
Posts: 32
Thanks: 0
Thanked 0 times in 0 posts
Default

I made several attempts with no luck All I need is a SIMPLE indicator that gives an audible alert when cci crosses +/- 180... I can't seem to get anything to compile without errors. It would be awesome if someone could help me with the code...
Jibu V is offline  
Reply With Quote
Old 07-22-2007, 11:17 PM   #4
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Just to double check: Before starting your efforts you need to make sure you NinjaScript files compile. Please verify by removing the erroneous file.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 08-03-2007, 09:04 AM   #5
Jibu V
Member
 
Join Date: Jul 2007
Posts: 32
Thanks: 0
Thanked 0 times in 0 posts
Default

Okay, so I managed to put together some code that compiles correctly. The code seems to be working - it triggers a sound when the CCI crosses above or below +/- 180. The problem now is getting it to stop repeating the sound repeatedly during the bar that it triggers. I tried inserting the "ResetAlerts" method but that didn't seem to do anything. Is there a way to set this so that the sound only goes off once and then resets until the next time it crosses above or below? Thanks.
protected override void Initialize()
{
CalculateOnBarClose = false;
PriceTypeSupported = true;
}

/// <summary>
/// Calculates the indicator value(s) at the current index.
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(CCI(45), 180, 1))
{
Alert("Short Signal", NinjaTrader.Cbi.Priority.High, "Short Signal", @"D:\NinjaTrader 6\sounds\Alert4.wav", 10, Color.Black, Color.Yellow);
ResetAlert("reset");
}

// Condition set 2
if (CrossBelow(CCI(45), -180, 1))
{
Alert("Long Signal", NinjaTrader.Cbi.Priority.High, "Long Signal", @"D:\NinjaTrader 6\sounds\Alert4.wav", 10, Color.Black, Color.Yellow);
ResetAlert("reset");
}
}
Jibu V is offline  
Reply With Quote
Old 08-03-2007, 09:08 AM   #6
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Unfortunately we are unable to provide support down to a level of actually coding or revising a strategy. Your might consider contacting a NinjaTrader consultant: http://www.ninjatrader.com/webnew/pa...injaScript.htm

Also: You might consider contacting this user who appears to deal with a similar issue: http://www.ninjatrader-support.com/v...ght=consultant
NinjaTrader_Dierk is offline  
Reply With Quote
Old 08-03-2007, 09:09 AM   #7
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

You will have to do some coding where you use variables to set flags when or when not to trigger the alerts.
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-03-2007, 09:33 AM   #8
Jibu V
Member
 
Join Date: Jul 2007
Posts: 32
Thanks: 0
Thanked 0 times in 0 posts
Default

Couldn't this work the same way as "rearming"? I had it set to 10 before but it repeatedly sounded the alert... I feel like this should be something very simple that I'm overlooking...
Jibu V is offline  
Reply With Quote
Old 08-03-2007, 09:47 AM   #9
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Some hints: By the looks of it there are several flaws in the code below:
- ResetAlerts("reset") resets and alert for ID "reset", but your code never sets such an alert
- why would you want to the reset and alert right after you submitted an alert?

Your might consider contacting a NinjaTrader consultant who could help you working on your actual strategy: http://www.ninjatrader.com/webnew/pa...injaScript.htm

Due to bandwidth reason we are unfortunately unable to provide support down to that level.

Thanks for your understanding.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 08-03-2007, 09:47 AM   #10
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Re-arm means that the alert will not sound even if you call the method for the duration of the re-arm time.
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-03-2007, 10:04 AM   #11
Jibu V
Member
 
Join Date: Jul 2007
Posts: 32
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Ray View Post
Re-arm means that the alert will not sound even if you call the method for the duration of the re-arm time.
That would actually be totally fine, as once I get a signal, I don't expect another one for several minutes. So, just to clarify, if I set the rearm time in the alert to 120 seconds, the signal will go off ONCE and then not look for or sound another alert until 120 seconds after the first signal, correct?? If so, that would be great...
Jibu V is offline  
Reply With Quote
Old 08-03-2007, 11:06 AM   #12
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

That is correct.
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-03-2007, 11:08 AM   #13
Jibu V
Member
 
Join Date: Jul 2007
Posts: 32
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks for your help, Ray!
Jibu V is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Audible Indicator Alerts? Jibu V Miscellaneous Support 9 07-07-2010 01:12 AM
Alert() AO76 Strategy Development 5 05-27-2007 09:21 AM
Alert on cross over/under scjohn Market Analyzer 5 05-25-2007 07:21 AM
Ninjatrader alert nasdaq5048 Miscellaneous Support 1 08-09-2006 06:36 AM
Primary Connection alert on Control Panel tazman Suggestions And Feedback 1 06-15-2006 12:46 AM


All times are GMT -6. The time now is 09:24 PM.