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

Indicator in market analyzer results unexpected

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

    Indicator in market analyzer results unexpected

    Hi... after much help (and patience) from power users on this board, I was able to get an indicator seemingly working. I say seemingly because it runs without error, but with unexpected results. I'm running the indicator in market analyzer to generate alerts. I get an alert on a stock that doesn't match the conditions described in my code. To debug it, I added a print statement just before I set the indicator value to 1 (which is what my alert condition checks for) and the symbol that generates the alert never hits the print line or breakpoint when I debug it. What DOES print out, as well as hit the breakpoint is two different symbols that do indeed match the code conditions, but these don't throw alerts. So close, yet so far. Any help would be awesome... here's the code:

    Code:
    public class RetraceToEMA112712 : Indicator
        {
            #region Variables
            // Wizard generated variables
                private int fastMA = 10; // Default setting for FastMA
                private int medMA = 20; // Default setting for MedMA
                private int slowMA = 50; // Default setting for SlowMA
            // User defined variables (add any user defined variables below)
            #endregion
            
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                Overlay    = false;
                Add(PeriodType.Day,1);
            }
            
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                for (int index = 0; index < BarsArray.Length; index++) 
                {
                    if (CurrentBars[index] < (slowMA+12)) return;
                }
                
                if(BarsInProgress==0)
                {
                    //Check for uptrend
                    int uptrendCheckCount = 0;
                    int countOfClosesOverSlowEma = 0;
                    double keyPriceViolationLevelPriorDay = EMA(Closes[1],slowMA)[0]*1.0025;
                    double keyPriceViolationLevelToday = EMA(Closes[1],slowMA)[0] + Math.Abs(EMA(Closes[1],slowMA)[0] - EMA(Closes[1],slowMA)[1]);
                    
                    for(int i=0;i<10;i++)
                    {
                        if((EMA(Closes[1],fastMA)[i] >= EMA(Closes[1],medMA)[i]) && (EMA(Closes[1],medMA)[i] >= EMA(Closes[1],slowMA)[i]))
                        {
                            uptrendCheckCount++;
                        }
                        
                        if(Closes[1][i+1] >= EMA(Closes[1],slowMA)[i+1])
                        {
                            countOfClosesOverSlowEma++;
                        }
                    }
                    
                    if((countOfClosesOverSlowEma==10)&&(uptrendCheckCount==10))
                    {
                        if(Lows[1][0] <= keyPriceViolationLevelPriorDay)
                        {
                            if((Close[0] > Open[0])&&(Close[0] > keyPriceViolationLevelToday))
                            {
                                Plot0.Set(1);
                                Print("Instrument: " + this.Instrument + ", Time: " + Time[0] + ", CurrentBars[0]: " + CurrentBars[0] + ", CurrentBars[1]: " + CurrentBars[1]);
                            }
                        }
                    }
                }
            }
        }

    #2
    CSharpTrader, does the outcome differ dependent on where you run the script from (MarketAnalyzer or Chart)? How many data do you load in the MA? Does it match what's on the chart and would you use the same session template as well? Also per default MarketAnalyzer would call your indicator with CalculateOnBarClose = false.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand. I haven't tried to view the indicator on a chart... I've actually never set up one of my indicators to plot, my focus has only been to generate alerts. In market analyzer, I'm looking back 70 bars. My "slow mov avg" variable value is 50. Calculate on bar close is set to true. Session template is US Equities RTH. Hope this helps..

      Comment


        #4
        Then I would suggest starting to work with it on a chart to better understand when exactly a signal would be triggered according to your programmed in rules, from there also further debugging would be simpler. I just tried it for example on 300 days on ES 12-12 and it very rarely gives a signal.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          It's not designed to work on a chart... it's for a retracement to a mov avg based on daily data, across a list of hundreds of symbols... as a strategy, the exact same code (except for Plot[1]) tested and ran great. I can't run it on a chart in an interactive way, for the single symbol in the chart may almost never trigger it, as you observed. The purpose is to run it in market analyzer on many symbols to get one or two alerts a day. Experimenting with it on a chart isn't quite practical.

          Did you try it in market analyzer?

          Comment


            #6
            How do you confirm then the signal is correct or not if you don't cross check via a chart?
            BertrandNinjaTrader Customer Service

            Comment


              #7
              As a strategy, I looked at 1500+ backtest results. Very nice setups. In the current situation as an indicator, it's performing as I described... so maybe I'm missing something. I don't know how I could realistically load a chart with a symbol's data, and wait for an alert to trigger, in order to debug it.. as you noted, most symbols don't give one for days or weeks... it's effective for retracements to daily data, which aren't frequent. Is there a way to run it as an indicator/ alert on historical data?

              Comment


                #8
                You can certainly run your MA indicator on a chart and scroll through historical data to see it's signals generated, the MA would just pickup this Plot value and issue an alert on it, but the indicator / signals are the same.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Hi Bertrand... I just looked at several charts of both periods (daily and 5 min bars) and I don't see any indicators on the charts where I'd expect them, either..

                  Comment


                    #10
                    This would then unfortunately mean you would need to look into enhancing / debugging the present logic in your script to meet your needs - the chart can be a valuable help here to confirm it's hitting 'home' as you would expect - as the MA would process the signal generation in the same way, so there would be no special handling needed.
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      There's more to work with here than that... I'd love it if you could take a closer look. As I've said, the identical logic performs great in backtesting. Also of interest, it does generate alerts... just not ones that can be tracked in the output window, or a visual studio breakpoint. This clearly shows there's little I can do, if the alerts being triggered, I can't see. On the chart, either for that matter.

                      If you review it yourself, it's not particularly grueling code or of unusual conditional checks. Three stacked moving averages on the daily timeframe. The prior day violated a price level just over the slow one. Today, in a 5 min bar, we're trading above that point.

                      Between the correct conditions that do appear while I debug (I have a breakpoint on Plot0.Set(1) that gets hit where I expect it to), but don't actually trigger a physical alert in market analyzer, as well as an alert that is generated, that shouldn't be, it appears to not be my logic, but a platform- specific technical issue that I can't find.

                      Comment


                        #12
                        Originally posted by CSharpTrader View Post
                        Hi Bertrand. I haven't tried to view the indicator on a chart... I've actually never set up one of my indicators to plot, my focus has only been to generate alerts. In market analyzer, I'm looking back 70 bars. My "slow mov avg" variable value is 50. Calculate on bar close is set to true. Session template is US Equities RTH. Hope this helps..
                        I have found that when I want to debug MarketAnalyzer snafu's, the best debugger has been my eyes, comparing what I expect to what I see on a chart.

                        Comment


                          #13
                          It would be great if only I could see them (buggy or not on a chart). They only trigger and go to the output window.

                          Comment


                            #14
                            Here's a specific question... can data become corrupt for a symbol? In my case, 'RAD' is giving the false alerts.

                            Comment


                              #15
                              Originally posted by CSharpTrader View Post
                              It would be great if only I could see them (buggy or not on a chart). They only trigger and go to the output window.

                              Debugging Market Analyzer consists of:
                              1. Create an instrument list and load it into Market Analyzer.
                              2. Create a chart with the same indicators as you are monitoring in the Market Analyzer.
                              3. Link the chart to the Market Analyzer window.
                              When you get a hit on a symbol, you click on it, and it is automatically loaded in the chart. You cross-check what is on the chart with what Market Analyzer is saying, so as to see if your eyes are just telling you lies.
                              Last edited by koganam; 11-28-2012, 02:44 PM. Reason: Corrected grammar.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by mattbsea, Today, 05:44 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post mattbsea  
                              Started by RideMe, 04-07-2024, 04:54 PM
                              6 responses
                              31 views
                              0 likes
                              Last Post RideMe
                              by RideMe
                               
                              Started by tkaboris, Today, 05:13 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post tkaboris  
                              Started by GussJ, 03-04-2020, 03:11 PM
                              16 responses
                              3,282 views
                              0 likes
                              Last Post Leafcutter  
                              Started by WHICKED, Today, 12:45 PM
                              2 responses
                              20 views
                              0 likes
                              Last Post WHICKED
                              by WHICKED
                               
                              Working...
                              X