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

Simple MACD indicator question

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

    Simple MACD indicator question

    So I'm just trying to make a simple indicator for my market analyzer telling me whether or not the MACD diff is larger or smaller than it was 1 bar ago. But it's not returning any data? Wondering what I'm doing wrong. Thanks.

    namespace NinjaTrader.NinjaScript.Indicators.MyIndicators
    {
    public class myMACDdiff : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "myMACDdiff";
    Calculate = Calculate.OnPriceChange;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;

    AddPlot(Brushes.Orange, "MACDdiff");
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    double currentdiff = MACD(6, 20, 9).Diff[0];
    double olddiff = MACD(6, 20, 9).Diff[1];
    Value [0] = currentdiff - olddiff;


    }
    }
    }

    #2
    Hello tvaughan4,

    Do you see any errors appear in the Log tab of the Control Center when running this script?

    I see that an index of 1 barsAgo is used without any check that there is a bar 1 bar ago.



    As a tip, to export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      the CurrentBar check was the issue, thank you, attached the code

      different issue now. it seems the output is slightly different from what I get on the graph on the chart. So right now I'm getting a difference reading of 2.28 on my market analyzer for this code. But if I do it manually on the histogram on the chart, it comes out to 2.83. Any idea why the two readings are different? should be the same I would think?
      Attached Files

      Comment


        #4
        nevermind, it was a data series issue, they match up now

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by RubenCazorla, Today, 09:07 AM
        2 responses
        13 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by i019945nj, 12-14-2023, 06:41 AM
        7 responses
        82 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by timmbbo, 07-05-2023, 10:21 PM
        4 responses
        158 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by tkaboris, Today, 08:01 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by Lumbeezl, 01-11-2022, 06:50 PM
        31 responses
        820 views
        1 like
        Last Post NinjaTrader_Adrian  
        Working...
        X