АмиБрокер. The Step Candle Pattern

Метод определения свечных паттернов, которые появляются в поворотных точках. Код основан на формуле, представленной в статье «Подсчет волн 1-2-3», путем добавления правил идентификации свечных паттернов.

Формула индикатора The Step Candle Pattern

nc = Ref( Close, 1 ); // next close 
pc = Ref( Close, -1 ); // previous close 
no = Ref( Open, 1 ); // next open 
po = Ref( Open, -1 ); // previous open 

StepUp = 
// Black body before last low bar 
// and a step up white body at last low bar 
( pC < pO AND 
  Close > Open AND 
  Open >= pC AND 
  Open <= pO AND 
  Close > pO OR 
// Black body at the last low bar 
// and step up white body after last low bar 
  Close < Open AND 
  nC > nO AND  
  nO >= Close AND 
  nO <= Open AND 
  nC > Open OR 
// White body before last low bar 
// and step up white body at last low bar 
  pC > pO AND 
  Close > Open AND 
  Open >= pO AND 
  Open <= pC AND 
  Close > pC OR 
// White body at last low bar 
// and a step up white body after last low bar 
  Close > Open AND 
  nC > po AND 
  nO >= Open AND 
  nO <= Close AND 
  nC > Close ); 

StepDown = 
// Black body before last high bar 
// and a step down black body at last high bar 
( pC < pO AND 
  Close < Open AND 
  Open <= pO AND 
  Open >= pC AND 
  Close < pC OR 
// Black body at the last high bar 
// and step down black body after last high bar 
  Close < Open AND 
  nC < nO AND 
  nO <= Open AND 
  nO >= Close AND 
  nC < Close OR 
// White body before last high bar 
// and a step down black body at last high bar 
  pC > pO AND 
  Close < Open AND 
  Open <= pC AND 
  Open >= pO AND 
  Close < pO OR 
// White body at last high bar 
// and a step down black body after last high bar 
  Close > Open AND 
  nC < nO AND 
  nO <= Close AND 
  nO >= Open AND 
  nC < Open ); 

BodyGapUp = 
// Black body at the last low bar 
// followed by a bar with a gap up or equal value 
( Close <= Open AND 
  nO >= Open AND 
  nC >= Open OR 
// White body at last low bar 
// followed by a bar with a gap up or equal value 
  Close >= Open AND 
  nO >= Close AND 
  nC >= Close ); 

BodyGapDown = 
// White body at last high bar 
// followed by a bar with a gap down or equal value 
( Close >= Open AND 
  nO <= Open AND 
  nC <= Open OR 
// Black body at last high bar 
// followed by a bar with a gap down or equal value 
  Close <= Open AND 
  nO <= Close AND 
  nC <= Close ); 

BullishEngulfing = 
// Black small body or doji before last low bar 
// and larger white at last low bar 
( pC <= pO AND 
  Close > Open AND 
  Open <= pC AND 
  Close >= pO OR 
// Black small body or doji at the last low bar 
// and larger white after last low bar 
  Close <= Open AND 
  nC > nO AND 
  nO <= Close AND 
  nC >= Open OR 
// White small body or doji before last low bar 
// and larger white at last low bar 
  pC >= pO AND 
  Close > Open AND 
  Open <= pO AND 
  Close >= pC OR 
// White small body or doji at last low bar 
// and larger white after last low bar 
  Close >= Open AND 
  nC > O AND 
  nO <= Open AND 
  nC >= Close ); 

BearishEngulfing = 
// White small body or doji before last high bar 
// and larger black body at last high 
( pC >= pO AND 
  Close < Open AND 
  Open >= pC AND 
  Close <= pO OR 
// White small body or doji at last high bar 
// and larger black body after last high bar 
  Close >= Open AND 
  nC < nO AND 
  nO >= Close AND 
  nC <= Open OR 
// Black small body or doji before last high bar 
// and larger Black body at last high bar 
  pC <= pO AND 
  Close < Open AND 
  Open >= pO AND 
  Close <= pC OR 
// Black small body or doji at last high bar 
// and larger Black body after last high bar 
  Close <= Open AND 
  nC < nO AND 
  nO >= Open AND 
  nC <= Close ); 

BullishHarami = 
// Black body at the last low bar and small white 
// OR black body after last low bar 
( Close < Open AND 
  nO >= Close AND 
  nO <= Open AND 
  nC >= Close AND 
  nC <= Open OR 
// White body at the last low bar and small white 
// OR black body after last low bar 
  Close > Open AND 
  nO <= Close AND 
  nO >= Open AND 
  nC <= Close AND 
  nC >= Open OR 
// Black body before the last low bar and small white 
// OR black body at last low bar 
  pC < no AND 
  Open >= pC AND 
  Open <= pO AND 
  Close >= pC AND 
  Close <= pO OR 
// White body before the last low bar and small white 
// OR black body at last low bar 
  pC > pO AND 
  Open <= pC AND 
  Open >= pO AND 
  Close <= pC AND 
  Close >= pO ); 

