NexusFi: Find Your Edge


Home Menu

 





NT7 sound alert failure


Discussion in NinjaTrader

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




 
Search this Thread
  #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?
April 2026 Jobs Report: +115k vs +65k Expected
Traders Hideout
TradingView Deploys AI to Monitor SEC Filings in Real Ti …
TradingView
Iran Airspace Contract Surges to 33.5% as Project Freedo …
Prediction Markets & Event Contracts
CME Lists U.S. Election Event Contracts as 2028 Democrat …
Prediction Markets & Event Contracts
Iran Peace Expired NO: Ceasefire on Life Support, OPEC a …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Trying to learn Volume and price action correlation
8 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
Algo automated / semi-automated trading anyone?
6 thanks
  #2 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: Futures & Stocks
Posts: 9,887 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,114


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

Thanks mucho


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


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

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


© 2026 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 - Downloads - Top
no new posts