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
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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.Brandon H.NinjaTrader Customer Service
-
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 FilesBrandon H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by helpwanted, Today, 03:06 AM
|
1 response
14 views
0 likes
|
Last Post Today, 03:35 AM | ||
Started by Brevo, Today, 01:45 AM
|
0 responses
11 views
0 likes
|
Last Post
by Brevo
Today, 01:45 AM
|
||
Started by aussugardefender, Today, 01:07 AM
|
0 responses
6 views
0 likes
|
Last Post Today, 01:07 AM | ||
Started by pvincent, 06-23-2022, 12:53 PM
|
14 responses
244 views
0 likes
|
Last Post
by Nyman
Today, 12:47 AM
|
||
Started by TraderG23, 12-08-2023, 07:56 AM
|
9 responses
387 views
1 like
|
Last Post
by Gavini
Today, 12:29 AM
|
Comment