Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Basic Donchian Channel Breakout
Collapse
X
-
Basic Donchian Channel Breakout
I have read the thread on May 2011 about a basic Donchian Channel Breakout to create in the Strategy Wizard... I see the code that you wrote but all I am trying to do is set an alarm when the price goes above or below a certain number of ticks of previous bar... seems simple but I have spent several weeks on this now and might be close but can't get it to work... I have setup a Ninjascript strategy and it looks good on chart but no alert... any help will be appreciated... thanks
Tags: None
-
thanks...I had to delete some
thanks...I had to delete some
///<summary>
/// Donchian channel alert
///</summary>
[Description("Donchian channel alert")]
publicclass Donchianchannelalert : Strategy
{
#region Variables
// Wizard generated variables
privateint myInput0 = 1; // Default setting for MyInput0
// User defined variables (add any user defined variables below)
#endregion
///<summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
///</summary>
protectedoverridevoid Initialize()
{
Add(DonchianChannel(1));
Add(DonchianChannel(1));
CalculateOnBarClose = false;
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
// Condition set 1
if (CrossBelow(DonchianChannel(1).Upper, DonchianChannel(1).Lower, 1))
{
Alert("MyAlert0", Priority.High, "Donchian Channel Alert", @"C:\Program Files (x86)\NinjaTrader 7\sounds\Alert1.wav", 10, Color.White, Color.Black);
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
publicint MyInput0
{
get { return myInput0; }
set { myInput0 = Math.Max(0, value); }
}
#endregion
Comment
-
You have this as your evaluation condition.
if (CrossBelow(DonchianChannel(1).Upper, DonchianChannel(1).Lower, 1))- By the definition of a channel of any kind, the channel lower line can never cross the channel upper line.
- Your channel length of 1 is equivalent to price, so in effect you are actually asking for when the High of the bar crosses below the Low of the bar.
What it means is that your condition can never be triggered.
Maybe if you stated in words what you are trying to code, we might be able to supply a snippet?
Comment
-
Thanks... I will try and fix that and see what happens... what I am trying to accomplish is that if the price goes 5 ticks above the previous bar... or goes 5 ticks below the previous bar... it will set off an alert... seems the Donchian Channel is the best indicator showing the high and low of the previous bar.
Comment
-
5 ticks above the previous bar:Originally posted by chuckmorman3 View PostThanks... I will try and fix that and see what happens... what I am trying to accomplish is that if the price goes 5 ticks above the previous bar... or goes 5 ticks below the previous bar... it will set off an alert... seems the Donchian Channel is the best indicator showing the high and low of the previous bar.
5 ticks below previous barCode:if (High[0] >= High[1] + (5 * TickSize)) { // do something }
Using the Donchian Channel to get the High and Low of a bar, when you can reference the same directly is kind of doing unecessary calculations, and not very efficient. Technically, it is not wrong. It just seems like a lot of extra work that may not be needed.Code:if (Low[0] <= Low[1] - (5 * TickSize)) { // do something }
Comment
-
This is the first time I have tried using NinjaScript... I am now watching the chart and placing orders accordingly... and alert would be very helpful so if there is an easier way please inform me... thank you for your help
This is the code I have tried without an offset
#regionUsingdeclarations
usingSystem;
usingSystem.ComponentModel;
usingSystem.Diagnostics;
usingSystem.Drawing;
usingSystem.Drawing.Drawing2D;
usingSystem.Xml.Serialization;
usingNinjaTrader.Cbi;
usingNinjaTrader.Data;
usingNinjaTrader.Indicator;
usingNinjaTrader.Gui.Chart;
usingNinjaTrader.Strategy;
#endregion
//Thisnamespaceholdsallstrategiesandisrequired.Donot changeit.
namespaceNinjaTrader.Strategy
{
///<summary>
///abovepreviousbar
///</summary>
[Description("abovepreviousbar")]
publicclassAbovepreviousbar:Strategy
{
#regionVariables
//Wizardgeneratedvariables
privateintmyInput0=1;//DefaultsettingforMyInput0
//Userdefinedvariables(addanyuserdefinedvariablesbel ow)
#endregion
///<summary>
///Thismethodisusedtoconfigurethestrategyandiscalledo ncebeforeanystrategymethodiscalled.
///</summary>
protectedoverridevoidInitialize()
{
CalculateOnBarClose=false;
}
///<summary>
///Calledoneachbarupdateevent(incomingtick)
///</summary>
protectedoverridevoidOnBarUpdate()
{
//Conditionset1
if(GetCurrentAsk()>=HighestBar(DefaultInput,1)
&&GetCurrentAsk()<=LowestBar(DefaultInput,1))
{
Alert("MyAlert2",Priority.High,"hilowalert",@"C:\P rogramFiles(x86)\NinjaTrader7\sounds\Alert1.wav",1 0,Color.White,Color.Black);
}
}
#regionProperties
[Description("")]
[GridCategory("Parameters")]
publicintMyInput0
{
get{returnmyInput0;}
set{myInput0=Math.Max(1,value);}
}
#endregion
}
}
#regionWizardsettings,neitherchangenorremove
Last edited by chuckmorman3; 07-22-2011, 02:45 PM.
Comment
-
It really has little to do with NinjaScript, and everything to do with your code logic. No matter the language, if your conditions never trigger, then your alert will not trigger either.
I am not sure that I know what you are seeking now. The response to which you replied translated your conditions into NinjaScript for you. Are you posting this other code because you want to use the Ask price rather than the historical prices of the last bar that closed?
If you breakdown the logic of your code, you will see that you have specified an impossible condition. Nothing can both be greater than the high and simultaneously less than the low; which is what you have coded. The dual equality condition means that your alert can only be triggered if the last bar is a doji and the Ask price hits the closing price of said doji.Last edited by koganam; 07-25-2011, 06:46 PM.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
558 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
324 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
545 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
547 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment