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

How to include last price of secondary series in indicator

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

    How to include last price of secondary series in indicator

    Hello, I have an indicator which uses a secondary 15M series. I created an alert and noticed yesterday that it missed a signal because my condition for the secondary series is based on Lows[1][0] whereas it should be based on the last price of the 15M series. The Alert is currently in the OnBarUpdate() method, but I believe that I may need to include it in the OnMarketData() method and use MarketDataType.Last instead of Lows[1][0]. Can you please confirm that the Alert needs to be in the OnMarketData() method and let me know how to adjust the Lows[1][0] so that it picks up the last price for the secondary series, if that is all I need to do.

    Thank you.

    Code:
    /Bear bar cross below CMA - Alert 
    			if ((Lows[1][0] < BMTCollectiveMA(BarsArray[1]).Plot0[0] || Lows[1][0] > (BMTCollectiveMA(BarsArray[1]).Plot0[0]+20*TickSize))//On 15M dataseries, L < CMA OR L > CMA+20pips
    			&& myBslBullInvPeriod3.BslShortPeriod[0] > myBslBullInvPeriod3.BslShortPeriod[1]
    			&& ((open0 >= BMTCollectiveMA()[0] && close0 < BMTCollectiveMA()[0] && close0 < open0 && close0 == low0 && vol0 > volSma0 )
    			|| ((open0 == close0) &&(Math.Abs(high0 - open0) > Math.Abs(low0 - open0)) && vol0 < volSma0 * 0.95 && high0 >= BMTCollectiveMA()[0] 
    			&& close0 < BMTCollectiveMA()[0])))			
    			Alert("myAlert1b", Priority.High, "Movement to Overbought - possible bear move", NinjaTrader.Core.Globals.InstallDir+@"\sounds\Alert2.wav", 10, Brushes.Red, Brushes.Black);

    #2
    Hello GeorgeW,

    I couldn't really say if the alert needs to be moved to OnMarketData or not, that would really depend on what your overall goal is. I could say that Lows[1] does signify the secondary series, if you have added only 1 secondary series Lows[1] would be that series Low series. To get the Last price you could use Closes[1][0].

    Index 0 would always be your primary series and each secondary series added would be the next count or 1 in this case.

    If the condition is not happening as expected I could suggest to add some Print statements in before the condition to check the values the strategy is seeing. This could help you understand if the alert needs to be moved or if any of the condition needs changed.

    We have some debugging steps and help in this post: http://ninjatrader.com/support/forum...ead.php?t=3418

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for responding, Jesse.
      The problem is that the secondary 15M series is looking at the last bar that has completed (for which the Low or Close may be above the EMA) when deciding if the Alert should be triggered, and not the 15M bar that is currently building (for which the most recent Low or Close may be below the EMA). Is it therefore simply a matter of changing Calculate On Bar Close to Calculate on Each Tick so that I am looking at the bar that is currently building? Is it possible to Calculate on Bar Close for the primary series but Calculate on Each Tick for the secondary? How would I code that?

      Comment


        #4
        Hello GeorgeW,

        Yes, You would want to use calculate on each tick if you wanted your condition to become true the moment the Low is below the EMA.

        It is not possible to set one data series to calculate on bar close and have another calculate on each tick, however what you could do is set the strategy/indicator to calculate on each tick, then as part of the condition which analyzes the series you wish to evaluate with calculate to each tick, you could refer to the previous bar index, for example Closes[1][1]. This works because Closes[1][1], referring to the 2nd data series 1 bar ago , has its value set on the close of the current bar.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by PaulMohn, Today, 12:36 PM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by yertle, Yesterday, 08:38 AM
        8 responses
        36 views
        0 likes
        Last Post ryjoga
        by ryjoga
         
        Started by rdtdale, Today, 01:02 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by alifarahani, Today, 09:40 AM
        3 responses
        16 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by RookieTrader, Today, 09:37 AM
        4 responses
        19 views
        0 likes
        Last Post RookieTrader  
        Working...
        X