BearishHarami = 
// Black body at the last high bar and small white 
// OR black body after last high bar 
( Close < Open AND 
  nO >= Close AND 
  nO <= Open AND 
  nC >= Close AND 
  nC <= Open OR 
// White body at the last high bar and small white 
// OR black body after last high bar 
  Close > Open AND 
  nO <= Close AND 
  nO >= Open AND 
  nC <= Close AND 
  nC >= Open OR 
// Black body before the last high bar and small white 
// OR black body at last high bar 
  pC < pO AND 
  Open >= pC AND 
  Open <= pO AND 
  Close >= pC AND 
  Close <= pO OR 
// White body before the last high bar and small white 
// OR black body at last high bar 
  pC > pO AND 
  Open <= pC AND 
  Open >= pO AND 
  Close <= pC AND 
  Close >= pO ); 

function DrawBearishPattern( CandlePattern, bar, y ) 
{ 
  Found = False; 

  if( CandlePattern == "Step Up/Dn" OR CandlePattern == "All" ) 
  { 
    if( StepDown[ bar ] OR BodyGapDown[ bar ] ) 
    { 
      PlotText( "D", bar, y, colorRed ); 
      Found = True; 
    } 
  } 

  if( NOT Found AND 
     ( CandlePattern == "Engulfing" OR CandlePattern == "All" ) ) 
  { 
    if( BearishEngulfing[ bar ] ) 
    { 
      PlotText( "E", bar, y, colorRed ); 
      Found = True; 
    } 
  } 

  if( NOT Found AND 
     ( CandlePattern == "Harami" OR CandlePattern == "All" ) ) 
  { 
    if( BearishHarami[ bar ] ) 
    { 
      PlotText( "H", bar, y, colorRed ); 
      Found = True; 
    } 
  } 

  return Found; 
} 

function DrawBullishPattern( CandlePattern, bar, y ) 
{ 
  Found = False; 

  if( CandlePattern == "Step Up/Dn" OR CandlePattern == "All" ) 
  { 
    if( StepUp[ bar ] OR BodyGapUp[ bar ] ) 
    { 
      PlotText( "U", bar, y, colorBlue ); 
      Found = True; 
    } 
  } 

  if( NOT Found AND 
     ( CandlePattern == "Engulfing" OR CandlePattern == "All" ) ) 
  { 
    if( BullishEngulfing[ bar ] ) 
    { 
      PlotText( "E", bar, y, colorBlue ); 
      Found = True; 
    } 
  } 

  if( NOT Found AND 
     ( CandlePattern == "Harami" OR CandlePattern == "All" ) ) 
  { 
    if( BullishHarami[ bar ] ) 
    { 
      PlotText( "H", bar, y, colorBlue ); 
      Found = True; 
    } 
  } 

  return Found; 
} 

CandlePattern = ParamList("CandlePattern", 
                "None|Step Up/Dn|Engulfing|Harami|All", 4); 
ZZPercent = Param("ZZPercent", 5 ); 
ATRPeriod = Param("ATRPeriod", 5 ); 
ATRFactor = Param("ATRFactor", 1.5, 0, 5 ); 

HLPivot = ZZPercent * 0.01 + ATRFactor * ATR( ATRPeriod )/Close; 

Ll = Low[ 0 ]; 
Hh = High[ 0 ]; 
Llb = Lhb = 0; 

if( High[ 1 ] >= Hh ) 
{ 
  Hh = High[ 1 ]; 
  Lhb = trend = 1; 
} 
else 
{ 
  Ll = Low[ 1 ]; 
  Llb = 1; 
  trend = -1; 
} 

Line = Null; 

PattFound = 0; 

for( i = 2; i < BarCount; i++ ) 
{ 
  if( trend > 0 ) 
  { 
    if( High[ i ] >= Hh ) 
    { 
      Hh = High[ i ]; 
      Lhb = i; 
      Curline = LineArray( Llb, Ll, Lhb, Hh ); 
      Line = IIf( IsNull( CurLine ), Line, CurLine ); 
    } 
    else 
    if( Low[ i ] < Hh - Hh * HLPivot[ i ] ) 
    { 
      Ll = Low[ i ]; 
      Llb = i; 
      trend = -1; 
      CurLine = LineArray( Lhb, Hh, Llb, Ll ); 
      Line = IIf( IsNull( CurLine ), Line, CurLine ); 

      PattFound += DrawBearishPattern( CandlePattern, Lhb, Hh + HH*0.01); 
    } 
  } 
  else 
  { 
    if( Low[ i ] <= Ll ) 
    { 
      Ll = Low[ i ]; 
      Llb = i; 
      CurLine = LineArray( Lhb, Hh, Llb, Ll ); 
      Line = IIf( IsNull( CurLine ), Line, CurLine ); 
    } 
    else 
    if( High[ i ] > Ll + Ll * HLPivot[ i ] ) 
    { 
      Hh = High[ i ]; 
      lhb = i; 
      trend = 1; 
      CurLine = LineArray( Llb, Ll, Lhb, Hh ); 
      Line = IIf( IsNull( CurLine ), Line, CurLine ); 

      PattFound += DrawBullishPattern( CandlePattern, LLb, LL - LL * 0.03); 
    } 
  } 
} 

Plot( Line, "", colorBlueGrey, styleThick ); 
Plot( Close, Date()+ " Close", colorDefault, styleCandle );
Erenbur

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *