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

EMA from higher timeframe

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

    EMA from higher timeframe

    Hi Ninjatrader support team,

    I encountered a problem when using EMA Indicator on a secound dataseries. The plotting gets stopped after a while:

    Click image for larger version

Name:	emaStop.png
Views:	518
Size:	82.3 KB
ID:	1056094

    What am I doing wrong? When printing the values, the indicator seems to calculated correctly... any advice?

    I use this code:

    Code:
     if (State == State.Configure)
                {
                    AddDataSeries(BarsPeriodType.Minute, 60);
                }

    Code:
     if(State == State.DataLoaded)
                {
                    _ema50Indicator = EMA(BarsArray[1] ,50);
                    _ema200Indicator = EMA(BarsArray[1],200);
                    _umkehrStaebeIndicator = Umkehrstaebe(Dochtgroese, ReversalMindestGroese, KulanzReversal, KulanzAusenstaebe, H1Signale);
                    _ausenStaebeIndicator = Aussenstaebe(KulanzAusenstaebe);
    
                    AddChartIndicator(_umkehrStaebeIndicator);
                    AddChartIndicator(_ausenStaebeIndicator);
                    AddChartIndicator(_ema50Indicator);
                    AddChartIndicator(_ema200Indicator);
                }
    Another problem: When using playback connection I think the values are wrong due to a lack of available data. How can I load more data from the past when backtesting a single day through playback connection?

    Best regards,
    Johnny

    #2
    Hello Johnny,

    Are there errors in the Log tab of the Control Center?

    Is this a script you are making?

    Have you adding prints to ensure the values are proper values?
    May we see the output from your prints?
    https://ninjatrader.com/support/foru...121#post791121

    Historical data must be downloaded and cached to the computer before the Playback connection is connected to be used for a backtest (with some caveats).
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      there are no errors in Control Center and on the left side you can see the output. Based on the fact that the indicator is calculated on an hourly basis and displayed on a 10 minute chart I would expect some "step-like lines". The behavior on a live account is the same, so I can confirm that it's not related to playback connection or historical data.
      Any advice? Do I need to add a plot or something?

      Click image for larger versionName:	emaStop2.pngViews:	1Size:	185.9 KBID:	1056341

      Best regards,
      Johnny

      Comment


        #4
        Hello Johnny,

        Your previous inquiry was:

        "The plotting gets stopped after a while:"

        Is this still the issue you would like assistance with?

        Are there prints for the bars that are not showing a plot?


        With your new inquiry:
        "Based on the fact that the indicator is calculated on an hourly basis and displayed on a 10 minute chart I would expect some "step-like lines""

        What is the input series supplied to the indicator?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I use BarsArray [1] shown in the code in post 1 and AddChartIndicator. So the indicator should handle the plotting there is no need to handle the plotting in my strategy right?

          Comment


            #6
            Hello Johnny90,

            With historical data, this may need to be downloaded from a real-time connection before connecting to the playback.

            I'm looking further into this behavior with AddChartIndicator(). I appreciate your patience.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Johnny90,

              Unfortunately, an indicator being added via AddChartIndicator() cannot use any additional data series hosted by the calling strategy, but can only use the strategy's primary data series. If you wish to use a different data series for the indicator's input, you can add the series in the indicator itself and explicitly reference it in the indicator code (please make sure though the hosting strategy has the same AddDataSeries() call included as well)

              Below is a link to where this is mentioned in the help guide.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Thanks Chelsea, its working now

                Comment


                  #9
                  Hey Chelsea,

                  i still have a little problem:

                  First of all, I copied EMA Indicator, added the 60 minute timeframe there and changed the code to this:

                  Code:
                     private double h1Value = 0;
                  
                          protected override void OnBarUpdate()
                          {
                              if (BarsInProgress == 0)
                              {
                                  Value[0] = h1Value;
                                  return;
                              }
                  
                              if (BarsInProgress == 1)
                              {
                                  if (Value.Count > 0)
                                  {
                                      h1Value = (CurrentBar == 0 ? Input[0] : Input[0] * constant1 + constant2 * Value[1]);
                                      return;
                                  }
                  
                              }
                          }
                  Now, when I add this indicator to the 10 minute chart I got the same values from EMA indicator in 60 minute chart, exactly what I wanted.

                  Click image for larger version

