NexusFi: Find Your Edge


Home Menu

 





Syncing a sound alert with arrows


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one protrader007 with 4 posts (0 thanks)
    2. looks_two Tarkus11 with 2 posts (1 thanks)
    3. looks_3 eDanny with 2 posts (1 thanks)
    4. looks_4 MWinfrey with 1 posts (1 thanks)
    1. trending_up 3,364 views
    2. thumb_up 3 thanks given
    3. group 2 followers
    1. forum 9 posts
    2. attach_file 0 attachments




 
Search this Thread

Syncing a sound alert with arrows

  #1 (permalink)
 protrader007 
Bee Cave,Tx
 
Experience: Intermediate
Platform: NinjaTrader
Trading: CL
Posts: 54 since Aug 2010
Thanks Given: 31
Thanks Received: 20

I'm trying to play a sound at the same time that I get an arrow. I'm using the code below and get both an arrow and a sound when the conditions are true but I also get a sound when there is no arrow.
Can someone please tell me what I'm doing wrong?
Thanks.


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
ZombieSqueeze
Platforms and Indicators
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
REcommedations for programming help
Sierra Chart
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
48 thanks
Just another trading journal: PA, Wyckoff & Trends
32 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
  #3 (permalink)
 
eDanny's Avatar
 eDanny 
East Rochester, NY
 
Experience: Intermediate
Platform: NT
Posts: 329 since Jul 2009
Thanks Given: 18
Thanks Received: 425



protrader007 View Post
I'm trying to play a sound at the same time that I get an arrow. I'm using the code below and get both an arrow and a sound when the conditions are true but I also get a sound when there is no arrow.
Can someone please tell me what I'm doing wrong?
Thanks.


You have two tests going on here. They might be both true at the same time or separately. Without seeing more of your code it is hard to tell how to rewrite it.

Dan

Reply With Quote
  #4 (permalink)
 protrader007 
Bee Cave,Tx
 
Experience: Intermediate
Platform: NinjaTrader
Trading: CL
Posts: 54 since Aug 2010
Thanks Given: 31
Thanks Received: 20


eDanny View Post
You have two tests going on here. They might be both true at the same time or separately. Without seeing more of your code it is hard to tell how to rewrite it.

Dan

I'm testing for a bunch of conditions and if they are all true I draw an arrow. This part is working OK, no problems at all.
I now want to play an alert sound if the same conditions are true in addition to drawing the arrow. Do I need to repeat the code and test for all the same conditions again or is there some way to say "draw an arrow" AND "play a sound" for the same set of conditions?

Started this thread Reply With Quote
  #5 (permalink)
 
eDanny's Avatar
 eDanny 
East Rochester, NY
 
Experience: Intermediate
Platform: NT
Posts: 329 since Jul 2009
Thanks Given: 18
Thanks Received: 425


protrader007 View Post
I'm testing for a bunch of conditions and if they are all true I draw an arrow. This part is working OK, no problems at all.
I now want to play an alert sound if the same conditions are true in addition to drawing the arrow. Do I need to repeat the code and test for all the same conditions again or is there some way to say "draw an arrow" AND "play a sound" for the same set of conditions?

Using PlaySound can be tricky because it will repeatedly play the sound while the condition exists. Therefore it is not very suitable out of the box for realtime, CalculateOnBarClose=false type indicators unless you code it right. You might want to set a bool variable to true when your condition triggers and on FirstTickofBar (the next bar) test for the bool and play the sound. Change variable to false. Playing in real time can work pretty much then same but every time your condition exists you would get the sound, even multiple times per bar unless you restrict it with code. You will have to figure out what you really want and code around it.

Dan

Reply With Quote
Thanked by:
  #6 (permalink)
 
MWinfrey's Avatar
 MWinfrey 
Lubbock TX
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Stage 5 Trading
Trading: CL
Posts: 1,878 since Jul 2009
Thanks Given: 1,450
Thanks Received: 3,335


protrader007 View Post
I'm testing for a bunch of conditions and if they are all true I draw an arrow. This part is working OK, no problems at all.
I now want to play an alert sound if the same conditions are true in addition to drawing the arrow. Do I need to repeat the code and test for all the same conditions again or is there some way to say "draw an arrow" AND "play a sound" for the same set of conditions?

