backup all works even x121 ...
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;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,562 @@
|
||||
|
||||
//
|
||||
// Detect Trends ...
|
||||
struct XTrendDetector
|
||||
{
|
||||
//
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
double higherHighs[];
|
||||
datetime higherHighTimes[];
|
||||
|
||||
//
|
||||
double higherLows[];
|
||||
datetime higherLowTimes[];
|
||||
|
||||
//
|
||||
double lowerHighs[];
|
||||
datetime lowerHighTimes[];
|
||||
|
||||
//
|
||||
double lowerLows[];
|
||||
datetime lowerLowTimes[];
|
||||
|
||||
//
|
||||
bool isFirstLow;
|
||||
|
||||
//
|
||||
bool isUpTrend;
|
||||
bool isDownTrend;
|
||||
|
||||
//
|
||||
int _numberOfPivots;
|
||||
int _pivotShoulders;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XTrendDetector()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
bool FindTrend(
|
||||
string _symbol,
|
||||
ENUM_TIMEFRAMES _period,
|
||||
int barIndex = 0,
|
||||
int _requiredPivots = 3,
|
||||
int _requiredShoulders = 3 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
if (_requiredPivots < 3)
|
||||
{
|
||||
_requiredPivots = 3;
|
||||
}
|
||||
|
||||
//
|
||||
if (_requiredShoulders < 3)
|
||||
{
|
||||
_requiredShoulders = 3;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
IsValid(_symbol) &&
|
||||
IsValid(_period)
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Swing Lows and Swing Highs ...
|
||||
|
||||
//
|
||||
int hhIndexes[];
|
||||
datetime hhTimes[];
|
||||
double hhs[];
|
||||
|
||||
//
|
||||
int llIndexes[];
|
||||
datetime llTimes[];
|
||||
double lls[];
|
||||
|
||||
//
|
||||
bool isEnough = false;
|
||||
|
||||
//
|
||||
double lastHH = 0;
|
||||
int lastHHIndex = barIndex;
|
||||
datetime lastHHTime = NULL;
|
||||
|
||||
//
|
||||
double lastLL = 0;
|
||||
int lastLLIndex = barIndex;
|
||||
datetime lastLLTime = NULL;
|
||||
|
||||
//
|
||||
// Calculate First ...
|
||||
lastHHIndex = FindSwing(
|
||||
_symbol,
|
||||
_period,
|
||||
X_SWING_HIGH,
|
||||
_requiredShoulders,
|
||||
lastHHIndex + 1 //
|
||||
);
|
||||
if (lastHHIndex >= 0)
|
||||
{
|
||||
//
|
||||
XOHCL lastBar;
|
||||
bool isInited = lastBar.Init(
|
||||
_symbol,
|
||||
_period,
|
||||
lastHHIndex //
|
||||
);
|
||||
if (isInited)
|
||||
{
|
||||
//
|
||||
lastHH = lastBar.high;
|
||||
lastHHTime = lastBar.time;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
lastLLIndex = FindSwing(
|
||||
_symbol,
|
||||
_period,
|
||||
X_SWING_LOW,
|
||||
_requiredShoulders,
|
||||
lastLLIndex + 1 //
|
||||
);
|
||||
if (lastLLIndex >= 0)
|
||||
{
|
||||
//
|
||||
XOHCL lastBar;
|
||||
bool isInited = lastBar.Init(
|
||||
_symbol,
|
||||
_period,
|
||||
lastLLIndex //
|
||||
);
|
||||
if (isInited)
|
||||
{
|
||||
//
|
||||
lastHH = lastBar.high;
|
||||
lastHHTime = lastBar.time;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
lastLLIndex >= 0 &&
|
||||
lastHHIndex >= 0
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isFirstLow =
|
||||
//
|
||||
lastLLIndex < lastHHIndex
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
while (!isEnough)
|
||||
{
|
||||
//
|
||||
int hhSize = ArraySize(hhs);
|
||||
if (hhSize < _requiredPivots)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
int llSize = ArraySize(lls);
|
||||
if (llSize < _requiredPivots * 2)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
// while (!isEnough)
|
||||
// {
|
||||
// //
|
||||
// int hhSize = ArraySize(hhs);
|
||||
// if (hhSize < _requiredPivots * 2)
|
||||
// {
|
||||
// //
|
||||
// lastHHIndex = FindSwing(
|
||||
// _symbol,
|
||||
// _period,
|
||||
// X_SWING_HIGH,
|
||||
// _requiredShoulders,
|
||||
// lastHHIndex + 1 //
|
||||
// );
|
||||
// if (lastHHIndex >= 0)
|
||||
// {
|
||||
// //
|
||||
// XOHCL hBar;
|
||||
// bool isInited = hBar.Init(
|
||||
// _symbol,
|
||||
// _period,
|
||||
// lastHHIndex //
|
||||
// );
|
||||
// if (isInited)
|
||||
// {
|
||||
// //
|
||||
// Add(
|
||||
// hBar.high,
|
||||
// hhs //
|
||||
// );
|
||||
|
||||
// //
|
||||
// Add(
|
||||
// hBar.time,
|
||||
// hhTimes //
|
||||
// );
|
||||
|
||||
// //
|
||||
// Add(
|
||||
// lastHHIndex,
|
||||
// hhIndexes //
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// int llSize = ArraySize(lls);
|
||||
// if (llSize < _requiredPivots * 2)
|
||||
// {
|
||||
// //
|
||||
// lastLLIndex = FindSwing(
|
||||
// _symbol,
|
||||
// _period,
|
||||
// X_SWING_LOW,
|
||||
// _requiredShoulders,
|
||||
// lastLLIndex + 1 //
|
||||
// );
|
||||
// if (lastLLIndex >= 0)
|
||||
// {
|
||||
// //
|
||||
// XOHCL lBar;
|
||||
// bool isInited = lBar.Init(
|
||||
// _symbol,
|
||||
// _period,
|
||||
// lastLLIndex //
|
||||
// );
|
||||
// if (isInited)
|
||||
// {
|
||||
// //
|
||||
// Add(
|
||||
// lBar.low,
|
||||
// lls //
|
||||
// );
|
||||
|
||||
// //
|
||||
// Add(
|
||||
// lBar.time,
|
||||
// llTimes //
|
||||
// );
|
||||
|
||||
// //
|
||||
// Add(
|
||||
// lastHHIndex,
|
||||
// llIndexes //
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// hhSize = ArraySize(hhs);
|
||||
// llSize = ArraySize(lls);
|
||||
// isEnough =
|
||||
// //
|
||||
// hhSize == _requiredPivots * 2 &&
|
||||
// llSize == _requiredPivots * 2
|
||||
// //
|
||||
// ;
|
||||
// }
|
||||
|
||||
// //
|
||||
// ArrayReverse(hhs);
|
||||
// ArrayReverse(hhTimes);
|
||||
// ArrayReverse(hhIndexes);
|
||||
|
||||
// //
|
||||
// ArrayReverse(lls);
|
||||
// ArrayReverse(llTimes);
|
||||
// ArrayReverse(llIndexes);
|
||||
|
||||
//
|
||||
// Draws ...
|
||||
for (int i = 0; i < ArraySize(hhs); i++)
|
||||
{
|
||||
//
|
||||
DrawArrow(
|
||||
ChartID(),
|
||||
"XTRND_HH" + ToString(i),
|
||||
0,
|
||||
hhTimes[i],
|
||||
hhs[i],
|
||||
234,
|
||||
ANCHOR_BOTTOM,
|
||||
clrMagenta,
|
||||
STYLE_SOLID,
|
||||
3 //
|
||||
);
|
||||
|
||||
//
|
||||
DrawArrow(
|
||||
ChartID(),
|
||||
"XTRND_LL" + ToString(i),
|
||||
0,
|
||||
llTimes[i],
|
||||
lls[i],
|
||||
233,
|
||||
ANCHOR_TOP,
|
||||
clrAqua,
|
||||
STYLE_SOLID,
|
||||
3 //
|
||||
);
|
||||
}
|
||||
|
||||
// //
|
||||
// // Here We Try to Detect Trands ...
|
||||
// int idxHH = 0;
|
||||
// int idxLL = 0;
|
||||
// isEnough = false;
|
||||
// isFirstLow = llTimes[0] > hhTimes[0];
|
||||
// while(!isEnough) {
|
||||
// //
|
||||
// datetime firstTime = NULL;
|
||||
// if (isFirstLow) {
|
||||
// //
|
||||
// firstTime = llTimes[0];
|
||||
|
||||
// //
|
||||
// // Looking for a High ...
|
||||
|
||||
// //
|
||||
// if (hhs[hhIdx] > lls[llIdx]) {
|
||||
|
||||
// }
|
||||
// } else {
|
||||
// //
|
||||
// firstTime = hhTimes[0];
|
||||
|
||||
// //
|
||||
// // Looking for a Low ...
|
||||
// }
|
||||
// }
|
||||
|
||||
//
|
||||
isUpTrend =
|
||||
//
|
||||
isFirstLow
|
||||
?
|
||||
//
|
||||
lls[0] > lls[1] &&
|
||||
lls[1] > lls[2] &&
|
||||
//
|
||||
hhs[0] > hhs[1] &&
|
||||
hhs[1] > hhs[2]
|
||||
//
|
||||
:
|
||||
//
|
||||
hhs[0] > hhs[1] &&
|
||||
hhs[1] > hhs[2] &&
|
||||
//
|
||||
lls[0] > lls[1] &&
|
||||
lls[1] > lls[2]
|
||||
//
|
||||
;
|
||||
isDownTrend =
|
||||
//
|
||||
isFirstLow
|
||||
?
|
||||
//
|
||||
lls[0] < lls[1] &&
|
||||
lls[1] < lls[2] &&
|
||||
//
|
||||
hhs[0] < hhs[1] &&
|
||||
hhs[1] < hhs[2]
|
||||
//
|
||||
:
|
||||
//
|
||||
hhs[0] < hhs[1] &&
|
||||
hhs[1] < hhs[2] &&
|
||||
//
|
||||
lls[0] < lls[1] &&
|
||||
lls[1] < lls[2]
|
||||
//
|
||||
;
|
||||
for (int i = 1; i < _requiredPivots; i++)
|
||||
{
|
||||
//
|
||||
// Lows ...
|
||||
|
||||
//
|
||||
// Lower Lows ...
|
||||
if (lls[i - 1] < lls[i])
|
||||
{
|
||||
//
|
||||
Add(
|
||||
lls[i - 1],
|
||||
lowerLows //
|
||||
);
|
||||
|
||||
//
|
||||
Add(
|
||||
llTimes[i - 1],
|
||||
lowerLowTimes //
|
||||
);
|
||||
}
|
||||
else
|
||||
//
|
||||
// Higher Lows ...
|
||||
if (lls[i - 1] > lls[i])
|
||||
{
|
||||
//
|
||||
Add(
|
||||
lls[i - 1],
|
||||
higherLows //
|
||||
);
|
||||
|
||||
//
|
||||
Add(
|
||||
llTimes[i - 1],
|
||||
higherLowTimes //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Highs ...
|
||||
|
||||
//
|
||||
// Higher Highs ...
|
||||
if (hhs[i - 1] > hhs[i])
|
||||
{
|
||||
//
|
||||
Add(
|
||||
hhs[i - 1],
|
||||
higherHighs //
|
||||
);
|
||||
|
||||
//
|
||||
Add(
|
||||
hhTimes[i - 1],
|
||||
higherHighTimes //
|
||||
);
|
||||
}
|
||||
else
|
||||
//
|
||||
// Lower Highs ...
|
||||
if (hhs[i - 1] < hhs[i])
|
||||
{
|
||||
//
|
||||
Add(
|
||||
hhs[i - 1],
|
||||
lowerHighs //
|
||||
);
|
||||
|
||||
//
|
||||
Add(
|
||||
hhTimes[i - 1],
|
||||
lowerHighTimes //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Remove Draws ...
|
||||
RemoveDraws("XTRND");
|
||||
|
||||
//
|
||||
symbol = _symbol;
|
||||
period = _period;
|
||||
_numberOfPivots = _requiredPivots;
|
||||
_pivotShoulders = _requiredShoulders;
|
||||
|
||||
//
|
||||
result = IsValid();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Cleanup ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
|
||||
//
|
||||
_numberOfPivots = 0;
|
||||
_pivotShoulders = 0;
|
||||
|
||||
//
|
||||
Clean(higherHighs);
|
||||
Clean(higherHighTimes);
|
||||
|
||||
//
|
||||
Clean(higherLows);
|
||||
Clean(higherLowTimes);
|
||||
|
||||
//
|
||||
Clean(lowerHighs);
|
||||
Clean(lowerHighTimes);
|
||||
|
||||
//
|
||||
Clean(lowerLows);
|
||||
Clean(lowerLowTimes);
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
IsValid(symbol) &&
|
||||
IsValid(period)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCBaseInd
|
||||
// Description: provides Indicator implementation
|
||||
// requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../../Classes/x-saherelm.xind.class.mq5"
|
||||
|
||||
//
|
||||
// a Simple Indicator ...
|
||||
|
||||
class XSCMid : public XSCBaseInd
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
|
||||
//
|
||||
// Property Getter(s) / Setter(s) ...
|
||||
|
||||
//
|
||||
// Override(s) ...
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
};
|
||||
Reference in New Issue
Block a user