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

OnMarketData High[0] is previous high

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

    OnMarketData High[0] is previous high

    This writes out the previous bars high and not the building bars high. How do you get the high of the building bar?

    protected override void OnMarketData(MarketDataEventArgs e)
    {
    NinjaTrader.Code.Output.Process(High[0].ToString(), PrintTo.OutputTab1);




    #2
    Hello TradingDreamer,

    Thanks for your post.

    If you use the mode of Calculate.OnEachTick or Calculate.OnPriceChange, in OnBarUpdate() the bar index of [0] would point to the currently forming bar so High[0] would return high of the current bar. You would not need to use OnMarketData to find the current high.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      That makes sense. However, my strategy is using Calculate.OnBarClose to separate out rules in BarClose and Market data. My workaround was to create a currentBarsHigh = new Series<double>(this, MaximumBarsLookBack.Infinite); and update the value in the OnMarketData if e.Last > currentBarsHigh[0] then currentBarsHigh[0] = e.Last. I think this is working to pass the values correctly to my custom indicator.

      Comment


        #4
        Hello TradingDreamer,

        Thanks for your reply.

        You might find it better to operate your code using Calculate.OnEachTick or CalculateOnPriceChange and then segment the code you want to run only once per bar to code that needs to access the current prices of the forming bar. This can be done by using a bool that is true once per bar. The system bool IsFirstTickOfBar can be used for that purpose. Reference: https://ninjatrader.com/support/help...ttickofbar.htm

        Here is a link to an example that demonstrates this: https://ninjatrader.com/support/help...either_cal.htm
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cre8able, 02-11-2023, 05:43 PM
        3 responses
        231 views
        0 likes
        Last Post rhubear
        by rhubear
         
        Started by frslvr, 04-11-2024, 07:26 AM
        8 responses
        111 views
        1 like
        Last Post NinjaTrader_BrandonH  
        Started by stafe, 04-15-2024, 08:34 PM
        10 responses
        44 views
        0 likes
        Last Post stafe
        by stafe
         
        Started by rocketman7, Today, 09:41 AM
        3 responses
        8 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by traderqz, Today, 09:44 AM
        2 responses
        5 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X