Announcement

Collapse
No announcement yet.

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 sjsj2732, 03-23-2026, 04:31 AM
      0 responses
      69 views
      0 likes
      Last Post sjsj2732  
      Started by NullPointStrategies, 03-13-2026, 05:17 AM
      0 responses
      312 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      305 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      146 views
      1 like
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      105 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Working...
      X