Code presented in the article “The Step Candle Pattern” by Sylvain Vervoort, in the July 2013 issue of Technical Analysis of Stocks & Commodities magazine.
NINJASCRIPT FOR FOUR CONDITIONS OF UPSTEP PATTERN
private void StepUp() { // Black body before last low bar and a step up white body at last low bar if (Close[CurrentBar-llb+1] < Open[CurrentBar-llb+1] && Close[CurrentBar-llb] > Open [CurrentBar-llb] && Open [CurrentBar-llb] >= Close[CurrentBar-llb+1] && Open [CurrentBar-llb] <= Open [CurrentBar-llb+1] && Close[CurrentBar-llb] > Open [CurrentBar-llb+1] || // Black body at the last low bar and step up white body after last low bar Close[CurrentBar-llb] < Open [CurrentBar-llb] && Close[CurrentBar-llb-1] > Open [CurrentBar-llb-1] && Open [CurrentBar-llb-1] >= Close[CurrentBar-llb] && Open [CurrentBar-llb-1] <= Open [CurrentBar-llb] && Close[CurrentBar-llb-1] > Open [CurrentBar-llb] || // White body before last low bar and step up white body at last low bar Close[CurrentBar-llb+1] > Open [CurrentBar-llb+1] && Close[CurrentBar-llb] > Open [CurrentBar-llb] && Open [CurrentBar-llb] >= Open [CurrentBar-llb+1] && Open [CurrentBar-llb] <= Close[CurrentBar-llb+1] && Close[CurrentBar-llb] > Close[CurrentBar-llb+1] || // White body at last low bar and a step up white body after last low bar Close[CurrentBar-llb] > Open [CurrentBar-llb] && Close[CurrentBar-llb-1] > Open [CurrentBar-llb-1] && Open [CurrentBar-llb-1] >= Open [CurrentBar-llb] && Open [CurrentBar-llb-1] <= Close[CurrentBar-llb] && Close[CurrentBar-llb-1] > Close[CurrentBar-llb]) UpStep = 1; else UpStep = 0; }
NINJA SCRIPT FOR FOUR CONDITIONS FOR DOWNSTEP PATTERN
private void StepDown() { // Black body before last high bar and a step down black body at last high bar if (Close[CurrentBar-lhb+1] < Open[CurrentBar-lhb+1] && Close[CurrentBar-lhb] < Open [CurrentBar-lhb] && Open [CurrentBar-lhb] <= Open [CurrentBar-lhb+1] && Open [CurrentBar-lhb] >= Close[CurrentBar-lhb+1] && Close[CurrentBar-lhb] < Close[CurrentBar-lhb+1] || // Black body at the last high bar and step down black body after last high bar Close[CurrentBar-lhb] < Open [CurrentBar-lhb] && Close[CurrentBar-lhb-1] < Open [CurrentBar-lhb-1] && Open [CurrentBar-lhb-1] <= Open [CurrentBar-lhb] && Open [CurrentBar-lhb-1] >= Close[CurrentBar-lhb] && Close[CurrentBar-lhb-1] < Close[CurrentBar-lhb] || // White body before last high bar and a step down black body at last high bar Close[CurrentBar-lhb+1] > Open[CurrentBar-lhb+1] && Close[CurrentBar-lhb] < Open [CurrentBar-lhb] && Open [CurrentBar-lhb] <= Close[CurrentBar-lhb+1] && Open [CurrentBar-lhb] >= Open [CurrentBar-lhb+1] && Close[CurrentBar-lhb] < Open [CurrentBar-lhb+1] || // White body at last high bar and a step down black body after last high bar Close[CurrentBar-lhb] > Open [CurrentBar-lhb] && Close[CurrentBar-lhb-1] < Open [CurrentBar-lhb-1] && Open [CurrentBar-lhb-1] <= Close[CurrentBar-lhb] && Open [CurrentBar-lhb-1] >= Open [CurrentBar-lhb] && Close[CurrentBar-lhb-1] < Open [CurrentBar-lhb]) DownStep = 1; else DownStep = 0; }
NINJASCRIPT FOR BODYGAPUP
private void BodyGapUp() { // Black body at the last low bar followed by a bar with a gap up or equal value if(Close[CurrentBar-llb]<= Open[CurrentBar-llb] && Open[CurrentBar-llb-1] >= Open[CurrentBar-llb] && Close[CurrentBar-llb-1] >= Open[CurrentBar-llb] || // White body at last low bar followed by a bar with a gap up or equal value Close[CurrentBar-llb] >= Open [CurrentBar-llb] && Open [CurrentBar-llb-1] >= Close[CurrentBar-llb] && Close[CurrentBar-llb-1] >= Close[CurrentBar-llb]) UpStep = 1; else UpStep = 0; }
NINJASCRIPT FOR BODYGAPDOWN
private void BodyGapDown() { // White body at last high bar followed by a bar with a gap down or equal value if (Close[CurrentBar-lhb]>=Open[CurrentBar-lhb] && Open[CurrentBar-lhb-1]<= Open[CurrentBar-lhb] && Close[CurrentBar-lhb-1]<=Open[CurrentBar-lhb] || // Black body at last high bar followed by a bar with a gap down or equal value Close[CurrentBar-lhb]<=Open[CurrentBar-lhb] && Open[CurrentBar-lhb-1]<= Close[CurrentBar-lhb] && Close[CurrentBar-lhb-1] <= Close[CurrentBar-lhb]) DownStep = 1; else DownStep = 0; }
NINJASCRIPT FOR BULLISH ENGULFING PATTERN
private void BullishEngulfing() { // Black small body or doji before last low bar and larger white at last low bar if (Close[CurrentBar-llb+1] <= Open[CurrentBar-llb+1] && Close[CurrentBar-llb] > Open[CurrentBar-llb] && Open[CurrentBar-llb]<=Close[CurrentBar-llb+1] && Close[CurrentBar-llb]>= Open[CurrentBar-llb+1] || // Black small body or doji at the last low bar and larger white after last low bar Close[CurrentBar-llb]<= Open[CurrentBar-llb] && Close[CurrentBar-llb-1]> Open[CurrentBar-llb-1] && Open[CurrentBar-llb-1]<= Close[CurrentBar-llb] && Close[CurrentBar-llb-1]>= Open[CurrentBar-llb] || // White small body or doji before last low bar and larger white at last low bar Close[CurrentBar-llb+1]>= Open[CurrentBar-llb+1] && Close[CurrentBar-llb] > Open[CurrentBar-llb] && Open[CurrentBar-llb] <= Open[CurrentBar-llb+1] && Close[CurrentBar-llb]>=Close[CurrentBar-llb+1] || // White small body or doji at last low bar and larger white after last low bar Close[CurrentBar-llb] >= Open[CurrentBar-llb] && Close[CurrentBar-llb-1]>Open[CurrentBar-llb-1] && Open[CurrentBar-llb-1]<=Open[CurrentBar-llb] && Close[CurrentBar-llb-1]>=Close[CurrentBar-llb]) BullEng = 1; else BullEng = 0; }
NINJASCRIPT FOR UPTREND TURNS TO DOWNTREND
if (CandlePattern != 0) // Look for candlestick patterns { if (CandlePattern == 1 || CandlePattern == 9) // Step Down candle pattern? { StepDown(); if (DownStep == 0) BodyGapDown(); //not a normal Step Down, try a Body Gap Down if (DownStep == 1) { // Writes "D" 10 Tick sizes above the highest high of the down turning point DrawText(downlineid+1.ToString(),true,"D",Curre ntBar-lhb,hh+TickSize, positioning,Color.Red,candlefont,StringAlignment.Center, Color.Empty,Color.Empty,0); //Show number of found patterns in top left corner of the chart PatternCnt++; DrawTextFixed("PatternCnt",PatternCnt.ToString(),TextPosition.TopLeft); return; //StepDown pattern found, not looking for any other pattern } } if (CandlePattern == 2 || CandlePattern == 9) BearishEngulfing(); if (BearEng == 1) { // Writes "E" 10 Ticks above the highest high of the down turning point DrawText(downlineid+2.ToString(),true,"E",CurrentBar-lhb,hh+TickSize, positioning,Color.Red,candlefont,StringAlignment.Center, Color.Empty,Color.Empty,0); PatternCnt++; DrawTextFixed("PatternCnt",PatternCnt.ToString(),TextPosition.TopLeft); return; //Bearish Engulfing pattern found, not looking for any other pattern } if (CandlePattern == 3 || CandlePattern == 9) BearishHarami(); if (BearHaram == 1) { // Writes "H" 10 Ticks above the highest high of the down turning point DrawText(downlineid+3.ToString(),true,"H",CurrentBar-lhb,hh+TickSize, positioning,Color.Red,candlefont,StringAlignment.Center, Color.Empty,Color.Empty,0); PatternCnt++; DrawTextFixed("PatternCnt",PatternCnt.ToString(),TextPosition.TopLeft); return; //Bearish Harami pattern, not looking for any other pattern } }
NINJASCRIPT FOR CANDLE PATTERN
// // SVEHLZZCandlePattern (NT7)is Copyright (C) 2012, Sylvain Vervoort <stocata.org>. // stocata.org reserves the right to modify/overwrite this NinjaScript with each release. // Release V1.0 October 2012 #region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Gui.Chart; #endregion // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { /// <summary> /// High-Low percent change ZigZag indicator ATR adjusted with Candle patterns. /// </summary> [Description("High-Low ZigZag with Candle Patterns")] public class SVEHLZZCandlePattern : Indicator { #region Variables private double ZZPercent = 5; private int ATRPeriod = 5; private double ATRFactor = 1.5; private Color zigZagColor = Color.DodgerBlue; private int CandlePattern = 9; // Default 9, all patterns private int positioning = 10; // text above/below pivot in PIPS private int linewidth = 1; private int trend; // confirmed trend of current zigzag, 1=up, -1=down private int lhb; // last high bar count of last swing high private int uplineid; // last used up line (name) id private int llb; // last low bar count of last swing low private int downlineid; // last used down line name private double hh; // New Higher high private double ll; // New lower low private double HLPivot; // The high-low pivot level switch private int BullEng=0, BearEng=0, UpStep=0, DownStep=0, BullHaram = 0, BearHaram = 0; private int PatternCnt=0; private Font candlefont = new Font("Arial", 10.0F,FontStyle.Bold); #endregion // ----------------------------------------------------------------------------------- /// <summary> /// Method used to configure the indicator called once before any bar data. /// </summary> protected override void Initialize() { CalculateOnBarClose = true; AutoScale = false; Overlay = true; } // ------------------------------------------------------------------------------------ /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar < 1) // minimum 2 bars required { ll = Low[0]; hh = High[0]; llb = lhb = 0; return; } if (CurrentBar < 2) // trend start based on bar 2 { if (High[0] >= hh) { hh = High[0]; lhb = 1; trend = 1; } else { ll = Low[0]; llb = 1; trend = -1; } uplineid = downlineid = CurrentBar; } // ATR factor = 0, only use percent setting if (ATRFactor == 0) HLPivot = (ZZPercent * 0.01); // Zigzag percent = 0, only use ATR else if (ZZPercent == 0) HLPivot = ATR(ATRPeriod)[0] / Close[0] * ATRFactor; // Use both influences else HLPivot = ZZPercent * 0.01 + ATR(ATRPeriod)[0] / Close[0] * ATRFactor; // look for swing points and draw lines if (trend > 0) // uptrend and a new higher high OR a new swing low? { if (High[0] >= hh) { // new higher high detected hh = High[0]; lhb = CurrentBar; // RemoveDrawObject("uplineid.ToString"); // Not required, handled by drawing line with the same name id DrawLine(uplineid.ToString(), AutoScale, CurrentBar-llb, ll, CurrentBar-lhb, hh, zigZagColor, DashStyle.Solid, linewidth); } else if (Low[0] < hh - hh*HLPivot) { // found a swing low ll = Low[0]; llb = CurrentBar; downlineid = CurrentBar; trend = -1; DrawLine(downlineid.ToString(), AutoScale, CurrentBar-lhb, hh, CurrentBar-llb, ll, zigZagColor, DashStyle.Solid, linewidth); if (CandlePattern != 0) { if (CandlePattern == 1 || CandlePattern == 9) //Step Down candle pattern? { StepDown(); if (DownStep == 0) BodyGapDown(); //not a normal Step Down, try a Body Gap Down if (DownStep == 1) { // Writes "D" 10 Tick sizes above the highest high DrawText(downlineid + 1.ToString(), true, "D", CurrentBar - lhb, hh + TickSize, positioning, Color.Red, candlefont, StringAlignment.Center, Color.Empty, Color.Empty, 0); //Show number of found patterns in top left corner of the chart PatternCnt++; DrawTextFixed("PatternCnt", PatternCnt.ToString(), TextPosition.TopLeft); return; //StepDown pattern, not looking for any other pattern } } if (CandlePattern == 2 || CandlePattern == 9) BearishEngulfing(); if (BearEng == 1) { // Writes "E" 10 Ticks above the highest high DrawText(downlineid + 2.ToString(), true, "E", CurrentBar - lhb, hh + TickSize, positioning, Color.Red, candlefont, StringAlignment.Center, Color.Empty, Color.Empty, 0); PatternCnt++; DrawTextFixed("PatternCnt", PatternCnt.ToString(), TextPosition.TopLeft); return; //Bearish Engulfing pattern, not looking for any other pattern } if (CandlePattern == 3 || CandlePattern == 9) BearishHarami(); if (BearHaram == 1) { // Writes "H" 10 Ticks above the highest high DrawText(downlineid + 3.ToString() , true, "H", CurrentBar - lhb, hh + TickSize, positioning, Color.Red, candlefont, StringAlignment.Center, Color.Empty, Color.Empty, 0); PatternCnt++; DrawTextFixed("PatternCnt", PatternCnt.ToString(), TextPosition.TopLeft); return; //Bearish Harami pattern, not looking for any other pattern } } } } else // trend is down, look for a down continuation or a new swing high { if (Low[0] <= ll) { // new lower low detected ll = Low[0]; llb = CurrentBar; // RemoveDrawObject("downlineid.ToString"); // Not required, handled by drawing line with the same name id DrawLine(downlineid.ToString(), AutoScale, CurrentBar-lhb, hh, CurrentBar-llb, ll, zigZagColor, DashStyle.Solid, linewidth); } else if (High[0] > ll + ll * HLPivot) { // found a swing high hh = High[0]; lhb = CurrentBar; uplineid = CurrentBar; trend = 1; DrawLine(uplineid.ToString(), AutoScale, CurrentBar-llb, ll, CurrentBar-lhb, hh, zigZagColor, DashStyle.Solid, linewidth); if (CandlePattern != 0) { if (CandlePattern == 1 || CandlePattern == 9) // StepUp pattern { StepUp(); if (UpStep == 0) BodyGapUp(); if (UpStep == 1) { // Writes "U" 10 Tick sizes below the lowest low DrawText(uplineid + 1.ToString(), true, "U", CurrentBar-llb, ll-TickSize, - positioning, Color.Blue, candlefont, StringAlignment.Center, Color.Empty, Color.Empty, 0); PatternCnt++; DrawTextFixed("PatternCnt", PatternCnt.ToString(), TextPosition.TopLeft); return; //StepUp pattern, not looking for any other pattern } } if (CandlePattern == 2 || CandlePattern == 9) BullishEngulfing(); if (BullEng == 1) { // Writes "E" 10 Tick sizes below the lowest low DrawText(uplineid + 2.ToString(), true, "E", CurrentBar-llb, ll-TickSize, - positioning, Color.Blue, candlefont, StringAlignment.Center, Color.Empty, Color.Empty, 0); PatternCnt++; DrawTextFixed("PatternCnt", PatternCnt.ToString(), TextPosition.TopLeft); return; //Bullish Engulfing pattern, not looking for any other pattern } if (CandlePattern == 3 || CandlePattern == 9) BullishHarami(); if (BullHaram == 1) { // Writes "H" 10 Tick sizes below the lowest low of the up turning point DrawText(uplineid + 3.ToString(), true, "H", CurrentBar - llb, ll - TickSize, - positioning, Color.Blue, candlefont, StringAlignment.Center, Color.Empty, Color.Empty, 0); PatternCnt++; DrawTextFixed("PatternCnt", PatternCnt.ToString(), TextPosition.TopLeft); return; //Bullish harami pattern, not looking for any other pattern } } } } } #region BullishEngulfing private void BullishEngulfing() { // Black small body or doji before last low bar and larger white body at last low if (Close[CurrentBar-llb+1] <= Open[CurrentBar-llb+1] && Close[CurrentBar-llb] > Open[CurrentBar-llb] && Open[CurrentBar-llb] <= Close[CurrentBar-llb+1] && Close[CurrentBar-llb] >= Open[CurrentBar-llb+1] || // Black small body or doji at the last low bar and larger white body after last low Close[CurrentBar-llb] <= Open[CurrentBar-llb] && Close[CurrentBar-llb-1] > Open[CurrentBar-llb-1] && Open[CurrentBar-llb-1] <= Close[CurrentBar-llb] && Close[CurrentBar-llb-1] >= Open[CurrentBar-llb] || // White small body or doji before last low bar and larger white body at last low bar Close[CurrentBar-llb+1] >= Open[CurrentBar-llb+1] && Close[CurrentBar-llb] > Open[CurrentBar-llb] && Open[CurrentBar-llb] <= Open[CurrentBar-llb+1] && Close[CurrentBar-llb] >= Close[CurrentBar-llb+1] || // White small body or doji at last low bar and larger white body after last low bar Close[CurrentBar-llb] >= Open[CurrentBar-llb] && Close[CurrentBar-llb-1] > Open[CurrentBar-llb-1] && Open[CurrentBar-llb-1] <= Open[CurrentBar-llb] && Close[CurrentBar-llb-1] >= Close[CurrentBar-llb]) BullEng = 1; else BullEng = 0; } #endregion #region BearishEngulfing private void BearishEngulfing() { // White small body or doji before last high bar and larger black body at last high if (Close[CurrentBar-lhb+1] >= Open[CurrentBar-lhb+1] && Close[CurrentBar-lhb] < Open[CurrentBar-lhb] && Open[CurrentBar-lhb] >= Close[CurrentBar-lhb+1] && Close[CurrentBar-lhb] <= Open[CurrentBar-lhb+1] || // White small body or doji at last high bar and larger black body after last high bar Close[CurrentBar-lhb] >= Open[CurrentBar-lhb] && Close[CurrentBar-lhb-1] < Open[CurrentBar-lhb-1] && Open[CurrentBar-lhb-1] >= Close[CurrentBar-lhb] && Close[CurrentBar-lhb-1] <= Open[CurrentBar-lhb] || // Black small body or doji before last high bar and larger Black body at last high bar Close[CurrentBar-lhb+1] <= Open[CurrentBar-lhb+1] && Close[CurrentBar-lhb] < Open[CurrentBar-lhb] && Open[CurrentBar-lhb] >= Open[CurrentBar-lhb+1] && Close[CurrentBar-lhb] <= Close[CurrentBar-lhb+1] || // Black small body or doji at last high bar and larger Black body after last high bar Close[CurrentBar-lhb] <= Open[CurrentBar-lhb] && Close[CurrentBar-lhb-1] < Open[CurrentBar-lhb-1] && Open[CurrentBar-lhb-1] >= Open[CurrentBar-lhb] && Close[CurrentBar-lhb-1] <= Close[CurrentBar-lhb]) BearEng = 1; else BearEng = 0; } #endregion #region StepUp private void StepUp() { // Black body before last low bar and a stepup white body at last low bar if (Close[CurrentBar-llb+1] < Open[CurrentBar-llb+1] && Close[CurrentBar-llb] > Open[CurrentBar-llb] && Open[CurrentBar-llb] >= Close[CurrentBar-llb+1] && Open[CurrentBar-llb] <= Open[CurrentBar-llb+1] && Close[CurrentBar-llb] > Open[CurrentBar-llb+1] || // Black body at the last low bar and stepup white body after last low bar Close[CurrentBar-llb] < Open[CurrentBar-llb] && Close[CurrentBar-llb-1] > Open[CurrentBar-llb-1] && Open[CurrentBar-llb-1] >= Close[CurrentBar-llb] && Open[CurrentBar-llb-1] <= Open[CurrentBar-llb] && Close[CurrentBar-llb-1] > Open[CurrentBar-llb] || // White body before last low bar and a stepup white body at last low bar Close[CurrentBar-llb+1] > Open[CurrentBar-llb+1] && Close[CurrentBar-llb] > Open[CurrentBar-llb] && Open[CurrentBar-llb] >= Open[CurrentBar-llb+1] && Open[CurrentBar-llb] <= Close[CurrentBar-llb+1] && Close[CurrentBar-llb] > Close[CurrentBar-llb+1] || // White body at last low bar and a stepup white body after last low bar Close[CurrentBar-llb] > Open[CurrentBar-llb] && Close[CurrentBar-llb-1] > Open[CurrentBar-llb-1] && Open[CurrentBar-llb-1] >= Open[CurrentBar-llb] && Open[CurrentBar-llb-1] <= Close[CurrentBar-llb] && Close[CurrentBar-llb-1] > Close[CurrentBar-llb]) UpStep = 1; else UpStep = 0; } #endregion #region BodyGapUp private void BodyGapUp() { // Black body at the last low bar followed by a bar with a gap up or equal value if (Close[CurrentBar-llb] <= Open[CurrentBar-llb] && Open[CurrentBar-llb-1] >= Open[CurrentBar-llb] && Close[CurrentBar-llb-1] >= Open[CurrentBar-llb] || // White body at last low bar followed by a bar with a gap up or equal value Close[CurrentBar-llb] >= Open[CurrentBar-llb] && Open[CurrentBar-llb-1] >= Close[CurrentBar-llb] && Close[CurrentBar-llb-1] >= Close[CurrentBar-llb]) UpStep = 1; else UpStep = 0; } #endregion #region StepDown private void StepDown() { // 1- Black body before last high bar and a stepdown black body at last high bar if (Close[CurrentBar-lhb+1] < Open[CurrentBar-lhb+1] && Close[CurrentBar-lhb] < Open[CurrentBar-lhb] && Open[CurrentBar-lhb] <= Open[CurrentBar-lhb+1] && Open[CurrentBar-lhb] >= Close[CurrentBar-lhb+1] && Close[CurrentBar-lhb] < Close[CurrentBar-lhb+1] || // 2- Black body at the last high bar and stepdown black body after last high bar Close[CurrentBar-lhb] < Open[CurrentBar-lhb] && Close[CurrentBar-lhb-1] < Open[CurrentBar-lhb-1] && Open[CurrentBar-lhb-1] <= Open[CurrentBar-lhb] && Open[CurrentBar-lhb-1] >= Close[CurrentBar-lhb] && Close[CurrentBar-lhb-1] < Close[CurrentBar-lhb] || // 3- White body before last high bar and a stepdown black body at last high bar Close[CurrentBar-lhb+1] > Open[CurrentBar-lhb+1] && Close[CurrentBar-lhb] < Open[CurrentBar-lhb] && Open[CurrentBar-lhb] <= Close[CurrentBar-lhb+1] && Open[CurrentBar-lhb] >= Open[CurrentBar-lhb+1] && Close[CurrentBar-lhb] < Open[CurrentBar-lhb+1] || // 4- White body at last high bar and a stepdown black body after last high bar Close[CurrentBar-lhb] > Open[CurrentBar-lhb] && Close[CurrentBar-lhb-1] < Open[CurrentBar-lhb-1] && Open[CurrentBar-lhb-1] <= Close[CurrentBar-lhb] && Open[CurrentBar-lhb-1] >= Open[CurrentBar-lhb] && Close[CurrentBar-lhb-1] < Open[CurrentBar-lhb]) DownStep = 1; else DownStep = 0; } #endregion #region BodyGapDown private void BodyGapDown() { // White body OR doji at the last high bar followed by a bar with a gap down or equal value if (Close[CurrentBar-lhb] >= Open[CurrentBar-lhb] && Open[CurrentBar-lhb-1] <= Open[CurrentBar-lhb] && Close[CurrentBar-lhb-1] <= Open[CurrentBar-lhb] || // Black body OR doji at the last high bar followed by a bar with a gap down or equal value Close[CurrentBar-lhb] <= Open[CurrentBar-lhb] && Open[CurrentBar-lhb-1] <= Close[CurrentBar-lhb] && Close[CurrentBar-lhb-1] <= Close[CurrentBar-lhb]) DownStep = 1; else DownStep = 0; } #endregion #region BullishHarami private void BullishHarami() { // Black body at the last low bar and small white OR black body after last low bar if (Close[CurrentBar-llb] < Open[CurrentBar-llb] && Open[CurrentBar-llb-1] >= Close[CurrentBar-llb] && Open[CurrentBar-llb-1] <= Open[CurrentBar-llb] && Close[CurrentBar-llb-1] >= Close[CurrentBar-llb] && Close[CurrentBar-llb-1] <= Open[CurrentBar-llb] || // White body at the last low bar and small white OR black body after last low bar Close[CurrentBar-llb] > Open[CurrentBar-llb] && Open[CurrentBar-llb-1] <= Close[CurrentBar-llb] && Open[CurrentBar-llb-1] >= Open[CurrentBar-llb] && Close[CurrentBar-llb-1] <= Close[CurrentBar-llb] && Close[CurrentBar-llb-1] >= Open[CurrentBar-llb] || // Black body before the last low bar and small white OR black body at last low bar Close[CurrentBar-llb+1] < Open[CurrentBar-llb+1] && Open[CurrentBar-llb] >= Close[CurrentBar-llb+1] && Open[CurrentBar-llb] <= Open[CurrentBar-llb+1] && Close[CurrentBar-llb] >= Close[CurrentBar-llb+1] && Close[CurrentBar-llb] <= Open[CurrentBar-llb+1] || // White body before the last low bar and small white OR black body at last low bar Close[CurrentBar-llb+1] > Open[CurrentBar-llb+1] && Open[CurrentBar-llb] <= Close[CurrentBar-llb+1] && Open[CurrentBar-llb] >= Open[CurrentBar-llb+1] && Close[CurrentBar-llb] <= Close[CurrentBar-llb+1] && Close[CurrentBar-llb] >= Open[CurrentBar-llb+1]) BullHaram = 1; else BullHaram = 0; } #endregion #region BearishHarami private void BearishHarami() { // Black body at the last high bar and small white OR black body after last high bar if (Close[CurrentBar-lhb] < Open[CurrentBar-lhb] && Open[CurrentBar-lhb-1] >= Close[CurrentBar-lhb] && Open[CurrentBar-lhb-1] <= Open[CurrentBar-lhb] && Close[CurrentBar-lhb-1] >= Close[CurrentBar-lhb] && Close[CurrentBar-lhb-1] <= Open[CurrentBar-lhb] || // White body at the last high bar and small white OR black body after last high bar Close[CurrentBar-lhb] > Open[CurrentBar-lhb] && Open[CurrentBar-lhb-1] <= Close[CurrentBar-lhb] && Open[CurrentBar-lhb-1] >= Open[CurrentBar-lhb] && Close[CurrentBar-lhb-1] <= Close[CurrentBar-lhb] && Close[CurrentBar-lhb-1] >= Open[CurrentBar-lhb] || // Black body before the last high bar and small white OR black body at last high bar Close[CurrentBar-lhb+1] < Open[CurrentBar-lhb+1] && Open[CurrentBar-lhb] >= Close[CurrentBar-lhb+1] && Open[CurrentBar-lhb] <= Open[CurrentBar-lhb+1] && Close[CurrentBar-lhb] >= Close[CurrentBar-lhb+1] && Close[CurrentBar-lhb] <= Open[CurrentBar-lhb+1] || // White body before the last high bar and small white OR black body at last high bar Close[CurrentBar-lhb+1] > Open[CurrentBar-lhb+1] && Open[CurrentBar-lhb] <= Close[CurrentBar-lhb+1] && Open[CurrentBar-lhb] >= Open[CurrentBar-lhb+1] && Close[CurrentBar-lhb] <= Close[CurrentBar-lhb+1] && Close[CurrentBar-lhb] >= Open[CurrentBar-lhb+1]) BearHaram = 1; else BearHaram = 0; } #endregion #region Properties [Description("ZigZag percent influence DEF = 5%, 0 = NO influence")] [Category("Parameters")] [Gui.Design.DisplayName("1. ZigZag Percentage")] public double _ZigZag_Percentage { get { return ZZPercent; } set { ZZPercent = Math.Max(0, value); } } [Description("ATR Look back Period DEFAULT = 5")] [Category("Parameters")] [Gui.Design.DisplayName("2. ATR Period")] public int ATR__Period { get { return ATRPeriod; } set { ATRPeriod = Math.Max(1, value); } } [Description("ZigZag ATR factor DEF = 1.5, 0 means NO influence")] [Category("Parameters")] [Gui.Design.DisplayName("3. ATR Factor")] public double ATR_Factor { get { return ATRFactor; } set { ATRFactor = Math.Max(0, value); } } [Description("Candle pattern: 1 = StepUp/Down, 2 = Engulfing, 3 = Harami, 9 = All; 0 = None")] [Category("Parameters")] [Gui.Design.DisplayName("4. Candle Pattern")] public int Candle_Pattern { get { return CandlePattern; } set { CandlePattern = Math.Max(0, value); } } [Description("Candle pattern text distance in pips above/below pivot point")] [Category("Parameters")] [Gui.Design.DisplayName("5. Text Distance in PIPS")] public int Text_Distance_in_PIPS { get { return positioning; } set { positioning = Math.Max(0, value); } } [Description("Color of the individual zigzag lines DEFAULT = DodgerBlue")] [Category("Parameters")] [Gui.Design.DisplayName("6. ZigZag Color")] public Color ZigZag_Color { get { return zigZagColor; } set { zigZagColor = value; } } [Browsable(false)] public string PainttrendcolorSerialize { get { return NinjaTrader.Gui.Design.SerializableColor.ToString(zigZagColor); } set { zigZagColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); } } #endregion } }