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

Alerts from Market Analyzer firing on prior days data...

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

    Alerts from Market Analyzer firing on prior days data...

    Hi. I'm in the home stretch (I think) of getting a custom indicator working in market analyzer. I had alerts firing, on trades that didn't seem to match the criteria of my code. After viewing the indicator on a chart, I see the indicator is plotting matching criteria points on bars on yesterday's data. I had assumed, however incorrectly, that the indicator would always be run on bar[0], each time a bar closed, giving me current conditions and alerts. Oddly enough, the prior days' alerts came through multiple times each, but erratically (some on every bar update, some spread out more).

    So... I've gotten some help in this area in the past, but can someone shed light on this/ let me know if there is a best practice to only generate alerts in MarketAnalyzer on the latest bar[0]? This has to be a common task. If it's of any interest, I'm using 5 min bars as the primary as well as daily bars.

    Code is below. Btw if anyone wants to use it for potential bounces on mov avg retracements be my guest.

    Code:
    protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                Overlay    = false;
                Add(PeriodType.Day,1);
            }
            
            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);
                            }
                        }
                    }
                }
            }

    #2
    Originally posted by CSharpTrader View Post
    Hi. I'm in the home stretch (I think) of getting a custom indicator working in market analyzer. I had alerts firing, on trades that didn't seem to match the criteria of my code. After viewing the indicator on a chart, I see the indicator is plotting matching criteria points on bars on yesterday's data. I had assumed, however incorrectly, that the indicator would always be run on bar[0], each time a bar closed, giving me current conditions and alerts. Oddly enough, the prior days' alerts came through multiple times each, but erratically (some on every bar update, some spread out more).

    So... I've gotten some help in this area in the past, but can someone shed light on this/ let me know if there is a best practice to only generate alerts in MarketAnalyzer on the latest bar[0]? This has to be a common task. If it's of any interest, I'm using 5 min bars as the primary as well as daily bars.

    Code is below. Btw if anyone wants to use it for potential bounces on mov avg retracements be my guest.

    Code:
    protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                Overlay    = false;
                Add(PeriodType.Day,1);
            }
     
            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);
                            }
                        }
                    }
                }
            }
    That depends on what you actually mean. If you want to ignore all signals prior to the currently running bar when you start, and only handle signals into the future thereafter, you can escape all bars that are not "real time" with:

    Code:
     
    if (Historical) return;
    at the start of OBU. Somehow, I am not sure that I have really understood what you want to do, so take that under advisement, please.

    Comment


      #3
      Thanks koganam. That looks like something that would do what i want.

      I want alert signals generated from market analyzer to be current, not from say, yesterdays data, which I *think* was my issue I posted earlier. So any logic that says High[0] is the last 5 min bar to close, and Highs[1][0] would always mean yesterdays' high.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by elirion, Today, 09:32 PM
      0 responses
      2 views
      0 likes
      Last Post elirion
      by elirion
       
      Started by cre8able, Today, 09:15 PM
      1 response
      5 views
      0 likes
      Last Post bltdavid  
      Started by cummish, Today, 08:43 PM
      0 responses
      12 views
      0 likes
      Last Post cummish
      by cummish
       
      Started by Option Whisperer, Today, 07:58 PM
      4 responses
      21 views
      0 likes
      Last Post Option Whisperer  
      Started by ETFVoyageur, 05-07-2024, 07:05 PM
      13 responses
      87 views
      0 likes
      Last Post ETFVoyageur  
      Working...
      X