• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EMAs different when backtesting

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

    EMAs different when backtesting

    Hi all, wondering if someone can help :-

    I am creating a strategy that looks at the 8, 20 and 50 EMAs in code...and then does something.

    I have also added the 8 20 and 50 EMAs to my chart as standard indicators.

    The problem I am having is during back-testing using the StrategyAnalzer. When I run the back-test and step into my code (VisualStudio) - I see values for the EMAs that are different to those that I see on the standard indicators.

    I have checked the standard indicators and they are all set up correctly and also check via TradingView - so I know those values are correct. It`s just that in my strategy in ninjascript - I see completely different values.

    Code used in script :

    EightEMA = EMA(Close, 8)[0];
    TwentyEMA = EMA(Close, 20)[0];
    FiftyEMA = EMA(Close, 50)[0];

    For example GBPUSD (Kinetic data source) for 13/12/2019 shows 8 EMA = 1.31651 (which is correct). However in code I see a different value.


    Any help would be appreciated.

    Thanks







    #2
    Hello foxy_rav,

    Thanks for your post.

    I would recommend comparing values which are printed in from your strategy against the values on the Strategy Analyzer's chart. This ensures that the indicator values you are comparing in the strategy are the same indicator values which it would add to a chart. Indicators added to a separate chart which are not added by the strategy would not be associated with the strategy and could have different results due to a difference in settings and the data which the indicator is applied to.

    Demo - https://drive.google.com/file/d/1g5T...w?usp=drivesdk

    In the test above, we see the strategy's prints for the indicator and we are comparing them to the Strategy Analyzer's chart with the Data Box open to check bar indexes and indicator plot values.

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi, thank you for the response.

      The demo was helpful and I had a light-bulb moment based on what the presenter was showing/saying - I was not setting the BarsRequiredToTrade value in the StrategyAnalyzer and therefore the EMAs were wrongly being calculated in the back-test.

      Setting this property correctly in the Analyzer and printing out the values - they are the same and as expected.

      I do have a couple of more questions :-

      1) Is there a way of setting the BarsRequredToTrade in code ? Would this be correct : https://ninjatrader.com/support/help...redtotrade.htm ??

      2) In the demo the Currentbar index is being written to the output window. - Is there a way of outputting the current bar`s date/time ?


      Thanks again









      Comment


        #4
        Hello foxy_rav,

        Thanks for your post.

        BarsRequiredToTrade/BarsRequiredToPlot can be set in OnStateChange under State.SetDefaults or State.Configure.

        You can print Time[0] to print the timestamp of the bar that is processing.

        Let us know if there is anything else we can do to help.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cutzpr, Today, 05:22 PM
        0 responses
        1 view
        0 likes
        Last Post cutzpr
        by cutzpr
         
        Started by ATMtrader0001, Today, 01:13 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by NtFan, Today, 04:18 PM
        0 responses
        6 views
        0 likes
        Last Post NtFan
        by NtFan
         
        Started by kaseipds, Today, 01:29 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by kaseipds, Today, 12:04 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X