Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

On Price Change Strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    On Price Change Strategy

    Hi,

    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.

    #2
    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>

    Comment


      #3
      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


        #4
        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


          #5
          Hi Brandon,

          Thank you. That was helpful. I took that approach initially, but wanted to see if there was perhaps a different (better) way of doing it. Thank you for the code sample and the confirmation. Appreciate it. Regards,
          Paul

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          50 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          69 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X