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

MarketAnalyzer - no calculation on custom indicator

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

    MarketAnalyzer - no calculation on custom indicator

    Hi,

    I would like to filter Inside Days, based on a custom indicator, in the MarketAnalyzer.

    See attached sample and code.

    What's wrong with it?

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class MyMaIndicator : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Filtering for ID for usage in Market Analyzer on a daily basis.";
                    Name                                        = "MyMaIndicator";
                    Calculate                                    = Calculate.OnBarClose;
                    IsOverlay                                    = false;
                    DisplayInDataBox                            = false;
                    DrawOnPricePanel                            = false;
                    DrawHorizontalGridLines                        = false;
                    DrawVerticalGridLines                        = false;
                    PaintPriceMarkers                            = false;
                    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(new Stroke(Brushes.HotPink, 2), PlotStyle.Square, "ID");
                }
                else if (State == State.Configure)
                {
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (CurrentBar < 2)
                    return;
                
                if (High[0] <= High[1] && Low[0] >= Low[1])
                    ID[0] = 1;
            }
    
            #region Properties
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> ID
            {
                get { return Values[0]; }
            }
            
            #endregion
        }
    }
    Attached Files

    #2
    Hello Knoppers,

    Thank you for the post.

    I wanted to check, what specifically is the question surrounding what you have provided? I see that the indicator appears to be working on the chart, are you questioning why the value is 0 in the Market Analyzer? If so, are you using exactly the same settings and data source in the Market Analyzer to match the chart?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,


      The value in the MarketAnalyzer column should be 1.

      Please have a look to the code I've provided.


      The parameter values in the chart and MarketAnalyzer are the same. (daily)


      Seems to be strange, so when I check "Inside Days" on an intraday timeframe the MA is working correctly and showing values "1" for those.
      For Daily Chart in the MA columns there are always the value 0.

      Comment


        #4
        Hello Knoppers,

        Thank you for the reply.

        If you are using different timeframes, that would cause differences. This is likely the cause, you can confirm this by debugging the script further.

        If you have ensured that all settings are the same between the chart and MA, this could be caused by data. I would suggest that you use prints to further diagnose what may be happening.

        We have a short guide to debugging your code here: https://ninjatrader.com/support/help...script_cod.htm

        In contrast to what you provided, you could start by adding a print before the condition to see if both tests are evaluating the same data:

        Print(Time[0] + " " + High[0] + " <= " + High[1] + " " + Low[0] + " >= " + Low[1]);
        if (High[0] <= High[1] && Low[0] >= Low[1])

        This type of print would be output to the New -> NinjaScript Output Window where you could use the Timestamp used to verify values between the two tests.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by yertle, Yesterday, 08:38 AM
        7 responses
        28 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by bmartz, 03-12-2024, 06:12 AM
        2 responses
        21 views
        0 likes
        Last Post bmartz
        by bmartz
         
        Started by funk10101, Today, 12:02 AM
        0 responses
        4 views
        0 likes
        Last Post funk10101  
        Started by gravdigaz6, Yesterday, 11:40 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by MarianApalaghiei, Yesterday, 10:49 PM
        3 responses
        11 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X