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

Problems with indicator & strategy in RealTime

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

    Problems with indicator & strategy in RealTime

    Hello,

    I have an indicator and a strategy for calculating the SMA(5) and display it in output window. Both would must to display the same results, I think.

    But it doesn't. I don't know where is the problem. Could you help me, please ? Thanks very much.


    This is the code for the indicator:





    This is the code for the strategy:





    This is the output: (only the first outputs are matching).

    Attached Files

    #2
    You will want to debug what is going on in your strategy's DataSeries. From the output numbers it would seem the strategy's output is way off numerically.

    Also, try running them separately on two different charts. Then individually one at a time. Is your strategy still getting these negative values? SMA on the close of an instrument generally never yields negative values.

    Also, try just using dsSMA.Set(Close[0]) instead of the (0, Close[0]) set. See if that makes any difference. Same applies to your other DataSeries .Set.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I have changed the strategy code by deleting the Set functions.
      Also I am printing the five dsClose items that the SMA function must use for its calcs:


      ///
      <summary>
      /// Called on each bar update event (incoming tick)
      ///</summary>
      protectedoverridevoid OnBarUpdate()
      {
      dsClose[
      0] = Close[0];
      if ( CurrentBar < 5 ) return;

      if ( Historical ) return;
      Print(
      "------------------------------------");
      Print( dsClose[
      0] + " " + dsClose[1] + " " + dsClose[2] + " " + dsClose[3] + " " + dsClose[4]);
      dsSMA[
      0] = SMA(dsClose, 5)[0];
      Print(
      " STRATEGY : " + dsSMA[0]);
      Print(
      "************************************");
      }



      The result is ... . The dsClose dataserie is filled correctly, but the output SMA is an error.



      Is there any logical reason for this performance ?
      I use the Simulated Data Feed connection.


      Thanks very much.
      Attached Files

      Comment


        #4
        You can't do it like this: dsSMA[0] = SMA(dsClose, 5)[0];

        You need to use .Set.
        Code:
        dsClose.Set(Close[0]);
        dsSMA.Set(SMA(dsClose, 5)[0]);
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          cls71,

          I have it reproducing on my end. I will talk to development.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            it is the same. I have tried: with .Set(...), with .Set(0,...) , with no Set and the result is the same.

            (PD: .Set(n, ...) would must to work if I want to change a previous value).


            Nobody has detected this error ??? It occurs only in realtime, no backtesting. Only with strategies, no indicators.

            Debugging the core, the first time ( when the output is good ), the cacheSMA is null and the calc is correct.
            But the next times, (when the output is bad), the cacheSMA isn't null and the calc is incorrect.

            The first time when cacheSMA == null :




            The next times when cacheSMA != null :

            Attached Files

            Comment


              #7
              Josh will follow up early next week. Thanks for your patience.

              Comment


                #8
                Hello Josh,
                do you know anything about this ?

                Thanks very much

                Comment


                  #9
                  Hi cls71,

                  This is a bug. Thank you for reporting. In the meantime please push these types of calculations into an indicator and reference the indicator.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Ok. Thanks.

                    Comment


                      #11
                      Hi,

                      I am having a problem with a strategy i wrote that uses some code to calculate an ergodic value. The strategy seems to calculate the ERG values correctly when running against historical data, but as soon as it starts processing real time data the values no longer appear correct (in as much as they stop matching an ergodic indicator I have that uses the same logic.).

                      The ergodic logic in the strategy is pretty straight forward and is all based on closing prices. Here is the logic:

                      medium_closediff.Set(Close[0]-Close[1]);
                      medium_absclosediff.Set(Math.Abs(Close[0]-Close[1]));

                      medium_wERG.Set(WMA(WMA(medium_absclosediff,fast), slow)[0] == 0 ? 0 : 100 * WMA(WMA(medium_closediff,fast),slow)[0] / WMA(WMA(medium_absclosediff,fast),slow)[0]);
                      medium_wErgodic.Set(EMA(medium_wERG,SignalLen)[0]);



                      I have this exact same logic in an indicator....as you can see, it is all based on calculations using the closing price ([0] and [1]). During start up of the strategy, all the Ergodic values match the live chart perfectly during historical processing, but as soon as the strategy starts processing live data it begins calculating different (and wrong) values than the chart.

                      The odd thing is I have looked at the value of the first incoming real time bar to the strategy, and it has the exact same close price as the next real time value on the chart. Even though they both have the same ergodic values up to that point, and even though they both receive the same close price on the next bar, they begin producing different calculations. It seems impossible since the calculations are identical up to that point, and since the only incremental input is the close price of the next bar (which is validated to be the same between the two).

                      If this is the same problem as the bug identified in this thread, is there any way for me to work around this?

                      Comment


                        #12
                        bridenour,

                        Please ensure your indicator has no CalculateOnBarClose line in it and try again.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          The indicator has the correct values, the strategy is producing incorrect values (using the same exact code).

                          The strategy is set to CalculateOnBarClose = true -- are you suggesting i set this to false?

                          thanks

                          Comment


                            #14
                            I checked the indicator, it has CalculateOnBarClose = false. The indicator calculates everything properly.

                            I changed my strategy to CalculateOnBarClose = false. It still produces the same incorrect values. For whatever reason, with each bar that comes in, the calculated value of the ERG just starts getting closer and closer to zero.


                            I am wondering if it is the same bug as was identified in this thread. Works great on historical data and then goes haywire as soon as live data starts being procesed

                            Comment


                              #15
                              The indicator cannot have that line present at all. This is a known bug. Please remove all CalculateOnBarClose lines from the indicator.
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Max238, Today, 01:28 AM
                              2 responses
                              26 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Started by Shansen, 08-30-2019, 10:18 PM
                              25 responses
                              949 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by JonesJoker, 04-22-2024, 12:23 PM
                              8 responses
                              41 views
                              0 likes
                              Last Post JonesJoker  
                              Started by timko, Today, 06:45 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post timko
                              by timko
                               
                              Started by Waxavi, 04-19-2024, 02:10 AM
                              2 responses
                              41 views
                              0 likes
                              Last Post poeds
                              by poeds
                               
                              Working...
                              X