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 helpwanted, Today, 03:06 AM
          1 response
          14 views
          0 likes
          Last Post sarafuenonly123  
          Started by Brevo, Today, 01:45 AM
          0 responses
          11 views
          0 likes
          Last Post Brevo
          by Brevo
           
          Started by aussugardefender, Today, 01:07 AM
          0 responses
          6 views
          0 likes
          Last Post aussugardefender  
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          244 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          9 responses
          387 views
          1 like
          Last Post Gavini
          by Gavini
           
          Working...
          X