NinjaTrader Support Forum  

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

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 06-29-2011, 06:44 AM   #1
Viper3
Junior Member
 
Join Date: Jul 2007
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default One Alert per bar

I am using the Wizard. My strategy is a cross of the zeroline and want to have it give one Alert per bar. Right now it gives alerts for everytime the price moves. I am not a programmer, so any help would be great. I added emails to the alert and yes I am getting alot of emails......lol
Attached Images
File Type: jpg $EURUSD (9 Min) 6_14_2011.jpg (139.8 KB, 11 views)
Viper3 is offline  
Reply With Quote
Old 06-29-2011, 07:25 AM   #2
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
Default

Hello,

Thanks for the forum post!

The best way to change this to once per bar is to change the indicator to only calculate once per bar instead of on each tick. To do this right click on the chart and go to strategies. Then change the setting for Calculate On Bar Close to true. This will cause the code to run only once per bar which will be what your looking for on your alert.

Let me know if I can be of further assistance.
NinjaTrader_Brett is offline  
Reply With Quote
Old 06-29-2011, 09:22 AM   #3
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,199
Thanks: 24
Thanked 1,225 times in 996 posts
Send a message via Skype™ to koganam
Default

Quote:
Originally Posted by Viper3 View Post
I am using the Wizard. My strategy is a cross of the zeroline and want to have it give one Alert per bar. Right now it gives alerts for everytime the price moves. I am not a programmer, so any help would be great. I added emails to the alert and yes I am getting alot of emails......lol
How is your alert being triggered?
Can you post the line which triggers the alert ?
koganam is offline  
Reply With Quote
Old 06-29-2011, 10:32 AM   #4
Viper3
Junior Member
 
Join Date: Jul 2007
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default

I can post the step by step of the strategy if you like or email it.
Viper3 is offline  
Reply With Quote
Old 06-29-2011, 10:47 AM   #5
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,199
Thanks: 24
Thanked 1,225 times in 996 posts
Send a message via Skype™ to koganam
Default

Quote:
Originally Posted by Viper3 View Post
I can post the step by step of the strategy if you like or email it.
OK. Just post the entire text to the forum. Or the step by step if you wish.
koganam is offline  
Reply With Quote
Old 06-30-2011, 09:40 AM   #6
Viper3
Junior Member
 
Join Date: Jul 2007
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default

{
#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(WoodiesCCI(
2, 5, 50, 34, 25, 14, 60, 100, 2));
Add(WoodiesCCI(
2, 5, 50, 34, 25, 14, 60, 100, 2));
CalculateOnBarClose =
true;
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
// Condition set 1
if (CrossAbove(WoodiesCCI(2, 5, 50, 34, 25, 14, 60, 100, 2), 0, 1))
{
DrawArrowUp(
"My up arrow" + CurrentBar, false, 0, Low[0], Color.Lime);
PlaySound(
@"C:\Program Files\NinjaTrader 7\sounds\Alert1.wav");
SendMail(
"caragiom@gmail.com", "caragiom@gmail.com", "Alert Trade 9 minute chart", "Go long set stop at 30 T1 @20");
}
Viper3 is offline  
Reply With Quote
Old 06-30-2011, 09:44 AM   #7
Viper3
Junior Member
 
Join Date: Jul 2007
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default

So I need to put it under Variables. can you help me write that part. I did this but it need to be written right.

region Variables


// Wizard generated variables


private int 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.


/// boot alreadyAlertThis = false;


/// OnBarUpdate()


/// {


/// if (FirstTickOfBar)


/// {alreadyAlertThisBar=false;}


/// if(alert conditions == true&& alreadyAlertThisBar == false)


/// {


/// Alert(.....)


/// alreadyAlertThisBar = true;


/// }


/// }


///
Viper3 is offline  
Reply With Quote
Old 06-30-2011, 11:39 AM   #8
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,199
Thanks: 24
Thanked 1,225 times in 996 posts
Send a message via Skype™ to koganam
Default

See what happens with this. You cannot do it in the wizard, You are going to have to unlock the code.

Code:
private bool boolAlertSounded = false; // declare and intialize the bool flag

protected override void OnBarUpdate()
{
if (FirstTickOfBar) boolAlertSounded = false; //reset the bool flag at the start of the bar
// Condition set 1
if (CrossAbove(WoodiesCCI(2, 5, 50, 34, 25, 14, 60, 100, 2), 0, 1))
{
DrawArrowUp(
"My up arrow" + CurrentBar, false, 0, Low[0], Color.Lime);
if (!boolAlertSounded) PlaySound(
@"C:\Program Files\NinjaTrader 7\sounds\Alert1.wav"); // only if bool flag is false, play sound
SendMail(
"caragiom@gmail.com", "caragiom@gmail.com", "Alert Trade 9 minute chart", "Go long set stop at 30 T1 @20");
boolAlertSounded = true; // set the bool flag to stop sound play
}
koganam 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
email alert every bar close meirba Miscellaneous Support 1 03-26-2011 10:16 PM
sound alert() for a big bar crmcwi Indicator Development 2 05-11-2010 05:30 AM
Alert set to once per bar blarouche Indicator Development 4 08-18-2009 09:12 AM
audio alert upon completion of a bar stephenszpak Market Analyzer 18 05-10-2009 01:57 AM
Alert on new bar? tradingcube Charting 2 02-03-2009 12:22 PM


All times are GMT -6. The time now is 05:51 AM.