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

MACD Indicator values

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

    MACD Indicator values

    Hi,

    I encountered an offset between the MACD indicator value (blue bar chart) and the same indicator applied in a strategy (value printed in chart).

    Both applied period (15m) and setting (10, 38, 38) are the same! So I would expect the values be the same as well. But the value of the strategy is at 41 an the indicator show -14.

    What could be the cause of this difference?

    Thanks.
    Attached Files

    #2
    Hello P-Sionic, and thank you for your query.

    So that I may have a more complete picture of what is happening, would it be possible for you to show me the code in your strategy both to generate and print out your MACD values? Could you also let me know what instrument you are trading, including its expiry date, and at what time of day you observed this?
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick reply.

      Instrument: $GER_CFDEUR (=German Index via FXCM)
      Start of Code:

      protected override void Initialize()
      {
      Add(PeriodType.Minute, 15);
      Add(PeriodType.Minute, 60);

      CalculateOnBarClose = false;
      ExitOnClose = false;
      TraceOrders = true;
      EntryHandling = EntryHandling.UniqueEntries;
      }

      protected override void OnBarUpdate()
      {
      Info = "MACD: " + Math.Round(BarsArray[1], MACD(10, 38, 38)[1],0)"
      DrawTextFixed("",Info,TextPosition.BottomRight);
      }

      End of Code



      So the MACD value should go directly into the print out.

      Presently the print out value is at -5 and the value of the MACD indicator chart is at around -10.
      Attached the settings of the MACD indicator.
      Attached Files

      Comment


        #4
        Hello again P-Sionic,

        I noticed that you called Math.Round using the overload covered in this publicly available MSDN documentation link :

        Rounds a value to the nearest integer or to the specified number of fractional digits.


        The first argument is the number you are rounding, where the second argument is the maximum number of decimal places. I have reason to believe, therefore, that the code you are using is actually printing the value of BarsArray[1] , and not the value of your MACD indicator. I also noticed that you are looking 1 bar ago with the MACD indicator, rather than examining the current bar.

        I would like to ask, then, if you could use this in your Print statement, and if it gives you a different result :

        Math.Round(MACD(10, 38, 38)[0], System.MidpointRounding.AwayFromZero)

        Or, if you are comparing to your secondary data series in both instances,

        Math.Round(MACD(BarsArray[1], 10, 38, 38)[0], System.MidpointRounding.AwayFromZero)

        Please let us know if there are any other ways we can help.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Thanks that was exactly it!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by proptrade13, Today, 11:06 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by quantismo, 04-17-2024, 05:13 PM
          4 responses
          32 views
          0 likes
          Last Post quantismo  
          Started by love2code2trade, 04-17-2024, 01:45 PM
          4 responses
          32 views
          0 likes
          Last Post love2code2trade  
          Started by cls71, Today, 04:45 AM
          2 responses
          10 views
          0 likes
          Last Post eDanny
          by eDanny
           
          Started by kulwinder73, Today, 10:31 AM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Erick  
          Working...
          X