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

Accessing historical data in dataseries

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

    Accessing historical data in dataseries

    Having problem accessing historical data. I have two conditions that set different values and then I save to a dataseries. If neither condition is met, I want to retain the latest value so it stays the same until a condition changes it. However now if neither condition is met I get a zero instead of previous value.

    I initialize the variable to the previous bars dataseries value.
    Then check for each condition to see if the value should be changed.
    Then save the value to the dataseries. ( so expect to save a new value or previously set value )

    When a condition is met it is correctly saving the value.
    But when neither is met it is saving zero instead of the value from prev bar.
    ( once the value is 3, it should stay 3 until changed to 1 )

    small code snippet:

    gHiLo = (int)gHitHiLo[1]; // init to prev bar value
    if( cciVal >= minAbsVal )
    gHiLo = 3 ; // signal cci has crossed 100 line
    if( cciVal <= (-1 * minAbsVal) )
    gHiLo = 1; // signal cci has crossed -100 line
    gHitHiLo.Set( gHiLo ); // store value to dataseries


    Also, I have had problems when performing a plot and the value is a negative number ? It does not do the plot and get a log "overflow error"
    Example Plot0.Set( -2 );

    Thanks

    #2
    Please check your error logs for your DataSeries issue. Check out this tip on debugging http://www.ninjatrader-support.com/v...ead.php?t=3418.

    Did you remember to do this snippet? http://www.ninjatrader-support.com/v...ead.php?t=3170

    For the Plot0.Set(-2), thanks for reporting. We will look into it.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      The negative plot issue you pointed out will be fixed in the next version of NT6.5 beta. Thank you for reporting.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by Josh View Post
        The negative plot issue you pointed out will be fixed in the next version of NT6.5 beta. Thank you for reporting.
        Thanks for the update.
        I used print to the output window to isolate the other issue.
        But am finding the output listings are not in order.
        Times and dates appear out of order and doesn't seem to match to the bars of the chart. I have calculateonbarclose set to true.

        ------------------------------------------------------------------------
        cci value 152.524357838809
        gHiLo initial value 3 bars 22 time 02/07/08 9:03:59 AM
        gHiLo from prev bar dataseries 3
        gHiLo after eval 3
        ------------------------------------------------------------------------
        cci value 152.524357838809
        gHiLo initial value 3 bars 23 time 02/07/08 9:04:45 AM
        gHiLo from prev bar dataseries 3
        gHiLo after eval 3
        ------------------------------------------------------------------------
        cci value 152.524357838809
        gHiLo initial value 3 bars 24 time 02/07/08 9:05:47 AM
        gHiLo from prev bar dataseries 3
        gHiLo after eval 3
        ------------------------------------------------------------------------
        cci value 131.194968553471
        gHiLo initial value 0 bars 2 time 02/07/08 8:33:29 AM
        gHiLo from prev bar dataseries 0
        gHiLo after eval 3
        ------------------------------------------------------------------------
        cci value 131.194968553471
        gHiLo initial value 3 bars 3 time 02/07/08 8:35:28 AM
        gHiLo from prev bar dataseries 3
        gHiLo after eval 3
        ------------------------------------------------------------------------
        cci value 131.194968553471
        gHiLo initial value 3 bars 4 time 02/07/08 8:36:49 AM
        gHiLo from prev bar dataseries 3
        gHiLo after eval 3

        Comment


          #5
          Could you post a simple as possible code snippet that demonstrates what you are experiencing? Thanks.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by Josh View Post
            Could you post a simple as possible code snippet that demonstrates what you are experiencing? Thanks.
            Code snippet at the bottom.

            I have been loading one indicator the uses CCI(14)[0]
            Then passes this into another indicator that uses the code snippet.
            When I do this it results in the problem I experienced.

            But if I place the cci eval in the second indicator ( rather than passing in ), and it then works fine. The output is fine and the plot is fine.

            Seems to have something to do with the way I have coordinated the two indicators. I am trying to use the second as a function that returns a value to the calling indicator to use.

            Print( " ------------------------------------------------------------------------" );
            Print(
            " cci value " + value );
            Print(
            " gHiLo initial value " + gHiLo + " bars " + CurrentBar + " time " + Time[0].ToString() );

            gHiLo = (
            int)gHitHiLo[1];
            Print(
            " gHiLo from prev bar dataseries " + gHiLo );
            if( gHiLo == 0 && CurrentBar > 20 ) { // look a prev periods
            barsAgo = MRO( delegate{ return gHitHiLo[1] != 0; }, 1, 10 );
            if( barsAgo < 0 )
            barsAgo = MRO(
            delegate{ return gHitHiLo[1] != 0; }, 1, 20 );
            if( barsAgo > 0 )
            gHiLo = (
            int)gHitHiLo[barsAgo];
            Print(
            " gHiLo from MRO " + gHiLo + " barsAgo " + barsAgo );
            }

            if( value >= minAbsVal ) gHiLo = 3 ; // signal cci has crossed 100 line
            if( value <= (-1 * minAbsVal) ) gHiLo = 1; // signal cci has crossed -100 line
            gHitHiLo.Set( gHiLo );
            Print(
            " gHiLo after eval " + gHiLo );

            Comment


              #7
              Maybe some clarification for me.
              When loading an indicator the Initialize code is only run once at the start of the chart, but when an indicator is called by another the Initialize is run each time it called??????? Maybe that is causing my issues.

              I am using a custom dataseries in the called indicator that I instantiate in the initialize method, is that why it seems to get corrupted.

              Comment


                #8
                Right. Because NinjaTrader is multi-threaded it is not guaranteed that calling like that will ensure they are in sync with each other. You may want to check out Update() or just go with calling it directly from your second indicator.
                Josh P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by RookieTrader, Today, 09:37 AM
                3 responses
                14 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by kulwinder73, Today, 10:31 AM
                0 responses
                5 views
                0 likes
                Last Post kulwinder73  
                Started by terofs, Yesterday, 04:18 PM
                1 response
                23 views
                0 likes
                Last Post terofs
                by terofs
                 
                Started by CommonWhale, Today, 09:55 AM
                1 response
                3 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by Gerik, Today, 09:40 AM
                2 responses
                7 views
                0 likes
                Last Post Gerik
                by Gerik
                 
                Working...
                X