Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can't add MACD into data chart using ninjascript strategy

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

    Can't add MACD into data chart using ninjascript strategy


    Hi,

    I'm working on my strategy and I'm trying to add MACD indicator on the data chart, instead of using a new panel. I can set up the indicator by setting up the scale justification settings to Left or Overlay and setting panel 1 and works fine, but when I set this setting on my Ninjascript strategy, it stays the same (second panel below the chart).

    You can see on the price panel MACD from the indicator and on the panel below, from the strategy.

    My code is:

    if (State == State.DataLoaded) {​
    MACD1 = MACD(Close, Convert.ToInt32(Fast), Convert.ToInt32(Slow), Convert.ToInt32(Smooth));

    MACD1.ScaleJustification = ScaleJustification.Left; //Overlay also doesnt work
    MACD1.Panel= 1;

    MACD1.Plots[0].Brush = Brushes.DarkCyan;
    MACD1.Plots[1].Brush = Brushes.Crimson;
    MACD1.Plots[2].Brush = Brushes.Transparent;

    AddChartIndicator(MACD1);​
    }


    I also have IsOverlay = true on State == State.SetDefaults

    Does anyone can help me to point out what I'm missing?

    Thank you!

    Attached Files

    #2
    Hello chbruno,

    Thanks for your post.

    When setting MACD1.ScaleJustification = ScaleJustification.Left in State.DataLoaded in a NinjaScript strategy, I am seeing the plot price markers of the MACD indicator appear on the left side of the Chart. See the attached screenshot.

    That said, the MACD indicator that comes with NinjaTrader is programmed to plot in a separate panel. Setting IsOverlay = true in State.SetDefaults of the strategy means that the strategy would be placed on the price panel, not the indicator.

    If you want the MACD indicator to be placed in the price panel when adding it to a NinjaScript strategy then you would need to create a custom MACD indicator that sets IsOverlay = true in the indicator script and then add that custom indicator to the strategy using AddChartIndicator().

    You could consider creating a custom NinjaScript indicator that adds plots to the script using AddPlot() and assigns the MACD()[0], MACD().Avg[0], and MACD().Diff[0] values to plots and sets IsOverlay to true. Then add that indicator to the strategy using AddChartIndicator().

    Or, you could create a copy of the MACD indicator script that comes default with NinjaTrader and modify it. To do so, open a New > NinjaScript Editor window, open the Indicators folder, double-click on the MACD file, right-click in the MACD script, select 'Save as', name the copy of the script, click OK, and then modify the copy of the script.
    Attached Files
    <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 reply.

      I just can't understand why I'm able to set the indicator properly and not able to have the same results when using it with a strategy.
      I believe I will work on a new copy of MACD as you recommended.

      Thank you!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      53 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X