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

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 GussJ, 03-04-2020, 03:11 PM
        16 responses
        3,280 views
        0 likes
        Last Post Leafcutter  
        Started by WHICKED, Today, 12:45 PM
        2 responses
        19 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Started by Tim-c, Today, 02:10 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Taddypole, Today, 02:47 PM
        0 responses
        5 views
        0 likes
        Last Post Taddypole  
        Started by chbruno, 04-24-2024, 04:10 PM
        4 responses
        53 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Working...
        X