for example,
if Close[0] > Open[0] {
PlaySound (.....);
}
want to happen this one only once per bar. What is simplest method?
btw, i know complex methods, like saving unique identifier in array and re-checking...
Private bool doOnce=false; if(Close[0]>0 && doOnce==False) { PlaySound; doOnce=true; }
private bool doOnce=false; if(Close[0]>0 && doOnce==false) { PlaySound; doOnce=true; }
BRIEF CODE { [B]private bool doOnce = false;[/B] ... protected override void OnBarUpdate() { if(CurrentBar < 1)return; if (VOL()[0] >= VOLMA(5)[1] && [B](doOnce == false))[/B] { PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\VolumeSpike.wav"); [B]doOnce = true; ...[/B] }
FULL CODE // // Copyright (C) 2020, NinjaTrader LLC <www.ninjatrader.com>. // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release. // #region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; using NinjaTrader.NinjaScript.DrawingTools; #endregion //This namespace holds Indicators in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Indicators { public class VolumeUpDown_Alert : Indicator { [B]private bool doOnce = false;[/B] protected override void OnStateChange() { if (State == State.SetDefaults) { Name = "VolumeUpDown_Alert"; Calculate = Calculate.OnEachTick; DrawOnPricePanel = false; IsOverlay = false; IsSuspendedWhileInactive = true; AddPlot(new Stroke(Brushes.DarkCyan, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.VolumeUp); AddPlot(new Stroke(Brushes.Crimson, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.VolumeDown); AddLine(Brushes.DarkGray, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZe roLine); } else if (State == State.Historical) { if (Calculate == Calculate.OnPriceChange) { Draw.TextFixed(this, "NinjaScriptInfo", string.Format(NinjaTrader.Custom.Resource.NinjaScr iptOnPriceChangeError, Name), TextPosition.BottomRight); Log(string.Format(NinjaTrader.Custom.Resource.Ninj aScriptOnPriceChangeError, Name), LogLevel.Error); } } } protected override void OnBarUpdate() { if(CurrentBar < 1)return; if (VOL()[0] >= VOLMA(5)[1] && [B](doOnce == false))[/B] { PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\VolumeSpike.wav"); [B]doOnce = true; // prevent additional alerts[/B] } if (Close[0] >= Open[0]) { UpVolume[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0]; DownVolume.Reset(); } else { UpVolume.Reset(); DownVolume[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0]; } } #region Properties [Browsable(false)] [XmlIgnore] public Series<double> DownVolume { get { return Values[1]; } } [Browsable(false)] [XmlIgnore] public Series<double> UpVolume { get { return Values[0]; } } #endregion } } #region NinjaScript generated code. Neither change nor remove. namespace NinjaTrader.NinjaScript.Indicators { public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase { private VolumeUpDown_Alert[] cacheVolumeUpDown_Alert; public VolumeUpDown_Alert VolumeUpDown_Alert() { return VolumeUpDown_Alert(Input); } public VolumeUpDown_Alert VolumeUpDown_Alert(ISeries<double> input) { if (cacheVolumeUpDown_Alert != null) for (int idx = 0; idx < cacheVolumeUpDown_Alert.Length; idx++) if (cacheVolumeUpDown_Alert[idx] != null && cacheVolumeUpDown_Alert[idx].EqualsInput(input)) return cacheVolumeUpDown_Alert[idx]; return CacheIndicator<VolumeUpDown_Alert>(new VolumeUpDown_Alert(), input, ref cacheVolumeUpDown_Alert); } } } namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns { public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase { public Indicators.VolumeUpDown_Alert VolumeUpDown_Alert() { return indicator.VolumeUpDown_Alert(Input); } public Indicators.VolumeUpDown_Alert VolumeUpDown_Alert(ISeries<double> input ) { return indicator.VolumeUpDown_Alert(input); } } } namespace NinjaTrader.NinjaScript.Strategies { public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.VolumeUpDown_Alert VolumeUpDown_Alert() { return indicator.VolumeUpDown_Alert(Input); } public Indicators.VolumeUpDown_Alert VolumeUpDown_Alert(ISeries<double> input ) { return indicator.VolumeUpDown_Alert(input); } } } #endregion
[B]private bool doOnce = false;[/B]
if(CurrentBar < 1) return; if (VOL()[0] >= VOLMA(5)[1] && [B](doOnce == false)) [/B]
{ PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\VolumeSpike.wav");
[B]doOnce = true; ...[/B] }
[B]doOnce = false;[/B]
{ [B]private bool doOnce = false;[/B] ... if(CurrentBar < 1)return; if (VOL()[0] >= VOLMA(5)[1] && [B](doOnce == false)[/B]) { PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\VolumeSpike.wav"); [B]doOnce = true; doOnce = false;[/B] }
{ [B]private bool doOnce = false;[/B] ... protected override void OnBarUpdate() { if(CurrentBar < 1)return; if (VOL()[0] >= VOLMA(5)[1]) && [B](doOnce == false)[/B]) { PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\VolumeSpike.wav"); [B]doOnce = true;[/B] } if (IsFirstTickOfBar) { [B]doOnce = false;[/B] } if (Close[0] >= Open[0]) { UpVolume[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0]; DownVolume.Reset(); } else { UpVolume.Reset(); DownVolume[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0]; } }
Print(string.Format("{0} | VOL()[0]: {1} | State: {2} | VOLMA(5)[1]: {3} | doOnce: {4}", Time[0], VOL()[0], State, VOLMA(5)[1], doOnce));
protected override void OnBarUpdate() { if(CurrentBar < 1)return; if (VOL()[0] >= VOLMA(5)[1] && (doOnce == false)) { PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\CrudeVolumeSpike.wav"); doOnce = true; // prevent additional alerts } if (IsFirstTickOfBar) { doOnce = false; } Print(string.Format("{0} | VOL()[0]: {1} | State: {2} | VOLMA(5)[1]: {3} | doOnce: {4}", Time[0], VOL()[0], State, VOLMA(5)[1], doOnce)); if (Close[0] >= Open[0]) { UpVolume[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0]; DownVolume.Reset(); } else { UpVolume.Reset(); DownVolume[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0]; } }
// // Copyright (C) 2020, NinjaTrader LLC <www.ninjatrader.com>. // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release. // #region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; using NinjaTrader.NinjaScript.DrawingTools; #endregion //This namespace holds Indicators in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Indicators { public class VolumeUpDown_AlertX : Indicator { private bool doOnce = false; protected override void OnStateChange() { if (State == State.SetDefaults) { Name = "VolumeUpDown_AlertX"; Calculate = Calculate.OnEachTick; DrawOnPricePanel = false; IsOverlay = false; IsSuspendedWhileInactive = true; AddPlot(new Stroke(Brushes.DarkCyan, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.VolumeUp); AddPlot(new Stroke(Brushes.Crimson, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.VolumeDown); AddLine(Brushes.DarkGray, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZe roLine); } else if (State == State.Historical) { if (Calculate == Calculate.OnPriceChange) { Draw.TextFixed(this, "NinjaScriptInfo", string.Format(NinjaTrader.Custom.Resource.NinjaScr iptOnPriceChangeError, Name), TextPosition.BottomRight); Log(string.Format(NinjaTrader.Custom.Resource.Ninj aScriptOnPriceChangeError, Name), LogLevel.Error); } } } protected override void OnBarUpdate() { if(CurrentBar < 1)return; if (VOL()[0] >= VOLMA(5)[1] && (doOnce == false)) { PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\CrudeVolumeSpike.wav"); doOnce = true; // prevent additional alerts } if (IsFirstTickOfBar) { doOnce = false; } Print(string.Format("{0} | VOL()[0]: {1} | State: {2} | VOLMA(5)[1]: {3} | doOnce: {4}", Time[0], VOL()[0], State, VOLMA(5)[1], doOnce)); if (Close[0] >= Open[0]) { UpVolume[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0]; DownVolume.Reset(); } else { UpVolume.Reset(); DownVolume[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0]; } } #region Properties [Browsable(false)] [XmlIgnore] public Series<double> DownVolume { get { return Values[1]; } } [Browsable(false)] [XmlIgnore] public Series<double> UpVolume { get { return Values[0]; } } #endregion } } #region NinjaScript generated code. Neither change nor remove. namespace NinjaTrader.NinjaScript.Indicators { public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase { private VolumeUpDown_AlertX[] cacheVolumeUpDown_AlertX; public VolumeUpDown_AlertX VolumeUpDown_AlertX() { return VolumeUpDown_AlertX(Input); } public VolumeUpDown_AlertX VolumeUpDown_AlertX(ISeries<double> input) { if (cacheVolumeUpDown_AlertX != null) for (int idx = 0; idx < cacheVolumeUpDown_AlertX.Length; idx++) if (cacheVolumeUpDown_AlertX[idx] != null && cacheVolumeUpDown_AlertX[idx].EqualsInput(input)) return cacheVolumeUpDown_AlertX[idx]; return CacheIndicator<VolumeUpDown_AlertX>(new VolumeUpDown_AlertX(), input, ref cacheVolumeUpDown_AlertX); } } } namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns { public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase { public Indicators.VolumeUpDown_AlertX VolumeUpDown_AlertX() { return indicator.VolumeUpDown_AlertX(Input); } public Indicators.VolumeUpDown_AlertX VolumeUpDown_AlertX(ISeries<double> input ) { return indicator.VolumeUpDown_AlertX(input); } } } namespace NinjaTrader.NinjaScript.Strategies { public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.VolumeUpDown_AlertX VolumeUpDown_AlertX() { return indicator.VolumeUpDown_AlertX(Input); } public Indicators.VolumeUpDown_AlertX VolumeUpDown_AlertX(ISeries<double> input ) { return indicator.VolumeUpDown_AlertX(input); } } } #endregion
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by geddyisodin, Yesterday, 05:20 AM
|
8 responses
51 views
0 likes
|
Last Post Today, 10:45 AM | ||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
10 responses
36 views
0 likes
|
Last Post Today, 11:10 AM | ||
Started by DayTradingDEMON, Today, 09:28 AM
|
4 responses
24 views
0 likes
|
Last Post Today, 10:47 AM | ||
Started by George21, Today, 10:07 AM
|
1 response
17 views
0 likes
|
Last Post Today, 10:43 AM | ||
Started by Stanfillirenfro, Today, 07:23 AM
|
9 responses
25 views
0 likes
|
Last Post Today, 10:16 AM |
Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing one’s financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.
CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.
This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates.
Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.
Comment