Just put the logic Danny suggested in the same block of code where you draw the arrow.

Reply With Quote
Thanked by:
  #7 (permalink)
 Tarkus11 
East Coast
 
Experience: Beginner
Platform: Ninja
Trading: ES, NQ
Posts: 124 since Apr 2010
Thanks Given: 55
Thanks Received: 80


protrader007 View Post
I'm trying to play a sound at the same time that I get an arrow. I'm using the code below and get both an arrow and a sound when the conditions are true but I also get a sound when there is no arrow.
Can someone please tell me what I'm doing wrong?
Thanks.


I think if you are calculation on bar close = true, you could do


if (ShowArrows)
{
Draw...
if (soundOn &&...
}

if calc on bar close = false, then you would have to have the sound conditional on a flag and outside the brackets, since the arrow condition might be met but it might not be the 1st tick of bar anymore to trigger the sound.

Reply With Quote
Thanked by:
  #8 (permalink)
 protrader007 
Bee Cave,Tx
 
Experience: Intermediate
Platform: NinjaTrader
Trading: CL
Posts: 54 since Aug 2010
Thanks Given: 31
Thanks Received: 20


Tarkus11 View Post
I think if you are calculation on bar close = true, you could do


if (ShowArrows)
{
Draw...
if (soundOn &&...
}

if calc on bar close = false, then you would have to have the sound conditional on a flag and outside the brackets, since the arrow condition might be met but it might not be the 1st tick of bar anymore to trigger the sound.


MWinfrey View Post
Just put the logic Danny suggested in the same block of code where you draw the arrow.


eDanny View Post
Using PlaySound can be tricky because it will repeatedly play the sound while the condition exists. Therefore it is not very suitable out of the box for realtime, CalculateOnBarClose=false type indicators unless you code it right. You might want to set a bool variable to true when your condition triggers and on FirstTickofBar (the next bar) test for the bool and play the sound. Change variable to false. Playing in real time can work pretty much then same but every time your condition exists you would get the sound, even multiple times per bar unless you restrict it with code. You will have to figure out what you really want and code around it.

Dan

Thanks guys, I really appreciate your help. Now I understand the problem.
I am using CalculateOnBarClose=false and will figure out how to code around it.

Started this thread Reply With Quote
  #9 (permalink)
 protrader007 
Bee Cave,Tx
 
Experience: Intermediate
Platform: NinjaTrader
Trading: CL
Posts: 54 since Aug 2010
Thanks Given: 31
Thanks Received: 20


eDanny View Post
Using PlaySound can be tricky because it will repeatedly play the sound while the condition exists. Therefore it is not very suitable out of the box for realtime, CalculateOnBarClose=false type indicators unless you code it right. You might want to set a bool variable to true when your condition triggers and on FirstTickofBar (the next bar) test for the bool and play the sound. Change variable to false. Playing in real time can work pretty much then same but every time your condition exists you would get the sound, even multiple times per bar unless you restrict it with code. You will have to figure out what you really want and code around it.

Dan

FYI, I played around with setting a bool variable, testing it and resetting it but in the end I decided to use the Alert function. Much easier to code and I also have the results in the Alert window as a bonus!

Started this thread Reply With Quote
  #10 (permalink)
 Tarkus11 
East Coast
 
Experience: Beginner
Platform: Ninja
Trading: ES, NQ
Posts: 124 since Apr 2010
Thanks Given: 55
Thanks Received: 80



protrader007 View Post
FYI, I played around with setting a bool variable, testing it and resetting it but in the end I decided to use the Alert function. Much easier to code and I also have the results in the Alert window as a bonus!


Just an FYI - I ran into this in the past too. For my purposes, the way I dealt with my own alert approach was
1) private int alertcounter = 0;
2)
if (whateverConditions && alertcounter == 0)
{
Alert Stuff
alertcounter++;
}

3) Somewhere outside the brackets has to be some logical condition that resets alertcounter to 0 again for the next time. Like if the condition was an upcross of a shorter moving avg over a longer mov avg, when they cross in the other direction, alertcounter would be reset to 0 (though maybe there should be an upcrossalertcounter and downcrossalertcounter in that case...).

I could do stuff with the integer counter (like use modulus (%)) to alert on odd or even counter or whatever (if I chose not to reset it).

Reply With Quote




Last Updated on March 16, 2011


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts