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 changing value after F5

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

    Indicator changing value after F5

    Hi,
    I'm having trouble finding an error, I would appreciate if you could give me some hint, because currently I have no clue as to what is wrong :
    so I developped this indicator
    when I press F5, the indicator is reloaded and redraws,
    but the recent values change. See the images attached.
    I did not compile anything before pressing F5.

    What could be wrong, any idea where to look ?

    thanks for your help
    Attached Files

    #2
    fle,

    Indicator logic is highly dependent on the data it is processing. When you process in real-time with CalculateOnBarClose=false you can generate different results depending on your indicator logic. You will need to thoroughly debug with Print() statements tracking every part of your calculations to find the area of your code causing issues.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      thank you for your reply,

      do you think it could help to try with CalculateOnBarClose=true ?

      Comment


        #4
        Believe you will have the same results with it set to true when you reload historical data.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I've changed the CalculateOnBarClose to true,
          and let it run for some time now, and it seems to be correct now : historical data reloaded match the real time data collected.

          Thank you,
          you have been very helpfull,
          as usual.

          Comment


            #6
            Unfortunately, after longer testing, it appears that the problem is not solved.

            I have both indicator and strategy set to CalculateOnBarClose=true.
            I changed from Gain feed to IB.

            Could it be a rounding number problem (the same indicators are running smoothly on TS) ?
            Is this just the way NT works, and there is nothing to do about it ?

            Thank you for your help.

            Comment


              #7
              Hi fle, jumping in here, however I remember an issue from the past we discussed - is the indicator plotted from a strategy via the StrategyPlot techniques?
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Hi Bertrand,

                You remember correctly, the strategy uses StrategyPlot to plot the indicator.

                However, my problem here is not in the plot (I dumped my requirement of having the indicator ploted while backtesting, even if it is useful).
                I can withness the problem in my strategy, and also when I plot the indicator in a graph.

                What happen is that the indicator seems to be calculated on different datas, be it done in real time (tested using IB or Gain) or on historical data (after doing F5).

                On real time data, the indicator makes steps, is not smooth.
                As a result, I get fake signals, non valid entries or premature exits.

                I don't understand if the problem comes from my coding, or if it it just the way NT works.
                Any hint would be appreciated.

                Comment


                  #9
                  fle,

                  To understand where your calculations come from you would need to use Print() statements along every single step of the way so you can track it. Then you should compare it with calculations done by hand to find where the calculations differ before you can address any potential reasons for the differences.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi again,
                    I followed you advise,
                    and printed the Time OHLC and indicator value
                    I started the strategy, let it run a few minutes and took a snapshot of the values
                    Then I pressed F5, waited for the strat to start again and took another snapshot
                    The result is in the file attached.

                    After pressing F5, past OHLC values are changed, hence the indicator as well.

                    This was done using Gain feed.
                    I tried the same with IB as datafeed, and with similar results.

                    What can I do to solve this problem ?
                    Attached Files

                    Comment


                      #11
                      fle,

                      Please debug the calculations within your indicator one by one. Remember, when you are processing data in real-time with CalculateOnBarClose = false you will get a lot more whiplashing price action which depending on how your code calculates can influence the final outcome of your indicator. Unfortunately we cannot go through the code line by line this for you, but if you take literally print out every single step of the calculations and run it by hand on the side you will be able to find where in your code it is doing what it is doing. Good luck.

                      Also note that reloading historical data can create different data sets which cause different prices.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        hi Josh,
                        thank you for your answer.

                        Indicator + strategy are CalculateOnBarClose = true
                        The problem is not in the indicator.
                        As you can see from my attachement, the data OHLC are not the same in realtime or reloaded.

                        From your comment I understand it is a normal behavior of NT, some sort of filtering being applied on backfilled data.
                        (of course this is not what I expected, because it spoils the validity of backtesting)

                        Thank you for you inputs.

                        Comment


                          #13
                          fle,

                          When it comes to data, what you see is what is coming through from your data provider. You could try a different data feed to see if you get better results with a different one.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi again,
                            after deep investigation, I think the problem is due to the multiple instruments not being in sync.
                            As a result, when OnBarUpdate fires on my first dataserie, I might not have the latest value for the other dataseries, and it creates this jitter on the chart (and trading signals calculation)

                            I have tried to wait for having all data up to date before doing my main calculation, with the following code :
                            Code:
                                        //ignore data other than EURUSD, unless we are waiting for completion of incoming data from various feeds
                                        if ((BarsInProgress != 0 && !WaitFlag) || ErrorFlag )
                                        {
                                            return;    
                                        }
                            
                                        DateTime current = DateTime.Now;
                                        for (int index = 0; index < maxDatafeedNb; index++) 
                                            {
                                                if ((ToTime(Times[0][0]) != ToTime(Times[pairDatafeed[index].BarsArrayNb][0])) && pairDatafeed[index].tradePosition!=0)
                                                {
                                                    WaitFlag = true;
                                                    Print(current.ToString() + ": wait "+ToTime(Times[pairDatafeed[index].BarsArrayNb][0]).ToString() + " "+ pairDatafeed[index].plotName + " barNb " + CurrentBar );
                                                    return;
                                                }                        
                                            }
                                        WaitFlag=false;
                                        for (int index = 0; index < maxDatafeedNb; index++) 
                                        {
                                            if (!Historical )                
                                                    Print(current.ToString() + ": "+ToTime(Times[pairDatafeed[index].BarsArrayNb][0]).ToString() + " "+ pairDatafeed[index].plotName + " barNb " + CurrentBar + " barRX "+barsReceived.ToString());
                                        }
                            using the Print() loop, I can see that all my dataseries have now the same time when they enter in the main calculation block of code.

                            However, a collateral damage is that now the indicators do not plot on my chart.
                            I can see in the log and w/ a Print() that the main calculation code is executed. But nothing is printed (via StrategyPlot).

                            I suppose its because now StrategyPlot is not called from the primary dataserie. I saw a post on that.
                            I work with CalculateOnBarClose=true, and would like to avoir COBC=false, because then I bump into other problems.

                            But then, how to do this sync ? any suggestion would be welcomed

                            Comment


                              #15
                              fle__,

                              Unfortunately that is a limitation for StrategyPlot.

                              You are correct in that each bar series is not necessarily in time with each other. They update whenever their particular series updates. Unfortunately there is no easy workaround except plot it back in BIP=0 once everything is calculated.
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by wzgy0920, 04-20-2024, 06:09 PM
                              2 responses
                              26 views
                              0 likes
                              Last Post wzgy0920  
                              Started by wzgy0920, 02-22-2024, 01:11 AM
                              5 responses
                              32 views
                              0 likes
                              Last Post wzgy0920  
                              Started by wzgy0920, Yesterday, 09:53 PM
                              2 responses
                              49 views
                              0 likes
                              Last Post wzgy0920  
                              Started by Kensonprib, 04-28-2021, 10:11 AM
                              5 responses
                              191 views
                              0 likes
                              Last Post Hasadafa  
                              Started by GussJ, 03-04-2020, 03:11 PM
                              11 responses
                              3,230 views
                              0 likes
                              Last Post xiinteractive  
                              Working...
                              X