Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom Indicator to read MACD parameters and values

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

    Custom Indicator to read MACD parameters and values

    Hi,

    As I'm working on the custom indicator that will read MACD settings and the macd/avg/hist values (using plots Values[x]) without loading the MACD indicator inside the indicator.

    Note: Both custom indicator and MACD indicator are already on the same chart.

    I looked at MACD indicator code (at bottom of MACD.cs):

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private MACD[] cacheMACD;
    public MACD MACD(int fast, int slow, int smooth)
    {
    return MACD(Input, fast, slow, smooth);
    }
    
    public MACD MACD(ISeries<double> input, int fast, int slow, int smooth)
    {
    if (cacheMACD != null)
    for (int idx = 0; idx < cacheMACD.Length; idx++)
    if (cacheMACD[idx] != null && cacheMACD[idx].Fast == fast && cacheMACD[idx].Slow == slow && cacheMACD[idx].Smooth == smooth && cacheMACD[idx].EqualsInput(input))
    return cacheMACD[idx];
    return CacheIndicator<MACD>(new MACD(){ Fast = fast, Slow = slow, Smooth = smooth }, input, ref cacheMACD);
    }
    }
    }
    I understand that MACD indicator is public accessible for other indicator.

    is it possible for you to provide us the basic sample indicator that will allow for accessing to MACD settings and read the values directly without using AddChartIndicator inside the custom indicator?

    It will be a big help for us.

    Thanks.



    #2
    Hello nothingbutprofits,

    Thanks for your post.

    You could access values from the MACD indicator without using AddChartIndicator() by assigning a value of the MACD indicator to a double variable.

    An example would look something like this.

    Code:
    // Prints the current MACD value
    double value = MACD(12, 26, 9)[0];
    Print("The current MACD value is " + value.ToString());
    Note that AddChartIndicator() adds an indicator to a strategy only for the purpose of displaying it on a chart.

    If you would like to plot the MACD values in a custom indicator, you could assign the value of the MACD indicator to a plot created using AddPlot().

    See this help guide page for more information and examples of accessing MACD indicator values: https://ninjatrader.com/support/help...gence_macd.htm

    Also, see this help guide for more information about AddPlot(): https://ninjatrader.com/support/help...t8/addplot.htm

    And, see the attached example script which demonstrates assigning the MACD value to a double variable and assigning that double variable to a plot.

    Let us know if we may assist further.
    Attached Files
    Last edited by NinjaTrader_BrandonH; 10-26-2021, 08:09 AM.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thanks for your response.

      I tried your MACDCustomIndicator ..and realized that I may need to explain more in details. (my apologies)

      1) The indicator will be used as a "tool" to read MACD parameters and values, not to display the indicator on chart. It will be used for linking to "button" to display the MACD parameters/last values (macd, avg, diff)

      I see the MACD (12,26,9)[0] settings there.

      Is it possible for the custom indicator to read the actual MACD settings (fast, slow, smooth) from the existing MACD indicator on the chart, instead of dummy values (12,26,9) and display it in draw.text on PricePanel chart?

      Comment


        #4
        Hello nothingbutprofits,

        Thanks for your note.

        You would not be able to read the Fast, Slow, and Smooth indicator properties being used by an existing MACD indicator that is on the chart. You would only be able to access the MACD plots that are listed in the MACD help guide page below (MACD, Avg, Diff).

        MACD: https://ninjatrader.com/support/help...gence_macd.htm

        To get the values of indicators existing on a chart, see post #6 of this forum thread: https://ninjatrader.com/support/foru...ors-in-a-chart

        Let us know if we may assist further.

        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Originally posted by NinjaTrader_BrandonH View Post
          Hello nothingbutprofits,

          You would not be able to read the Fast, Slow, and Smooth indicator properties being used by an existing MACD indicator that is on the chart. You would only be able to access the MACD plots that are listed in the MACD help guide page below (MACD, Avg, Diff).
          MACD: https://ninjatrader.com/support/help...gence_macd.htm
          Understood. I'm just asking.

          Originally posted by NinjaTrader_BrandonH View Post
          To get the values of indicators existing on a chart, see post #6 of this forum thread:

          Hi, Is it possible to acces and get the value of all Indicators, that are in a Chart? So, if I have an indicator, from which I don't know the code, can I get
          This idea will work...as the best workaround.

          You're awesome..many thanks!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          576 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          334 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          553 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X