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