/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // Use this method for calculating your indicator values. Assign a value to each // plot below by replacing 'Close[0]' with your own formula. if (CurrentBar < Lenght) { Trend.Set(true); UpTrend.Set(Close[0]); DownTrend.Set(Close[0]); return; } ; if (Close[0] > DownTrend[1]) { Trend.Set(true); } else if (Close[0] < UpTrend[1]) { Trend.Set(false); } else { Trend.Set(Trend[1]); } if (Trend[0] && !Trend[1]) { UpTrend.Set(Median[0] - ATR(Lenght)[0] * Multiplier); UpTrend.Set(1, DownTrend[1]); if (ShowArrows) { DrawArrowUp(CurrentBar.ToString(), true, 0, UpTrend[0] - TickSize, Color.Blue); } } else if (!Trend[0] && Trend[1]) { DownTrend.Set(Median[0] + ATR(Lenght)[0] * Multiplier); DownTrend.Set(1, UpTrend[1]); if (ShowArrows) { DrawArrowDown(CurrentBar.ToString(), true, 0, DownTrend[0] + TickSize, Color.Red); } } else if (Trend[0]) { UpTrend.Set((Median[0] - ATR(Lenght)[0] * Multiplier) > UpTrend[1] ? (Median[0] - ATR(Lenght)[0] * Multiplier) : UpTrend[1]); } else { DownTrend.Set((Median[0] + ATR(Lenght)[0] * Multiplier) < DownTrend[1] ? (Median[0] + ATR(Lenght)[0] * Multiplier) : DownTrend[1]); } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar < 2) { barCount.Set(-1); return; } // do book-keeping on new bars... if (CurrentBar != lastBarSeen) { lastBarSeen = CurrentBar; barCount.Set(barCount[1] + 1); volumeCount += Volume[1]; //Print("Bar: "+CurrentBar+" time: "+Time[0]+" tgt: "+tgtTime+ " sess: "+sessionTime); // determine if it's time for a new bar... bool barReset = atBarResetTime(); bool sessionStart = atSessionStart(); if (barReset || sessionStart) { // we need to start fresh... barCount.Set(0); volumeCount = 0; newBar.Set(true); if (sessionStart) { newSession.Set(true); } } else { // update stuff... newBar.Set(false); newSession.Set(false); } } //Print("CurrentBar: " + CurrentBar + " Bar Count: " + barCount[0] + " Vol count: " +volumeCount+" " +newBar[0]); }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // MACD Crossover: Fast Line cross above Slow Line if (CrossAbove(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1)) { // Paint the current price bar lime to draw our attention to it BarColor = Color.Lime; /* This crossover condition is considered bullish so we set the "bullIndication" BoolSeries object to true. * We also set the "bearIndication" object to false so it does not take on a null value. */ bullIndication.Set(true); bearIndication.Set(false); } // MACD Crossover: Fast Line cross below Slow Line else if (CrossBelow(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1)) { // Paint the current price bar magenta to draw our attention to it BarColor = Color.Magenta; /* This crossover condition is considered bearish so we set the "bearIndication" BoolSeries object to true. * We also set the "bullIndication" object to false so it does not take on a null value. */ bullIndication.Set(false); bearIndication.Set(true); } // MACD Crossover: No cross else { /* Since no crosses occured we are not receiving any bullish or bearish signals so we * set our BoolSeries objects both to false. */ bullIndication.Set(false); bearIndication.Set(false); } // We set our variable to the close value. exposedVariable = Close[0]; }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (med == null) { med = Z20091120SortedWindow(Median, windowLength); } if (CurrentBar < (windowLength + 1)) { Value.Set(Median[0]); dirup.Set(true); return; } double slope = calcSlope(lookback); if ((med[0] > med[1]) && (slope <= 0)) { Value.Set(Value[1]); } else if ((med[0] < med[1]) && (slope >= 0)) { Value.Set(Value[1]); } else { // either everything is flat, or the // med and slope agree... bool assumeUp = (slope > 0); if (slope == 0) { if (med[0] != med[1]) { assumeUp = (med[0] > med[1]); } else { assumeUp = dirup[1]; } } if (assumeUp) { Value.Set(Math.Max(Value[1], med[0])); } else { Value.Set(Math.Min(Value[1], med[0])); } /* if( (Value[1] == Value[2]) && * (med[1] != med[2]) ) { * Value.Set(Median[0]); * med.Set(Median[0]); * } */ } if (Value[0] > Value[1]) { dirup.Set(true); } else if (Value[0] < Value[1]) { dirup.Set(false); } else { dirup.Set(dirup[1]); } bool upbar = ((Close[0] > Open[0]) || (Close[0] == High[0])); bool dnbar = ((Close[0] < Open[0]) || (Close[0] == Low[0])); if (!dirup[0] && dirup[1] && upbar) { dirup.Set(true); Value.Set(Value[1]); } if (dirup[0] && !dirup[1] && dnbar) { dirup.Set(false); Value.Set(Value[1]); } if (!dirup[0] && dirup[1] && (Value[1] <= (High[0] + tolerance * TickSize))) { dirup.Set(true); Value.Set(Value[1]); } if (dirup[0] && !dirup[1] && (Value[1] >= (Low[0] - tolerance * TickSize))) { dirup.Set(false); Value.Set(Value[1]); } if ((Value[0] > Value[1]) && dnbar) { Value.Set(Value[1]); } if ((Value[0] < Value[1]) && upbar) { Value.Set(Value[1]); } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (colorizer == null) { colorizer = Z20091221Colorizer3(maval, colorMethod, colorParam); med = Z20091120SortedWindow(Median, windowLength); } if (CurrentBar < (windowLength + 1)) { maval.Set(Median[0]); dirup.Set(true); return; } double slope = calcSlope(lookback); if ((med[0] > med[1]) && (slope <= 0)) { maval.Set(maval[1]); } else if ((med[0] < med[1]) && (slope >= 0)) { maval.Set(maval[1]); } else { // either everything is flat, or the // med and slope agree... bool assumeUp = (slope > 0); if (slope == 0) { if (med[0] != med[1]) { assumeUp = (med[0] > med[1]); } else { assumeUp = dirup[1]; } } if (assumeUp) { maval.Set(Math.Max(maval[1], med[0])); } else { maval.Set(Math.Min(maval[1], med[0])); } /* if( (maval[1] == maval[2]) && * (med[1] != med[2]) ) { * maval.Set(Median[0]); * med.Set(Median[0]); * } */ } if (maval[0] > maval[1]) { dirup.Set(true); } else if (maval[0] < maval[1]) { dirup.Set(false); } else { dirup.Set(dirup[1]); } bool upbar = ((Close[0] > Open[0]) || (Close[0] == High[0])); bool dnbar = ((Close[0] < Open[0]) || (Close[0] == Low[0])); if (!dirup[0] && dirup[1] && upbar) { dirup.Set(true); maval.Set(maval[1]); } if (dirup[0] && !dirup[1] && dnbar) { dirup.Set(false); maval.Set(maval[1]); } if (!dirup[0] && dirup[1] && (maval[1] <= (High[0] + tolerance * TickSize))) { dirup.Set(true); maval.Set(maval[1]); } if (dirup[0] && !dirup[1] && (maval[1] >= (Low[0] - tolerance * TickSize))) { dirup.Set(false); maval.Set(maval[1]); } if ((maval[0] > maval[1]) && dnbar) { maval.Set(maval[1]); } if ((maval[0] < maval[1]) && upbar) { maval.Set(maval[1]); } colorizer.drawColor(this, 0, 1, 2); }
/// <summary> /// Called on each bar update event (incoming tick) protected override void OnBarUpdate() { if (CurrentBar == 0) { displacement = Math.Max(Displacement, -CurrentBar); priorUpTrend = true; currentUpTrend = true; upTrend.Set(true); StopDot.Set(Close[0]); StopLine.Set(Close[0]); PlotColors[0][-displacement] = Color.Transparent; PlotColors[1][-displacement] = Color.Transparent; return; } if (FirstTickOfBar) { displacement = Math.Max(Displacement, -CurrentBar); movingBase = baseline[1]; offset = Math.Max(TickSize, offsetSeries[1]); trailingAmount = multiplier * offset; margin = volatility[1]; if (currentUpTrend) { currentStopShort = movingBase + trailingAmount; if (priorUpTrend) { currentStopLong = Math.Max(currentStopLong, movingBase - trailingAmount); } else { currentStopLong = movingBase - trailingAmount; } StopDot.Set(currentStopLong); ReverseDot.Set(currentStopShort); PlotColors[0][-displacement] = upColor; if (showStopLine) { StopLine.Set(currentStopLong); if (gap && !priorUpTrend) { PlotColors[1][-displacement] = Color.Transparent; } else { PlotColors[1][-displacement] = upColor; } } else { StopLine.Reset(); } } else { currentStopLong = movingBase - trailingAmount; if (!priorUpTrend) { currentStopShort = Math.Min(currentStopShort, movingBase + trailingAmount); } else { currentStopShort = movingBase + trailingAmount; } StopDot.Set(currentStopShort); ReverseDot.Set(currentStopLong); PlotColors[0][-displacement] = downColor; if (showStopLine) { StopLine.Set(currentStopShort); if (gap && priorUpTrend) { PlotColors[1][-displacement] = Color.Transparent; } else { PlotColors[1][-displacement] = downColor; } } else { StopLine.Reset(); } } if (showPaintBars) { if (currentUpTrend) { trendColor = upColor; } else { trendColor = downColor; } CandleOutlineColorSeries[-displacement] = trendColor; BarColorSeries[-displacement] = trendColor; } if (showArrows) { if (currentUpTrend && !priorUpTrend) { DrawArrowUp("arrow" + CurrentBar, true, -displacement, currentStopLong - 0.5 * margin, upColor); } else if (!currentUpTrend && priorUpTrend) { DrawArrowDown("arrow" + CurrentBar, true, -displacement, currentStopShort + 0.5 * margin, downColor); } } priorUpTrend = currentUpTrend; stoppedOut = false; } if (reverseIntraBar) // only one trend change per bar is permitted { if (!stoppedOut) { if (priorUpTrend && Low[0] < currentStopLong) { currentUpTrend = false; stoppedOut = true; } else if (!priorUpTrend && High[0] > currentStopShort) { currentUpTrend = true; stoppedOut = true; } } } else { if (priorUpTrend && Close[0] < currentStopLong) { currentUpTrend = false; } else if (!priorUpTrend && Close[0] > currentStopShort) { currentUpTrend = true; } else { currentUpTrend = priorUpTrend; } } // this information can be accessed by a strategy if (CalculateOnBarClose) { upTrend.Set(currentUpTrend); } else if (FirstTickOfBar && !reverseIntraBar) { upTrend.Set(priorUpTrend); } else if (reverseIntraBar) { upTrend.Set(currentUpTrend); } if (showPaintBars && candles) { if (Open[0] < Close[0]) { BarColorSeries[-displacement] = Color.FromArgb(alpha, trendColor); } } if (soundAlert && !Historical && IsConnected() && (CalculateOnBarClose || reverseIntraBar)) { if (currentUpTrend && !priorUpTrend) { try { Alert("NewUpTrend", NinjaTrader.Cbi.Priority.Medium, "NewUpTrend", confirmedUpTrend, rearmTime, Color.Black, upColor); } catch {} } else if (!currentUpTrend && priorUpTrend) { try { Alert("NewDownTrend", NinjaTrader.Cbi.Priority.Medium, "NewDownTrend", confirmedDownTrend, rearmTime, Color.Black, downColor); } catch {} } } if (soundAlert && !Historical && IsConnected() && !CalculateOnBarClose && !reverseIntraBar) { if (currentUpTrend && !priorUpTrend) { try { Alert("PotentialUpTrend", NinjaTrader.Cbi.Priority.Medium, "PotentialUpTrend", potentialUpTrend, rearmTime, Color.Black, upColor); } catch {} } else if (!currentUpTrend && priorUpTrend) { try { Alert("PotentialDownTrend", NinjaTrader.Cbi.Priority.Medium, "PotentialDownTrend", potentialDownTrend, rearmTime, Color.Black, downColor); } catch {} } } }
/// <summary> /// Called on each bar update event (incoming tick) protected override void OnBarUpdate() { if (CurrentBar == 0) { upTrend.Set(true); StopDot.Set(Close[0]); StopLine.Set(Close[0]); PlotColors[0][0] = neutralColor; PlotColors[1][0] = neutralColor; return; } if (FirstTickOfBar) { priorUpTrend = upTrend[1]; priorStop = StopLine[1]; priorColor = PlotColors[0][1]; medianline = MM[1]; offset = MAE[1]; } if (Close[0] > priorStop) { upTrend.Set(true); newStop = medianline - Multiplier * offset; currentUpTrend = true; if (!priorUpTrend) // trend change up { StopDot.Set(newStop); StopLine.Set(newStop); } else { StopDot.Set(Math.Max(newStop, priorStop)); StopLine.Set(Math.Max(newStop, priorStop)); } } else if (Close[0] < priorStop) { upTrend.Set(false); newStop = medianline + Multiplier * offset; currentUpTrend = false; if (priorUpTrend) // trend change down { StopDot.Set(newStop); StopLine.Set(newStop); } else { StopDot.Set(Math.Min(newStop, priorStop)); StopLine.Set(Math.Min(newStop, priorStop)); } } else { upTrend.Set(priorUpTrend); currentUpTrend = priorUpTrend; StopDot.Set(priorStop); StopLine.Set(priorStop); } if (PaintBars) { if (currentUpTrend) { CandleOutlineColor = upColor; BarColor = upColor; } else { CandleOutlineColor = downColor; BarColor = downColor; } if (Open[0] < Close[0] && candles) { BarColor = Color.Transparent; } } if (ShowArrows) { if (currentUpTrend && !priorUpTrend) { DrawArrowUp("arrow" + CurrentBar, true, 0, newStop - 0.5 * offset, upColor); } else if (!currentUpTrend && priorUpTrend) { DrawArrowDown("arrow" + CurrentBar, true, 0, newStop + 0.5 * offset, downColor); } else { RemoveDrawObject("arrow" + CurrentBar); } } if (ShowStopDots) { if (currentUpTrend) { PlotColors[0][0] = upColor; } else { PlotColors[0][0] = downColor; } } if (ShowStopLine) { if (currentUpTrend && !priorUpTrend) { if (gap) { PlotColors[1][0] = neutralColor; } else { PlotColors[1][0] = upColor; } } else if (currentUpTrend) { PlotColors[1][0] = upColor; } else if (!currentUpTrend && priorUpTrend) { if (gap) { PlotColors[1][0] = neutralColor; } else { PlotColors[1][0] = downColor; } } else { PlotColors[1][0] = downColor; } } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // Bollinger calculations //==================================== double smaValue = SMA(Period)[0]; double stdDevValue = StdDev(Period)[0]; double bUpper = smaValue + NumStdDev * stdDevValue; double bMiddle = smaValue; double bLower = smaValue - NumStdDev * stdDevValue; double bWidth = bUpper - bLower; // KeltnerChannel calculations //==================================== diff.Set(High[0] - Low[0]); double middle = SMA(Typical, Period)[0]; double offset = SMA(diff, Period)[0] * offsetMultiplier; double upper = middle + offset; double lower = middle - offset; double kWidth = upper - lower; // Set momentum double momentum = CurrentBar == 0 ? 0 : Input[0] - Input[Math.Min(CurrentBar, moPeriod)]; mo.Set(momentum); //==================================== double squeezeRatio = bWidth / kWidth; //SqueezeAlert.Set(bWidth/kWidth); // Smoothing out momentum double smoothedMo = SMA(mo, smoothPeriod)[0]; Histogram.Set(smoothedMo); //Value.Set(SMA(mo, Period)[0]); // alternative syntax if (CurrentBar > 1) { if (Histogram[0] > 0.0) { //if (Stochastics(periodD, periodK, smooth).K[0] < 50) if (Histogram[0] > Histogram[1]) { PlotColors[0][0] = PosUpColor; } else { PlotColors[0][0] = PosDownColor; } } else { //if (Rising(Stochastics(periodD, periodK, smooth).K)) //if (Stochastics(periodD, periodK, smooth).K[0] > 50) if (Histogram[0] < Histogram[1]) { PlotColors[0][0] = NegDownColor; } else { PlotColors[0][0] = NegUpColor; } } VolComp.Set(0); inSqueeze.Set((squeezeRatio < alertLine) ? true : false); if (inSqueeze[0]) { // in a squeeze PlotColors[1][0] = normalColor; } else { PlotColors[1][0] = alertColor; } } }
protected override void OnBarUpdate() { // Stochastic Momentum = SM {distance of close - midpoint} //sms[0]=Close[0] - 0.5 * ((MAX(High, _Range)[0] + MIN(Low, _Range)[0])); // High low diffs //hls.Set(MAX(High, _Range)[0] - MIN(Low, _Range)[0]); if (FirstTickOfBar) { firstTickHi = MaxHI[0]; firstTickLo = MinLO[0]; } HH = Math.Max(firstTickHi, High[0]); LL = Math.Min(firstTickLo, Low [0]); //hls[0]=MaxHi[0] - MinLo[0]; sms[0] = Close[0] - 0.5 * (HH + LL); hls[0] = HH - LL; // Stochastic Momentum Index = SMI //emaEMAhls=EMA( EMA(hls, EMAPeriod1),EMAPeriod2 ); //double denom = 0.5*EMA( EMA(hls, EMAPeriod1),EMAPeriod2 )[0]; denominator = 0.5 * emaEMAhls[0]; // aug 19 2014 //emaEMAsms=(EMA( EMA(sms,EMAPeriod1), EMAPeriod2 )); //smis.Set( 100*(EMA( EMA(sms,EMAPeriod1), EMAPeriod2 ))[0] / (denom ==0 ? 1 : denom )); smis[0] = 100 * emaEMAsms[0] / (denominator == 0 ? 1 : denominator); // aug 19 2014 // Set the line value for the SMIEMA by taking the EMA of the SMI //emaSMI=EMA(smis, SMIEMAPeriod); //SMIEMA.Set(EMA(smis, SMIEMAPeriod)[0]); SMIEMA[0] = emaSMI[0]; // aug 19 2014 double priceValue = DYNPrice[0]; PriceLine[0] = priceValue; SignalLine[0] = DYNSignal[0]; #region Draw devices and maybe play sounds upDeviceSeries[0] = false; downDeviceSeries[0] = false; switch (PickDeviceSelection) { case DeviceSelection.SMI_only: { if (CrossBelow(smis, SMIEMA, 1)) { drawDevice(false, "SMIOnlyUp"); downDeviceSeries.Set(0, true); if (PlaySoundFile) { PlaySound(SoundFileName); } } else if (CrossAbove(smis, SMIEMA, 1)) { drawDevice(true, "SMIOnlyDown"); upDeviceSeries.Set(0, true); if (PlaySoundFile) { PlaySound(SoundFileName); } } break; } case DeviceSelection.TDI_only: { if (CrossAbove(PriceLine, SignalLine, 1)) // have used the Signal instead of the Average line) { drawDevice(true, "TDIOnlyUp"); upDeviceSeries.Set(0, true); if (PlaySoundFile) { PlaySound(SoundFileName); } } else if (CrossBelow(PriceLine, SignalLine, 1)) { drawDevice(false, "TDIOnlyDown"); downDeviceSeries.Set(0, true); if (PlaySoundFile) { PlaySound(SoundFileName); } } break; } case DeviceSelection.Both: { if (CrossBelow(smis, SMIEMA, 1) && CrossBelow(PriceLine, SignalLine, 1)) { drawDevice(false, "BothDown"); downDeviceSeries.Set(0, true); if (PlaySoundFile) { PlaySound(SoundFileName); } } else { RemoveDrawObject("BothDown" + CurrentBar); } if (CrossAbove(smis, SMIEMA, 1) && CrossAbove(PriceLine, SignalLine, 1)) { drawDevice(true, "BothUp"); upDeviceSeries.Set(0, true); if (PlaySoundFile) { PlaySound(SoundFileName); } } else { RemoveDrawObject("BothUp" + CurrentBar); } break; } } #endregion (Draw devices...) }
protected override void OnBarUpdate() { if (ChartControl == null || Bars == null) { return; } if (Displacement + (CalculateOnBarClose ? 1 : 0) > 0 && CurrentBar > 0 && BarColorSeries[1] != Color.Transparent) { InitColorSeries(); } BarColorSeries.Set(Math.Max(0, CurrentBar + Math.Max(0, Displacement) + (CalculateOnBarClose ? 1 : 0)), Color.Transparent); CandleOutlineColorSeries.Set(Math.Max(0, CurrentBar + Math.Max(0, Displacement) + (CalculateOnBarClose ? 1 : 0)), Color.Transparent); Condition4.Reset(); Condition5.Reset(); Condition2.Reset(); Condition67.Reset(); if (CurrentBar == 0) { hao.Set(Open[0]); hah.Set(High[0]); hal.Set(Low[0]); hac.Set(Close[0]); return; } hac.Set((Open[0] + High[0] + Low[0] + Close[0]) * 0.25); // Calculate the close hao.Set((hao[1] + hac[1]) * 0.5); // Calculate the open hah.Set(Math.Max(High[0], hao[0])); // Calculate the high hal.Set(Math.Min(Low[0], hao[0])); // Calculate the low if (CurrentBar < 3) { return; } bool condition1 = (ZLEMA(7)[0] < hao[0] || ZLEMA(7)[0] < Median[0]) && ZLEMA(7)[0] < ZLEMA(21)[1] && hac[0] < ZLEMA(21)[2] && (MACD(12, 26, 9).Diff[0] < 0 || (hac[0] < ZLEMA(21)[2] && hao[0] < ZLEMA(21)[2]) || Close[0] < SMA(21)[0] || ZLEMA(7)[0] < ZLEMA(21)[2]); bool condition2 = (ZLEMA(7)[0] > hao[0] || ZLEMA(7)[0] > Median[0]) && ZLEMA(7)[0] > ZLEMA(21)[1] && hac[0] > ZLEMA(21)[2] && (MACD(12, 26, 9).Diff[0] > 0 || (hac[0] > ZLEMA(21)[2] && hao[0] > ZLEMA(21)[2]) || Close[0] > SMA(21)[0] || ZLEMA(7)[0] > ZLEMA(21)[2]); bool condition3 = (Low[0] + ((High[0] - Low[0]) * 0.1)) < SMA(21)[0] && (High[0] - ((High[0] - Low[0]) * 0.1)) < SMA(21)[0] && ZLEMA(7)[0] < ZLEMA(7)[1] && ZLEMA(11)[0] < hao[0]; bool condition4 = condition1 && condition3; bool condition5 = condition1 || condition3; bool condition6 = ZLEMA(7)[0] < ZLEMA(7)[1] && ZLEMA(11)[0] < ZLEMA(11)[1] && ZLEMA(11)[0] < SMA(21)[0] && hac[0] < hao[0] && Close[0] < Median[0]; bool condition7 = hac[0] < SMA(21)[0] && ZLEMA(7)[0] < ZLEMA(7)[1] && High[0] < SMA(78)[0] && SMA(21)[0] < SMA(78)[0] && SMA(78)[0] < SMA(78)[3]; c4.Set(condition4); c5.Set(condition5); c2.Set(condition2); c67.Set(condition6 || condition7); if (condition6 || condition7) { if (st67 == SignalType.PLOT) { Condition67.Set(hah[0] + 3 * TickSize); } else if (st67 == SignalType.BACKGROUNDCOLOR) { BackColor = Plots[3].Pen.Color; } } if (condition2) { if (st2 == SignalType.PLOT) { Condition2.Set(hal[0] - TickSize); } else if (st2 == SignalType.BACKGROUNDCOLOR) { BackColor = Plots[2].Pen.Color; } } if (condition5) { if (st5 == SignalType.PLOT) { Condition5.Set(hah[0] + 2 * TickSize); } else if (st5 == SignalType.BACKGROUNDCOLOR) { BackColor = Plots[1].Pen.Color; } } if (condition4) { if (st4 == SignalType.PLOT) { Condition4.Set(hah[0] + TickSize); } else if (st4 == SignalType.BACKGROUNDCOLOR) { BackColor = Plots[0].Pen.Color; } } if (FirstTickOfBar && c4[1] && !c4[2] && playAlert) { PlaySound("Aler4.wav"); } }
protected override void OnBarUpdate() { if (CurrentBar < 1) { if (_smooth > 1 && _avg == null) switch (_maType) { case MovingAverageType.SMA: _avg = SMA(Input, _smooth); break; case MovingAverageType.SMMA: _avg = SMMA(Input, _smooth); break; case MovingAverageType.TMA: _avg = TMA(Input, _smooth); break; case MovingAverageType.WMA: _avg = WMA(Input, _smooth); break; case MovingAverageType.VWMA: _avg = VWMA(Input, _smooth); break; case MovingAverageType.TEMA: _avg = TEMA(Input, _smooth); break; case MovingAverageType.HMA: _avg = HMA(Input, _smooth); break; case MovingAverageType.VMA: _avg = VMA(Input, _smooth, _smooth); break; case MovingAverageType.JMA: _avg = JurikJMA(Input, 0, _smooth); break; default: _avg = EMA(Input, _smooth); break; } else _avg = Input; _trend.Set(true); UpTrend.Set(Input[0]); DownTrend.Set(Input[0]); return; } switch (_smode) { case SuperTrendMode.ATR: _offset = ATR(_length)[0] * Multiplier; break; case SuperTrendMode.Adaptive: _offset = ATR(_length)[0] * HomodyneDiscriminator(Input)[0] / 10; break; default: _offset = Dtt(_length, Multiplier); break; } if (FirstTickOfBar) _prevColor = _tempColor; _trend.Set(Close[0] > DownTrend[1] ? true : Close[0] < UpTrend[1] ? false : _trend[1]); if (_trend[0] && !_trend[1]) { _th = High[0]; UpTrend.Set(Math.Max(_avg[0] - _offset, _tl)); if (Plots[0].PlotStyle == PlotStyle.Line) UpTrend.Set(1, DownTrend[1]); _tempColor = _barColorUp; if (ShowArrows) DrawArrowUp(CurrentBar.ToString(), true, 0, UpTrend[0] - TickSize, _barColorUp); if(PlayAlert && _thisbar != CurrentBar) { _thisbar = CurrentBar; PlaySound(LongAlert); } } else if (!_trend[0] && _trend[1]) { _tl = Low[0]; DownTrend.Set(Math.Min(_avg[0] + _offset, _th)); if (Plots[1].PlotStyle == PlotStyle.Line) DownTrend.Set(1, UpTrend[1]); _tempColor = _barColorDown; if (ShowArrows) DrawArrowDown(CurrentBar.ToString(), true, 0, DownTrend[0] + TickSize, _barColorDown); if (PlayAlert && _thisbar != CurrentBar) { _thisbar = CurrentBar; PlaySound(ShortAlert); } } else { if (_trend[0]) { UpTrend.Set((_avg[0] - _offset) > UpTrend[1] ? (_avg[0] - _offset) : UpTrend[1]); _th = Math.Max(_th, High[0]); } else { DownTrend.Set((_avg[0] + _offset) < DownTrend[1] ? (_avg[0] + _offset) : DownTrend[1]); _tl = Math.Min(_tl, Low[0]); } RemoveDrawObject(CurrentBar.ToString()); _tempColor = _prevColor; } if (!_colorBars) return; CandleOutlineColor = _tempColor; BarColor = Open[0] < Close[0] && ChartControl.ChartStyleType == ChartStyleType.CandleStick ? Color.Transparent : _tempColor; }
protected override void OnBarUpdate() { if (CurrentBar == 0) { upTrend.Set(true); StopDot.Set(Close[0]); StopLine.Set(Close[0]); PlotColors[0][0] = neutralColor; PlotColors[1][0] = neutralColor; return; } if (FirstTickOfBar) { priorUpTrend = upTrend[1]; priorStop = StopLine[1]; offset = mae[1]; } if (Close[0] > priorStop) { upTrend.Set(true); newStop = mm[0] - (Multiplier * offset); currentUpTrend = true; if (!priorUpTrend) { StopDot.Set(newStop); StopLine.Set(newStop); } else { StopDot.Set(Math.Max(newStop, priorStop)); StopLine.Set(Math.Max(newStop, priorStop)); } } else if (Close[0] < priorStop) { upTrend.Set(false); newStop = mm[0] + (Multiplier * offset); currentUpTrend = false; if (priorUpTrend) { StopDot.Set(newStop); StopLine.Set(newStop); } else { StopDot.Set(Math.Min(newStop, priorStop)); StopLine.Set(Math.Min(newStop, priorStop)); } } else { currentUpTrend = priorUpTrend; upTrend.Set(priorUpTrend); StopDot.Set(priorStop); StopLine.Set(priorStop); } if (PaintBars) { if (currentUpTrend) { CandleOutlineColor = upColor; BarColor = upColor; } else { CandleOutlineColor = downColor; BarColor = downColor; } } if (colorbackground) { BackColor = Color.FromArgb(opacity, currentUpTrend ? backgroundcolorUp : backgroundcolorDn); } if (colorAllBackgrounds) { BackColorAll = Color.FromArgb(opacity, currentUpTrend ? backgroundcolorUp : backgroundcolorDn); } if (ShowArrows) { if (currentUpTrend && !priorUpTrend) { DrawArrowUp("arrow" + CurrentBar, true, 0, newStop - (0.5 * offset), upColor); PlaySound("Alert4.wav"); } else if (!currentUpTrend && priorUpTrend) { DrawArrowDown("arrow" + CurrentBar, true, 0, newStop + (0.5 * offset), downColor); PlaySound("Alert4.wav"); } else { RemoveDrawObject("arrow" + CurrentBar); } } if (ShowStopLine) { PlotColors[1][0] = currentUpTrend && !priorUpTrend ? (gap ? neutralColor : upColor) : (currentUpTrend ? upColor : (!currentUpTrend && priorUpTrend ? (gap ? neutralColor : downColor) : downColor)); } }
protected override void OnBarUpdate() { if (CurrentBar == 0) { trend.Set(true); UpTrend.Set(Input[0]); DownTrend.Set(Input[0]); return; } switch (smode) { case SuperTrendMode.ATR: offset = ATR(length)[0] * Multiplier; break; case SuperTrendMode.Adaptive: offset = ATR(length)[0] * HomodyneDiscriminator(Input)[0] / 10; break; default: offset = Dtt(length, Multiplier); break; } if (FirstTickOfBar) { prevColor = tempColor; } trend.Set(Close[0] > DownTrend[1] || !(Close[0] < UpTrend[1]) && trend[1]); if (trend[0] && !trend[1]) { th = High[0]; UpTrend.Set(Math.Max(avg[0] - offset, tl)); if (Plots[0].PlotStyle == PlotStyle.Line) { UpTrend.Set(1, DownTrend[1]); } tempColor = barColorUp; if (ShowArrows) { DrawArrowUp(CurrentBar.ToString(CultureInfo.InvariantCulture), true, 0, UpTrend[0] - TickSize, barColorUp); } if (thisbar != CurrentBar) { thisbar = CurrentBar; if (PlayAlert) { PlaySound(LongAlert); } if (SendEmail && !string.IsNullOrEmpty(mailFrom) && !string.IsNullOrEmpty(mailTo)) { SendMail(mailFrom, mailTo, "SuperTrend Long Signal", string.Format("{0}: {1} {2} {3} chart", Time[0], Instrument.FullName, Bars.Period.Value, Bars.Period.Id)); } } } else if (!trend[0] && trend[1]) { tl = Low[0]; DownTrend.Set(Math.Min(avg[0] + offset, th)); if (Plots[1].PlotStyle == PlotStyle.Line) { DownTrend.Set(1, UpTrend[1]); } tempColor = barColorDown; if (ShowArrows) { DrawArrowDown(CurrentBar.ToString(CultureInfo.InvariantCulture), true, 0, DownTrend[0] + TickSize, barColorDown); } if (thisbar != CurrentBar) { thisbar = CurrentBar; if (PlayAlert) { PlaySound(ShortAlert); } if (SendEmail && !string.IsNullOrEmpty(mailFrom) && !string.IsNullOrEmpty(mailTo)) { SendMail(mailFrom, mailTo, "SuperTrend Short Signal", string.Format("{0}: {1} {2} {3} chart", Time[0], Instrument.FullName, Bars.Period.Value, Bars.Period.Id)); } } } else { if (trend[0]) { UpTrend.Set((avg[0] - offset) > UpTrend[1] ? (avg[0] - offset) : UpTrend[1]); th = Math.Max(th, High[0]); } else { DownTrend.Set((avg[0] + offset) < DownTrend[1] ? (avg[0] + offset) : DownTrend[1]); tl = Math.Min(tl, Low[0]); } RemoveDrawObject(CurrentBar.ToString(CultureInfo.InvariantCulture)); tempColor = prevColor; } if (!colorBars) { return; } CandleOutlineColor = tempColor; BarColor = Open[0] < Close[0] && ChartControl.ChartStyleType == ChartStyleType.CandleStick ? Color.Transparent : tempColor; }