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

Indicator not Returning Correct Value

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

    Indicator not Returning Correct Value

    I'm writing a strategy with several of my custom indicators. I am running the strategy in the strategy analyzer. The strategy updates on bar close as well as most of the indicators. Two of the indicators update on each tick but only one of them returns the correct values when called, the other always returns 0. The indicator that always returns 0 is using the OnMarketData() method whereas the other oneachtick indicator is not.

    Tick replay does not make a difference and if I make the whole strategy calculate oneachtick the incorrect indicator is still wrong. However, if I use market replay all indicators return correct values to the strategy.

    What do I need to do to be able to return the correct values while using strategy analyzer like I do in market replay?

    #2
    Hello,

    Thank you for the post.

    In this situation, you are correct to look at TickReplay as you are using OnMarketData as this would be the only way that OnMarketData would be called historically. Can you tell me, have you created the indicator to align with the developing for tick replay page here:


    If so, you should be able to see the OnMarketData event being called with TickReplay enabled. Please keep in mind this would be data dependent, in case there is no data available for the time requested the test may fail to complete.

    I created a small sample of the syntax required for TickReplay in an indicator, could you try the attached example to see if you can Print out the historical values while running a backtest? I was able to see prints occurring meaning that OnMarketData is being called while the strategy is testing. Using a simple test like this, you could identify what may be happening with your own script to correct it.

    In the sample, please note how the indicator instance is both stored in a variable and also is being called from OnBarUpdate. There is no actual calculation being done but it is necessary to call the indicator to have it calculate historically.




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

    Comment


      #3
      Hi Jesse,

      I tried the strategy you provided and as expected it worked. I then slightly modified it to show what I'm attempting to do. It is still not working as I would expect. I use this method all the time with indicators that do not require tick replay and they always work, so I'm not sure what I'm doing wrong.

      I've attached my slightly modified indicator and strategy below.

      On line 77 of the strategy ("double myValue = myTickReplayIndicator1.Sells[1];") I also tried setting the indicator value to a Series<double> instead of just a double, which is what I normally do, but that did not work either.

      Running the strategy in strategy analyzer outputs the sells volume correctly from the indicator, but the value in the strategy is always 0. I want "Print("Strat, Sells: " + myValue);" to give the same value as "Print("Indicator, New Bar, Sells: " + Sells[1]);" but this is not happening.

      Any ideas of how to make that happen?
      Attached Files
      Last edited by Nick L; 08-22-2017, 02:15 PM.

      Comment


        #4
        Hello,

        Thank you for the reply.

        The main difference I can see in this script versus the sample is that you are both setting a value to 1 bars ago, and then checking 1 bars ago from the strategy. Was this intentional?

        I can see if the indicator sets its current bar value the strategy can retrieve the values.

        Could you try using 0 bars ago when setting the value from the indicator and see if this resolves the problem?

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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by terofs, Today, 04:18 PM
        0 responses
        5 views
        0 likes
        Last Post terofs
        by terofs
         
        Started by nandhumca, Today, 03:41 PM
        0 responses
        5 views
        0 likes
        Last Post nandhumca  
        Started by The_Sec, Today, 03:37 PM
        0 responses
        3 views
        0 likes
        Last Post The_Sec
        by The_Sec
         
        Started by GwFutures1988, Today, 02:48 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by ScottWalsh, 04-16-2024, 04:29 PM
        6 responses
        33 views
        0 likes
        Last Post ScottWalsh  
        Working...
        X