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

Custom indicator help needed

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

    Custom indicator help needed

    Hi. I'm still working at resolving why my custom multi- series indicator isn't performing as expected. I'm running it from market analyzer to generate alerts. I have two sample alerts attached in the pdf. One I'd expect, one I wouldn't. Both were triggered yesterday. As you can see from the one I didn't expect, the logic of my code doesn't pass at all in that case, yet the alert was generated. Also, you can view on the chart attached that this setup isn't plotted by the indicator on a chart.

    I've read some somewhat seemingly conflicting information on the use of if(Historical){return;} to make sure alerts are based only on processing from the latest bar. Perhaps this is part of my problem. My code is below, and sample results are attached. Hoping to get it wrapped up, many thanks in advance...

    Code:
    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()
            {
                if(Historical){return;}
                
                for (int index = 0; index < BarsArray.Length; index++) 
                {
                    if (CurrentBars[index] < (slowMA+12)) return;
                }
                
                if(BarsInProgress == 0)
                {
                    int retraceType = 0;
                    
                    //Is current intraday action favorable?
                    if((Close[0] > Open[0]) && (EMA(5)[0] > EMA(10)[0]))
                    {
                        int uptrendCheckCount = 0;
                        int countOfClosesOverSlowEma = 0;
                        double todaysEstimatedDailySlowMovAvg = (EMA(Closes[1],slowMA)[0] + Math.Abs(EMA(Closes[1],slowMA)[0] - EMA(Closes[1],slowMA)[1]));
                        double keyPriceViolationLevelPriorDay = EMA(Closes[1],slowMA)[0] * 1.025;
                        double keyPriceViolationLevelToday = todaysEstimatedDailySlowMovAvg * 1.025;
                        
                        //Make sure current price is > today's estimated slow daily MA.
                        if(Close[0] > todaysEstimatedDailySlowMovAvg)
                        {
                            //Check for uptrend on daily
                            for(int i = 0;i < 10;i++)
                            {
                                //Count up mov avg lines are stacked daily bars
                                if((EMA(Closes[1],fastMA)[i] >= EMA(Closes[1],medMA)[i]) && (EMA(Closes[1],medMA)[i] >= EMA(Closes[1],slowMA)[i]))
                                    uptrendCheckCount++;
                                
                                //Count up past closes >= slow ma line-small buffer (.1%) daily bars
                                if(Closes[1][i] >= EMA(Closes[1],slowMA)[i] * .999)
                                    countOfClosesOverSlowEma++;
                            }
                            
                            if((countOfClosesOverSlowEma == 10) && (uptrendCheckCount == 10))    //if it's an uptrend
                            {
                                //if close yesterday violated level, or 
                                if(Closes[1][0] <= keyPriceViolationLevelPriorDay) {retraceType = 1;}
                                //if today's price level has been violated,
                                else if(Low[LowestBar(Low,Bars.BarsSinceSession-1)] < keyPriceViolationLevelToday) {retraceType = 2;}
                            }
                        }
                    }
                    Plot0.Set(retraceType);
        
                }
            }
    Attached Files

    #2
    Hello CSharpTrader,
    Thanks for your note.

    To assist you further may I know what is the value of slowMA.

    Please make sure you are loading enough data (slowMA +12) so that the indicator can calculate the values.

    Also you have set if(Historical){return;}. Thus it is a real time indicator only.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thank you Joydeep. I have slowMA set to 50. I'm looking back 70 bars in market analyzer. I was told to try "if Historical" yesterday, after I wondered if I might be seeing trades/ alerts on conditions that were valid in the past, but not on the last bar.

      Comment


        #4
        Hello CSharpTrader,
        If I apply the indicator with 70 bars in the Market Analyzer I am getting 0 (zero) as the value.

        This seems to be ok, as your conditions must not have fulfilled.

        To assist you further may I know what scenario you are expecting.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Joydeep, I'm running the indicator to generate alerts from a symbol list in market analyzer. I'm not sure what you ran it on... on most symbols, most days, you would expect 0. Did you see the attached pdf? It shows alerts generated, from yesterday's market analyzer, on 5 min bars, 70 bars loaded. I attached one expected, one unexpected alert.

          Comment


            #6
            Hello CSharpTrader,
            To assist you further may I know how are you setting up the alert as there are no alert codes in the NinjaScript code. Are you using the alert feature in the Market Analyzer.

            If so then can you tell the exact settings so that I can test it at my end.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Yes... I have an alert condition set in market analyzer. I have the conditional check of > 0.

              Comment


                #8
                Hello CSharpTrader,
                When I load the indicator I can see the closing price as the value printed on the Market Analyzer at first. This may be due the the empty plot values. This might trigger the alerts (since Close > 0).

                If you try modifying your code and create the alert from the NinjaScript code itself then what result you are getting

                Code:
                if((countOfClosesOverSlowEma == 10) && (uptrendCheckCount == 10))    //if it's an uptrend
                {
                    //if close yesterday violated level, or 
                    if(Closes[1][0] <= keyPriceViolationLevelPriorDay) 
                	{
                		retraceType = 1; 
                		[B]Alert("Alert" + CurrentBar, Priority.Medium, "Lert type 1", "Alert1.wav", 0, Color.Black, Color.White);	[/B]
                	}
                    //if today's price level has been violated,
                    else if(Low[LowestBar(Low,Bars.BarsSinceSession-1)] < keyPriceViolationLevelToday) 
                	{
                		retraceType = 2; 
                		[B]Alert("Alert1" + CurrentBar, Priority.Medium, "Lert type 2", "Alert1.wav", 0, Color.Blue, Color.White);[/B]
                	}
                }
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  A good idea Joydeep... but I have run it with both > 0 and =1 (at different times), and the results are the same. =1 returned the ticker RAD alert.

                  Comment


                    #10
                    Hello CSharpTrader,
                    When I set the Plot values to == 1 (one) I am not getting the alerts.

                    With the Alert code in the strategy, are you getting the correct alerts.
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #11
                      Hi Joydeep. I get the same alerts with your code as were getting thrown by market analyzer. I sense it's hard to discern what's going on. Thanks for your patience. Since some of the alerts coming in are as expected (most of them are) I'll consider this resolved for now, and I'll review the output window values I've generated, as well as my logic.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by f.saeidi, Yesterday, 12:14 PM
                      9 responses
                      23 views
                      0 likes
                      Last Post f.saeidi  
                      Started by Tim-c, Today, 03:54 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post Tim-c
                      by Tim-c
                       
                      Started by FrancisMorro, Today, 03:24 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post FrancisMorro  
                      Started by Segwin, 05-07-2018, 02:15 PM
                      10 responses
                      1,772 views
                      0 likes
                      Last Post Leafcutter  
                      Started by Rapine Heihei, 04-23-2024, 07:51 PM
                      2 responses
                      31 views
                      0 likes
                      Last Post Max238
                      by Max238
                       
                      Working...
                      X