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.
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); } } } } }
Comment