Name:	emaMultipleTimeframe.png
Views:	484
Size:	95.1 KB
ID:	1058790


                  Now, I wanted to use my EMAH1 indicator in my strategy but the output shows slightly different values than the visible lines and I don't understand why.
                  Also, when I use the "AddChartIndicator" code with my strategy I still got the visual problems described earlier on.

                  Click image for larger version

Name:	output.png
Views:	468
Size:	40.1 KB
ID:	1058791

                  Any advise?

                  Best regards, Johnny

                  Comment


                    #10
                    Hello Johnny,

                    I am not able to reproduce this behavior.

                    Attached is a test script.

                    Below is a link to a video of the test.
                    https://drive.google.com/file/d/1gee...w?usp=drivesdk

                    If you test this test strategy on a new chart are you experiencing different behavior than what is shown in the video?

                    (edit, the indicator needs to use the previous secondary bar plot value not primary bar plot value for the calculation.)
                    Attached Files
                    Last edited by NinjaTrader_ChelseaB; 06-06-2019, 10:12 AM.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello Chelsea,

                      thanks for your fast reply, and yes, I checked the code and the output is now the same. Then I encountered that the difference between 10 minute and 60 minute was related by a lack of history data in 10 minute chart. I set up the "days to load" option, set the same value from 60 minute chart and got the same values in live connection.

                      Now, when I run this in playback mode I still have different values compared to 60 minute chart. I guess this is caused by a lack of data but don't know how to set up playback connection properly. Replay data is loaded completly for every day.


                      Click image for larger version

Name:	emaMultipleTimeframe2.png
Views:	502
Size:	123.8 KB
ID:	1058940

                      Click image for larger version

Name:	marketReplay.png
Views:	479
Size:	40.6 KB
ID:	1058941

                      Comment


                        #12
                        Hello Johnny90,

                        When an indicator is added to a chart with AddChartIndicator() it is the same instance on the chart that the values are coming from in the script.

                        The plot values printed from the indicator must always be the same values that are appearing visually on a chart.

                        If you are able to reproduce this using AddChartIndicator() and you are not manually adding an indicator to a chart separately (which may be a different instance) I would like to schedule a call with you to observe this.


                        With Playback, historical data will load on the chart before the playback begins. If you are using the Simulation license, you will need to download all of the historical data for the entire Days to load period previous to the point where the playback will start from a real-time data feed or brokerage connection before connecting to the playback.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Chelsea,

                          sorry, my answer was missleading. The problem with output is solved.
                          The problem i have now, are differences between 10 minute chart (with your ema Sample) and 60 minute chart ( with original ema indicator) when using Playback connection. The provided screenshot above should make the problem clear. Could you try reproducing this problem, i thought for market replay only replay data is necessary? I downloaded it completly, shown in second screenshot.

                          Best regards,
                          Johnny

                          Comment


                            #14
                            Hello Johnny,

                            If you are comparing the instance of an indicator from a script with a completely separate instance added directly to a chart, then you need to ensure all of the data is exactly the same.

                            What is the time and date of the first bar and second bar printed from the script?

                            What is the time and date of the first bar and second bar on the chart that has the indicator directly applied?
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hello Chelsea,

                              if I apply the indicator to the chart I'm able to set the days to load option and if I do so, the values are the same.
                              Click image for larger version

Name:	Daystoload.png
Views:	477
Size:	61.7 KB
ID:	1059411

                              if I use the same indicator in strategy I'm not able to set the days to load option, and "required bars to trade" don't seem to make any difference. The result is that a playback set up for the 17th May the calculation for ema 60 starts at 13th May...

                              Click image for larger version

Name:	DaystoloadStrategy.png
Views:	466
Size:	74.3 KB
ID:	1059412

                              Click image for larger version

Name:	DaystoloadStrategy2.png
Views:	458
Size:	55.4 KB
ID:	1059413

                              Hope you can help,

                              best regards,
                              Johnny

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by fx.practic, 10-15-2013, 12:53 AM
                              5 responses
                              5,406 views
                              0 likes
                              Last Post Bidder
                              by Bidder
                               
                              Started by Shai Samuel, 07-02-2022, 02:46 PM
                              4 responses
                              98 views
                              0 likes
                              Last Post Bidder
                              by Bidder
                               
                              Started by DJ888, Yesterday, 10:57 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by MacDad, 02-25-2024, 11:48 PM
                              7 responses
                              160 views
                              0 likes
                              Last Post loganjarosz123  
                              Started by Belfortbucks, Yesterday, 09:29 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post Belfortbucks  
                              Working...
                              X