NexusFi: Find Your Edge


Home Menu

 





NT7 sound alert failure


Discussion in NinjaTrader

Updated
    1. trending_up 2,956 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

NT7 sound alert failure

  #1 (permalink)
baberg
Canada
 
Posts: 29 since Jul 2011
Thanks Given: 4
Thanks Received: 1

Hello fellow trader warriors, I'm trying to program a sound alert. Here's my sample code.

 
Code
		if(FirstTickOfBar)
			{
				if(Close[1]>Close[2]) PlaySound("Alert1.wav");
				else if(Close[1]<Close[2]) PlaySound("Alert2.wav");
			}
Let me say, I cannot hear a single cow bell this way

Is there something to add anywhere on my script to make it work ? Thank you

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Exit Strategy
NinjaTrader
Better Renko Gaps
The Elite Circle
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #2 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


baberg View Post
Hello fellow trader warriors, I'm trying to program a sound alert. Here's my sample code.

 
Code
        
if(FirstTickOfBar)
{
            if(Close[1]>Close[2]) PlaySound("Alert1.wav");
            else if(Close[1]<Close[2]) PlaySound("Alert2.wav");
}
Let me say, I cannot hear a single cow bell this way

Is there something to add anywhere on my script to make it work ? Thank you

The above code is correct, so I can only speculate. Please post the entire indicator next time, export via File -> Utilities -> Export NinjaScript.

The code references the bars CurrentBar - 1 and CurrentBar - 2 for the condition. When OnBarUpdate() starts its course, it will start with CurrentBar = 0, which is the first bar of the bar series. For the first bar you cannot reference prior bars, because they do not exist. NinjaTrader will therefore throw an exception and show it in the logs.

The correct way of doing it, is to only access the two prior bars starting with CurrentBar = 2, because now you have two prior bars that exist, the bars numbered 0 and 1. The modified code below should run.

 
Code
if(CurrentBar > 1 && FirstTickOfBar)
{  
          if(Close[1]>Close[2]) PlaySound("Alert1.wav");
          else if(Close[1]<Close[2]) PlaySound("Alert2.wav");
}

Reply With Quote
Thanked by:
  #3 (permalink)
baberg
Canada
 
Posts: 29 since Jul 2011
Thanks Given: 4
Thanks Received: 1


Hello Fat Tails, you are correct. That was it. I always have a if(CurrentBar<1) return; at the beginning of my scripts just in case. I had only forgotten to put it at 2 :tape:

Thanks mucho

Reply With Quote
  #4 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


baberg View Post
Hello Fat Tails, you are correct. That was it. I always have a if(CurrentBar<1) return; at the beginning of my scripts just in case. I had only forgotten to put it at 2 :tape:

Thanks mucho

The "just in case" is dangerous, it really depends on the code. For some indicators you may want to write special instructions for (CurrentBar < period).

Reply With Quote




Last Updated on July 27, 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