last works on Candlestick Patterns ...
This commit is contained in:
@@ -0,0 +1,644 @@
|
||||
|
||||
//
|
||||
// Check Bar has Strong Body or Not ...
|
||||
bool HasStrongBody()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (!IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double body = GetBody();
|
||||
double shadow = GetShadows();
|
||||
|
||||
//
|
||||
result = body > shadow * 1.5;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Bar Must Open Below Prce
|
||||
// and Close Above it ...
|
||||
bool IsBreakUp(
|
||||
double price // a Price to Check Breake
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = HasStrongBody();
|
||||
if (!result || price <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Select required Prices ...
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
close > price &&
|
||||
open < price;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Bar Must Open Above Prce
|
||||
// and Close Below it ...
|
||||
bool IsBreakDown(
|
||||
double price // a Price to Check Breake
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = HasStrongBody();
|
||||
if (!result || price <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Select required Prices ...
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
open > price &&
|
||||
close < price;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool IsBreakOut(
|
||||
double price, // a Price to Check Breake
|
||||
bool useHighLow = true // if true using High and Low price for Breakeouts, if not use Open Close
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = HasStrongBody();
|
||||
if (!result || price <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Select required Prices ...
|
||||
|
||||
//
|
||||
double selectedUp =
|
||||
useHighLow
|
||||
? high
|
||||
: GetUp();
|
||||
double selectedDown =
|
||||
useHighLow
|
||||
? low
|
||||
: GetDown();
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
selectedUp > price &&
|
||||
selectedDown < price;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check a Support Line Rejected or not ...
|
||||
bool IsSupportRejected(
|
||||
double price // Support Price
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// this is zBar ...
|
||||
// so we are try to Recieve CBar ...
|
||||
XOHCL cBar;
|
||||
result = this.GetPreviousBar(cBar);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Now we are going to Recieve PBar ...
|
||||
XOHCL pBar;
|
||||
result = cBar.GetPreviousBar(pBar);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// We Have this (0) Bar, cBar (1) and pBar (2) ...
|
||||
|
||||
//
|
||||
// pBar Down Shadow must break Price Line ...
|
||||
// cBar and zBar Close must be Above Price Line ...
|
||||
// also zBar Open must be Above Price Line ...
|
||||
result =
|
||||
//
|
||||
pBar.high > price &&
|
||||
pBar.low < price &&
|
||||
cBar.close > price &&
|
||||
this.close > price &&
|
||||
this.open > price
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check a Support Line Breaked or not ...
|
||||
bool IsSupportBreaked(
|
||||
double price // Support Price
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// this is zBar ...
|
||||
// so we are try to Recieve CBar ...
|
||||
XOHCL cBar;
|
||||
result = this.GetPreviousBar(cBar);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Now we are going to Recieve PBar ...
|
||||
XOHCL pBar;
|
||||
result = cBar.GetPreviousBar(pBar);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// We Have this (0) Bar, cBar (1) and pBar (2) ...
|
||||
|
||||
//
|
||||
// pBar Down Shadow must break Price Line ...
|
||||
// cBar and zBar Close must be Below Price Line ...
|
||||
// also zBar Open must be Below Price Line ...
|
||||
result =
|
||||
//
|
||||
pBar.high > price &&
|
||||
pBar.low < price &&
|
||||
cBar.close < price &&
|
||||
this.close < price &&
|
||||
this.open < price
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check a Resistance Line Rejected or not ...
|
||||
bool IsResistanceRejected(
|
||||
double price // Resistance Price
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// this is zBar ...
|
||||
// so we are try to Recieve CBar ...
|
||||
XOHCL cBar;
|
||||
result = this.GetPreviousBar(cBar);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Now we are going to Recieve PBar ...
|
||||
XOHCL pBar;
|
||||
result = cBar.GetPreviousBar(pBar);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// We Have this (0) Bar, cBar (1) and pBar (2) ...
|
||||
|
||||
//
|
||||
// pBar Up Shadow must break Price Line ...
|
||||
// cBar and zBar Close must be Under Price Line ...
|
||||
// also zBar Open must be Under Price Line ...
|
||||
result =
|
||||
//
|
||||
pBar.high > price &&
|
||||
pBar.low < price &&
|
||||
cBar.close < price &&
|
||||
this.close < price &&
|
||||
this.open < price
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check a Resistance Line Breaked or not ...
|
||||
bool IsResistanceBreaked(
|
||||
double price // Support Price
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// this is zBar ...
|
||||
// so we are try to Recieve CBar ...
|
||||
XOHCL cBar;
|
||||
result = this.GetPreviousBar(cBar);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Now we are going to Recieve PBar ...
|
||||
XOHCL pBar;
|
||||
result = cBar.GetPreviousBar(pBar);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// We Have this (0) Bar, cBar (1) and pBar (2) ...
|
||||
|
||||
//
|
||||
// pBar Up Shadow must break Price Line ...
|
||||
// cBar and zBar Close must be Over Price Line ...
|
||||
// also zBar Open must be Pver Price Line ...
|
||||
result =
|
||||
//
|
||||
pBar.low < price &&
|
||||
pBar.high > price &&
|
||||
cBar.close > price &&
|
||||
this.close > price &&
|
||||
this.open > price
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Bar is Inside Previus Bar ...
|
||||
bool IsInsideBar(
|
||||
double threshold = 5 // Points Distance between Up and Down
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (threshold < 0)
|
||||
{
|
||||
threshold = 0;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL pBar;
|
||||
result = GetPreviousBar(pBar);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double offset = PointToPrice(threshold, this.symbol);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
pBar.high > this.high &&
|
||||
pBar.low < this.low &&
|
||||
MathAbs(pBar.low - this.low) > offset &&
|
||||
MathAbs(pBar.high - this.high) > offset
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Bar has Strongest Body in a Range ...
|
||||
bool HasStrongestBody(
|
||||
int mLoopback = 3 // loopback candles to compare it ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double body = GetBody();
|
||||
XOHCL prev = this;
|
||||
for (int i = 0; i < mLoopback; i++)
|
||||
{
|
||||
//
|
||||
bool isValid = prev.GetPreviousBar(prev);
|
||||
if (!isValid)
|
||||
{
|
||||
//
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
result &&
|
||||
body > prev.GetBody()
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Bar has Weakest Body in a Range ...
|
||||
bool HasWeakestBody(
|
||||
int mLoopback = 3 // loopback candles to compare it ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double body = GetBody();
|
||||
XOHCL prev = this;
|
||||
for (int i = 0; i < mLoopback; i++)
|
||||
{
|
||||
//
|
||||
bool isValid = prev.GetPreviousBar(prev);
|
||||
if (!isValid)
|
||||
{
|
||||
//
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
result &&
|
||||
body < prev.GetBody()
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Determines Swings based On this Bar ...
|
||||
// Calculates Based on atleast 3 Bars Prev ...
|
||||
ENUM_X_SWING_TYPE GetSwingType()
|
||||
{
|
||||
//
|
||||
ENUM_X_SWING_TYPE result = X_NO_SWING;
|
||||
|
||||
//
|
||||
// Find Current Index of Bar ...
|
||||
int barIndex = Index();
|
||||
if (barIndex <= -1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// First we have to Retrieve atleast 3 Bars before this bar ...
|
||||
XOHCL bars[];
|
||||
int barsCount = GetBars(
|
||||
bars,
|
||||
symbol,
|
||||
period,
|
||||
barIndex + 1,
|
||||
3
|
||||
//
|
||||
);
|
||||
if (barsCount < 3)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Swing Start Candle has Strong Body ...
|
||||
bool isStrongBodyCandle = bars[2].HasStrongBody();
|
||||
if (!isStrongBodyCandle)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Swing Low Conditions ...
|
||||
bool isSwingLowOrderBlock =
|
||||
bars[2].low < bars[1].low &&
|
||||
bars[1].low < bars[0].low &&
|
||||
bars[2].low < bars[0].low;
|
||||
if (isSwingLowOrderBlock)
|
||||
{
|
||||
result = X_SWING_LOW;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Swing High Conditions ...
|
||||
bool isSwingHighOrderBlock =
|
||||
bars[2].high > bars[1].high &&
|
||||
bars[1].high > bars[0].high &&
|
||||
bars[2].high > bars[0].high;
|
||||
if (isSwingHighOrderBlock)
|
||||
{
|
||||
result = X_SWING_HIGH;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Check Bar Is Hammer Pattern ...
|
||||
bool IsHammer()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
double fib382 = GetFibonacciLevel(
|
||||
high,
|
||||
low,
|
||||
0.382,
|
||||
-1 //
|
||||
);
|
||||
|
||||
//
|
||||
result = GetDown() > fib382;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Bar Is Shooting Star Pattern ...
|
||||
bool IsShootingStar()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
double fib382 = GetFibonacciLevel(
|
||||
high,
|
||||
low,
|
||||
0.382,
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
result = GetUp() < fib382;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Bar Bullish Engulfing Pattern ...
|
||||
bool IsBullishEngulf()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Current Bar Must be Bullish ...
|
||||
result = IsBullish();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Previous Bar ...
|
||||
XOHCL pBar;
|
||||
result = GetPreviousBar(pBar);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
pBar.IsBearish() &&
|
||||
open < pBar.close && close > pBar.open &&
|
||||
high >= pBar.high && low <= pBar.low
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Bar Bearish Engulfing Pattern ...
|
||||
bool IsBearishEngulf()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Current Bar Must be Bearish ...
|
||||
result = IsBearish();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Previous Bar ...
|
||||
XOHCL pBar;
|
||||
result = GetPreviousBar(pBar);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
pBar.IsBullish() &&
|
||||
open > pBar.close && close < pBar.open &&
|
||||
high >= pBar.high && low <= pBar.low
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user