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!
See more
See less

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.
    Brandon H.NinjaTrader Customer Service

    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
        Brandon H.NinjaTrader Customer Service

        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 llanqui, Yesterday, 10:29 AM
          3 responses
          22 views
          0 likes
          Last Post llanqui
          by llanqui
           
          Started by cshox, Today, 11:11 AM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by Seneca, 08-25-2020, 08:31 AM
          4 responses
          5,953 views
          0 likes
          Last Post Tin34
          by Tin34
           
          Started by TAJTrades, Today, 11:03 AM
          0 responses
          5 views
          0 likes
          Last Post TAJTrades  
          Started by wuannetraam, Today, 02:40 AM
          3 responses
          26 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X