Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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
-
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.
Code:if (High[0] >= High[1] + (5 * TickSize)) { // do something }
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 ghoul, Today, 06:02 PM
|
0 responses
7 views
0 likes
|
Last Post
by ghoul
Today, 06:02 PM
|
||
Started by Barry Milan, Yesterday, 10:35 PM
|
6 responses
18 views
0 likes
|
Last Post
by Barry Milan
Today, 06:01 PM
|
||
Started by DanielSanMartin, Yesterday, 02:37 PM
|
2 responses
13 views
0 likes
|
Last Post Today, 05:26 PM | ||
Started by DJ888, 04-16-2024, 06:09 PM
|
4 responses
13 views
0 likes
|
Last Post
by DJ888
Today, 04:28 PM
|
||
Started by terofs, Today, 04:18 PM
|
0 responses
12 views
0 likes
|
Last Post
by terofs
Today, 04:18 PM
|
Comment