NexusFi: Find Your Edge


Home Menu

 





NT7 sound alert failure


Discussion in NinjaTrader

Updated
    1. trending_up 2,960 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?
What broker to use for trading palladium futures
Commodities
Cheap historycal L1 data for stocks
Stocks and ETFs
Quantum physics & Trading dynamics
The Elite Circle
REcommedations for programming help
Sierra Chart
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
24 thanks
What is Markets Chat (markets.chat) real-time trading ro …
19 thanks
ApexTraderFunding.com experience and review
16 thanks
GFIs1 1 DAX trade per day journal
12 thanks
EG Indicators
11 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,103


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,103


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