What is the best way to have a strategy execute only on a price change? Do I need to compare prices in OnMarketData()? Thank you.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
On Price Change Strategy
Collapse
X
-
Hello Zeos6,
Thank you for your post.
You may set your strategy to calculate OnPriceChange in order to have the strategy run for each change in price. OnPriceChange means once for each price change. If there were two ticks in a row with the same price, the second tick would not trigger OnBarUpdate().
Please see this help guide link for more information about OnPriceChange and other Calculate modes - https://ninjatrader.com/support/help...?calculate.htm
Let us know if we may assist further.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
-
Thank you for your reply Brandon but the reply is meaningless to me. It completely avoids answering the question as it relates to OnMarketData. I simply asked for best way to check for price change in OnMarketData(). I am running the strategy with TickReplay and wish to handle things inside OnMarketData.
Comment
-
Hello Zeos6,
Thank you for your note.
You may check if the price has changed in OnMarketData() by using Price from MarketDataEventArgs. Please see the attached example script that demonstrates how this could be accomplished. In the example script, we create two variables (prevPrice and currentPrice) that will hold the previous price and the current price values. In OnMarketData(), we check if MarketDataType == MarketDataType.Last followed by assigning prevPrice a value of currentPrice and we assign currentPrice the current market value using marketDataUpdate.Price. The script then compares prevPrice to currentPrice and prints information to the Output window.
Also, please see this help guide page for more information about MarketDataEventArgs - https://ninjatrader.com/support/help...aeventargs.htm
Please let us know if we may further assist.Attached Files<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
50 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
126 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
69 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment