![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Jul 2009
Location: Texas
Posts: 58
Thanks: 6
Thanked 0 times in 0 posts
|
i have an alert that i use but i cant seem to figure out how to make it only sound once when it is set to alerm on the bar close. Right now it will sound on each tick of the bar. I want the alert to sound once as soon as the the two lines it is looking at crosses on the current bar but not to sound on each tick jump. In other words i want it to be a live indicator i guess is what you would call it.
if(sMAD[1] > sMA[1] && sMAD[0] < sMA[0] && sTime[0] == 1) { if(!Historical && sTime[0] == 1) { vPlayCount = 3; PlaySound(iAlert); } } This is what i have for now. |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Hello cbart_1,
You could set CalculateOnBarClose = true and it will only check on bar close. If you want to run your script with COBC = false, but only want this evaluated at bar close, could work with FirstTickOfBar for this, by adding FirstTickOfBar to your condition and referencing 1 bar back like in this reference sample. FirstTickOfBar is also a good mechanism for resetting a bool flag that could control sound playback. if (myBool) { PlaySound(iAlert); myBool = false; } if (FirstTickOfBar) myBool = true;
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Jul 2009
Location: Texas
Posts: 58
Thanks: 6
Thanked 0 times in 0 posts
|
I meant i have the indicator calculate on bar close set to false. This way if the bar ticks going up or down make the lines cross i only want the alarm to sound once, because the bar ticks make the lines cross multiple times on 1 bar. I just want it to sound once. This way it wont sound the alarm on every tick in a 1, 5, 10, 15, or 30 minute bar.
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Thanks for the reply. Using a bool flag and resetting at FirstTickOfBar is a good option for this then.
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Jul 2009
Location: Texas
Posts: 58
Thanks: 6
Thanked 0 times in 0 posts
|
I used the FirstTickOfBar and made a variable true and made it false in the crossing code. So i think this way it should set it back to being true on the beginning of each bar.
if (FirstTickOfBar) { FBTick = true; } if(sMAD[1] > sMA[1] && sMAD[0] < sMA[0] && sTime[0] == 1 && FBTick == true) { if(!Historical && sTime[0] == 1) { vPlayCount = 3; PlaySound(iAlert); FBTick = false; } } |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Yes, that's close, but will also want to include a check to the bool flag before playing sound.
if (FBTick) { PlaySound(iAlert); FBTick = false; }
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Member
Join Date: Jul 2009
Location: Texas
Posts: 58
Thanks: 6
Thanked 0 times in 0 posts
|
Ok this is how i put it in my code but now i dont get an alarm.
if (FirstTickOfBar) { FBTick = true; } if(sMAD[1] > sMA[1] && sMAD[0] < sMA[0] && sTime[0] == 1) { if(!Historical && sTime[0] == 1) { if (FBTick) { vPlayCount = 3; PlaySound(iAlert); FBTick = false; } } } |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Sorry, I'm not sure why that wouldn't work. Using bool flags is a common technique for executing something only once. It does look like you took some other parts of your script and included it after the bool check. Maybe that part of your script needs to be executed more than once per bar? I would try using my previous two examples used, where only PlaySound and bool assignment executes after your FirstTick returns true.
It's also good to learn techniques for debugging and simplifying your code, so you can follow code flow and work through these types of issues. Please see here for help debugging: http://www.ninjatrader.com/support/f...ead.php?t=3418
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Member
Join Date: Jul 2009
Location: Texas
Posts: 58
Thanks: 6
Thanked 0 times in 0 posts
|
ok thank you it is someting wrong with my sound code. i will go through it and find out what is wrong.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| email alert every bar close | meirba | Miscellaneous Support | 1 | 03-26-2011 10:16 PM |
| Alert throws to Alert window but no sound file... | Blash | Indicator Development | 4 | 02-15-2011 09:26 AM |
| sound alert() for a big bar | crmcwi | Indicator Development | 2 | 05-11-2010 05:30 AM |
| Alert on bar close, Chart Trader | gg80108 | Miscellaneous Support | 1 | 12-29-2008 09:25 AM |
| Making an Alert on conditional indicator | ericadam | Charting | 1 | 09-05-2008 02:26 PM |